lib/index.js
function getDockerfileContext(context) {
  const fs = require('fs');
  let files = [];
  let dockerfile = exports.resolveDockerfile(context);
  let file = fs.readFileSync(dockerfile, {encoding: 'utf8'});
  for (let line of file.split('\n')) {
    if (line.match(/^\s*(ADD|COPY).*$/)) {
      let entries = line.split(' ')
        .splice(1)
        .map(val => val.trim())
        .filter(val => val !== '')
        .filter(val => !val.startsWith('http'));
      if (entries[0].startsWith('--chown')) {
        entries = entries.splice(1);
      }

      // Array mode
      if (line.indexOf('[') !== -1 && line.indexOf(']') !== -1) {
        let args = JSON.parse(entries.join(' '));
        args.splice(-1);
        files = args
      }
      // Default mode
      else {
        entries.splice(-1);
        files = entries;
      }
    }
  }

  let resolvedFiles = [];
  for (let file of files) {
    resolvedFiles = resolvedFiles.concat(glob.sync(path.join(path.dirname(context), file)));
  }

  return { context, src: ['Dockerfile', ...resolvedFiles] };
}
function getDockerfileContext(context) {
  const fs = require('fs');
  let files = [];
  let dockerfile = exports.resolveDockerfile(context);
  let file = fs.readFileSync(dockerfile, {encoding: 'utf8'});
  for (let line of file.split('\n')) {
    if (line.match(/^\s*(ADD|COPY).*$/)) {
      let entries = line.split(' ')
        .splice(1)
        .map(val => val.trim())
        .filter(val => val !== '')
        .filter(val => !val.startsWith('http'));
      if (entries[0].startsWith('--chown')) {
        entries = entries.splice(1);
      }

      // Array mode
      if (line.indexOf('[') !== -1 && line.indexOf(']') !== -1) {
        let args = JSON.parse(entries.join(' '));
        args.splice(-1);
        files = args
      }
      // Default mode
      else {
        entries.splice(-1);
        files = entries;
      }
    }
  }

  let resolvedFiles = [];
  for (let file of files) {
    resolvedFiles = resolvedFiles.concat(glob.sync(path.join(path.dirname(context), file)));
  }

  return { context, src: ['Dockerfile', ...resolvedFiles] };
}
function getDockerfileContext ( context ) { const fs = require ( 'fs' ) ; let files = [ ] ; let dockerfile = exports . resolveDockerfile ( context ) ; let file = fs . readFileSync ( dockerfile , { encoding : 'utf8' } ) ; for ( let line of file . split ( '\n' ) ) { if ( line . match ( / ^\s*(ADD|COPY).*$ / ) ) { let entries = line . split ( ' ' ) . splice ( 1 ) . map ( val => val . trim ( ) ) . filter ( val => val !== '' ) . filter ( val => ! val . startsWith ( 'http' ) ) ; if ( entries [ 0 ] . startsWith ( '--chown' ) ) { entries = entries . splice ( 1 ) ; } // Array mode if ( line . indexOf ( '[' ) !== - 1 && line . indexOf ( ']' ) !== - 1 ) { let args = JSON . parse ( entries . join ( ' ' ) ) ; args . splice ( - 1 ) ; files = args } // Default mode else { entries . splice ( - 1 ) ; files = entries ; } } } let resolvedFiles = [ ] ; for ( let file of files ) { resolvedFiles = resolvedFiles . concat ( glob . sync ( path . join ( path . dirname ( context ) , file ) ) ) ; } return { context , src : [ 'Dockerfile' , ... resolvedFiles ] } ; }
Parses a Dockerfile and looks for sources that may be needed to build this image.
@param context
@returns {{context: *, src: *[]}}
Parses a Dockerfile and looks for sources that may be needed to build this image .