Skip to content

Commit

Permalink
feat: Add ubuntuVersion option / CLI flag, default to 20.10.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkobits committed Nov 20, 2020
1 parent 3db8149 commit e1a6f99
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ dockerize --node-version="12.13.4"

<a href="#top" title="Back to top"><img src="https://user-images.githubusercontent.com/441546/67830932-d6ab4680-fa99-11e9-9870-bc6d31db5a1b.png"></a>

<table>
<tr><th align="left">Name</th><th align="left">Required</th><th align="left">Default</th></tr>
<tr><td><code>--ubuntu-version</code></td><td><code>false</code></td><td><code>20.10</code></td></tr>
</table>

Ubuntu version to use as a base image. This option supports any valid tag for the [public `ubuntu` image](https://hub.docker.com/_/ubuntu/).

**Example:**

```
dockerize --ubuntu-version="latest"
```

**Note:** This argument is moot when the `--dockerfile` flag is used.

<a href="#top" title="Back to top"><img src="https://user-images.githubusercontent.com/441546/67830932-d6ab4680-fa99-11e9-9870-bc6d31db5a1b.png"></a>

<table>
<tr><th align="left">Name</th><th align="left">Required</th><th align="left">Default</th></tr>
<tr><td><code>--npmrc</code></td><td><code>false</code></td><td>N/A</td></tr>
Expand All @@ -154,6 +171,7 @@ dockerize --npmrc="~/.npmrc"
```

**Note:** If an `.npmrc` file is used, it will be deleted from the image once dependencies are installed.

**Note:** This argument is moot when the `--dockerfile` flag is used.

<a href="#top" title="Back to top"><img src="https://user-images.githubusercontent.com/441546/67830932-d6ab4680-fa99-11e9-9870-bc6d31db5a1b.png"></a>
Expand Down
9 changes: 9 additions & 0 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ cli.command<DockerizeArguments>({
conflicts: ['dockerfile']
});

command.option('ubuntu-version', {
group: 'Optional Arguments:',
description: 'Ubuntu version to use as a base image. [Default: 20.10]',
required: false,
type: 'string',
conflicts: ['dockerfile']
});

command.option('label', {
group: 'Optional Arguments:',
description: 'Labels to apply to the image. May be used multiple times.',
Expand Down Expand Up @@ -97,6 +105,7 @@ cli.command<DockerizeArguments>({
cwd: argv.cwd || process.cwd(),
tag: argv.tag,
nodeVersion: argv.nodeVersion,
ubuntuVersion: argv.ubuntuVersion,
labels: argv.label,
env: argv.env,
extraArgs: argv.extraArgs,
Expand Down
2 changes: 1 addition & 1 deletion src/etc/Dockerfile.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1
FROM ubuntu:19.04 as base
FROM ubuntu:<%= ubuntuVersion %> as base

ENV PATH=/tmp/node/bin:$PATH

Expand Down
7 changes: 7 additions & 0 deletions src/etc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export interface DockerizeOptions {
*/
nodeVersion?: string;

/**
* Ubuntu version to use as a base image.
*
* Default: 20.10
*/
ubuntuVersion?: string;

/**
* Additional labels to apply to the image.
*
Expand Down
7 changes: 7 additions & 0 deletions src/lib/dockerize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default async function dockerize(options: DockerizeOptions) {
ow(options.cwd, 'cwd', ow.string);
ow(options.tag, 'tag', ow.any(ow.undefined, ow.string));
ow(options.nodeVersion, 'Node version', ow.any(ow.undefined, ow.string));
ow(options.ubuntuVersion, 'Ubuntu version', ow.any(ow.undefined, ow.string));
ow(options.labels, 'labels', ow.any(ow.undefined, ow.string, ow.array.ofType(ow.string)));
ow(options.env, 'environment variables', ow.any(ow.undefined, ow.string, ow.array.ofType(ow.string)));
ow(options.extraArgs, 'extra Docker arguments', ow.any(ow.undefined, ow.string));
Expand All @@ -57,6 +58,11 @@ export default async function dockerize(options: DockerizeOptions) {

// ----- [3] Parse Options ---------------------------------------------------

/**
* Ubuntu version to use as a base image.
*/
const ubuntuVersion = options.ubuntuVersion ?? '20.10';

/**
* Tag that will be applied to the image.
*/
Expand Down Expand Up @@ -162,6 +168,7 @@ export default async function dockerize(options: DockerizeOptions) {
envVars,
hasLockfile,
nodeVersion,
ubuntuVersion,
tiniVersion: DEFAULT_TINI_VERSION,
hasNpmrc
}
Expand Down

0 comments on commit e1a6f99

Please sign in to comment.