Skip to content

Commit

Permalink
#3: Added docker build image script
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Sep 8, 2019
1 parent cefe3e9 commit aa57f38
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@actions/core": "^1.1.0"
},
"devDependencies": {
"chai": "^4.2.0",
"jest": "^24.9.0"
}
}
62 changes: 62 additions & 0 deletions src/__tests__/load-inputs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const chai = require('chai');
const expect = chai.expect;

describe('load-inputs module test suite', () => {
let loadInputs;
beforeEach(() => {
loadInputs = require('../load-inputs');
process.env = {};
});
describe('loadInputs', () => {
test('Required variables in env, should return valid inputs', () => {
// Given
process.env = {
INPUT_NAME: 'name',
INPUT_TAG: 'tag',
INPUT_USERNAME: 'username',
INPUT_PASSWORD: 's3cr3t'
};
// When
const result = loadInputs();
// Then
expect(result).to.eql(
{
name: 'name',
username: 'username',
password: 's3cr3t',
tag: 'tag',
registry: ''
})
});
test('Required variables NOT in env, should throw error', () => {
// Given
process.env = {
INPUT_NAME: 'name',
INPUT_TAG: 'tag'
};
// When - Then
expect(loadInputs).to.throw('Input required and not supplied: username');
});
test('Required and optional variables in env, should return valid inputs', () => {
// Given
process.env = {
INPUT_NAME: 'name',
INPUT_TAG: 'tag',
INPUT_USERNAME: 'username',
INPUT_PASSWORD: 's3cr3t',
INPUT_REGISTRY: 'https://hub.marcnuri.com'
};
// When
const result = loadInputs();
// Then
expect(result).to.eql(
{
name: 'name',
username: 'username',
password: 's3cr3t',
tag: 'tag',
registry: 'https://hub.marcnuri.com'
})
});
});
});
4 changes: 4 additions & 0 deletions src/docker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";

const child_process = require('child_process');

const build = inputs => {
console.log('Building docker image');
const imageName = `${inputs.name}:${inputs.tag}`;
child_process.execSync(`docker build -t ${imageName} .`)
};

const login = inputs => {
Expand Down
4 changes: 3 additions & 1 deletion src/load-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
const core = require('@actions/core');

const loadInputs = () => {
console.log('Loading input variables');
const result = {};
result.name = core.getInput('name', {required: true});
result.tag = core.getInput('tag', {required: true});
result.username = core.getInput('username', {required: true});
result.password = core.getInput('password', {required: true});
result.registry = core.getInput('name', {required: false});
result.registry = core.getInput('registry', {required: false});
return result;
};

module.exports = loadInputs;

0 comments on commit aa57f38

Please sign in to comment.