Skip to content

Commit

Permalink
feat: Adding web-app flag (#395)
Browse files Browse the repository at this point in the history
* This adds a new flag, `--web-app`  to make it easier to use the web app s2i image when working with modern web applications
  • Loading branch information
aalykiot authored and lholmquist committed Jan 13, 2020
1 parent 8622abb commit d1d0c14
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ These version tags correspond to the RHSCL tags of the [ubi8/nodejs s2i images](
#### dockerImage
Specify the s2i builder image of Node.js to use for the deployed applications. Defaults to [ubi8/nodejs s2i images](https://access.redhat.com/containers/#/registry.access.redhat.com/ubi8/nodejs-10)
#### web-app
Flag to automatically set the appropriate docker image for web app deployment. Defaults to false
#### outputImageStream
The name of the ImageStream to output to. Defaults to project name from package.json
Expand Down Expand Up @@ -206,6 +209,9 @@ Shows the below help
--projectLocation change the default location of the project [string]
--imageTag The tag of the docker image to use for the deployed
application. [string] [default: "latest"]
--web-app flag to automatically set the appropriate docker image
for web app deployment
[boolean] [default: false]
--outputImageStream The name of the ImageStream to output to. Defaults
to project name from package.json [string]
--outputImageStreamTag The tag of the ImageStream to output to. [string]
Expand Down
6 changes: 6 additions & 0 deletions bin/nodeshift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ yargs
type: 'string',
default: 'latest'
})
.option('web-app', {
describe: 'flag to automatically set the appropriate docker image for web app deployment',
type: 'boolean',
default: false
})
.options('outputImageStream', {
describe: 'The name of the ImageStream to output to. Defaults to project name from package.json',
type: 'string'
Expand Down Expand Up @@ -155,6 +160,7 @@ function createOptions (argv) {
options.projectLocation = argv.projectLocation;
options.dockerImage = argv.dockerImage;
options.imageTag = argv.imageTag;
options.webApp = argv.webApp;
options.outputImageStreamName = argv.outputImageStream;
options.outputImageStreamTag = argv.outputImageStreamTag;
process.env.NODESHIFT_QUIET = argv.quiet === true;
Expand Down
6 changes: 4 additions & 2 deletions lib/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ async function createOrUpdateBuildConfig (config) {
forcePull: config.build.forcePull,
incremental: config.build.incremental,
dockerImage: config.dockerImage,
buildEnv: config.build.env
buildEnv: config.build.env,
webApp: config.webApp
});
return config.openshiftRestClient.apis.build.v1.ns(config.namespace.name).buildconfigs.post({ body: newBuildConfig });
}
Expand All @@ -115,7 +116,8 @@ async function createOrUpdateBuildConfig (config) {
imageTag: config.imageTag,
forcePull: config.build.forcePull,
dockerImage: config.dockerImage,
buildEnv: config.build.env
buildEnv: config.build.env,
webApp: config.webApp
});
return config.openshiftRestClient.apis.build.v1.ns(config.namespace.name).buildconfigs.post({ body: newBuildConfig });
}
Expand Down
7 changes: 7 additions & 0 deletions lib/definitions/build-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ const logger = require('../common-log')();
const DEFAULT_DOCKER_IMAGE = 'registry.access.redhat.com/ubi8/nodejs-10';
const DEFAULT_DOCKER_TAG = 'latest';

// Default docker image for web-apps
const DEFAULT_WEB_APP_DOCKER_IMAGE = 'nodeshift/ubi8-s2i-web-app';

// https://docs.openshift.com/online/rest_api/openshift_v1.html#v1-buildstrategy
module.exports = (options = {}) => {
// Setting appropriate docker image if web-app flag is set
options.dockerImage = options.webApp ? DEFAULT_WEB_APP_DOCKER_IMAGE : options.dockerImage;

// Just doing the source strategy
const dockerImage = options.dockerImage ? options.dockerImage : DEFAULT_DOCKER_IMAGE;
const dockerTag = options.imageTag ? options.imageTag : DEFAULT_DOCKER_TAG;
logger.info(`Using s2i image ${dockerImage} with tag ${dockerTag}`);
const dockerImageName = `${dockerImage}:${dockerTag}`;
const env = options.buildEnv || [];

return {
type: 'Source',
sourceStrategy: {
Expand Down
7 changes: 7 additions & 0 deletions test/definitions-tests/build-strategy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,10 @@ test('accepts a node version using imageTag option', t => {
t.equals(result.sourceStrategy.from.name, 'registry.access.redhat.com/ubi8/nodejs-10:1-20');
t.end();
});

test('strategy with web-app option enabled', (t) => {
const result = buildStrategy({ webApp: true });

t.equal(result.sourceStrategy.from.name, 'nodeshift/ubi8-s2i-web-app:latest', 'docker image should be latest web-app image');
t.end();
});

0 comments on commit d1d0c14

Please sign in to comment.