Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting Dockerfile into a captain-definition file #214

Closed
dkimot opened this issue Mar 30, 2018 · 2 comments
Closed

Converting Dockerfile into a captain-definition file #214

dkimot opened this issue Mar 30, 2018 · 2 comments

Comments

@dkimot
Copy link

dkimot commented Mar 30, 2018

I wrote a script that converts a Dockerfile into a captain-definition file and modifies every COPY line so it is compliant with CDD and the fact that it moves the source code into a src directory. I run it as a git pre-commit hook through NPM and thought I would post it here because automation is always nice.

const fs = require('fs');
const path = require('path');

const dockerfileLines = fs.readFileSync(path.join(__dirname, '..', 'Dockerfile')).toString().split('\n');

for (let i = 0; i < dockerfileLines.length; i += 1) {
  let line = dockerfileLines[i];
  if (line.indexOf('COPY .') === 0) {
    dockerfileLines[i] = line.replace('COPY .', 'COPY ./src');
  }
}

const captainDefinition = JSON.stringify({
  schemaVersion: 1,
  dockerfileLines,
});

fs.writeFileSync(path.join(__dirname, '..', 'captain-definition'), captainDefinition);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants