From ac6e42f5d58c78a605dd1016e608a0e94f10186b Mon Sep 17 00:00:00 2001 From: Leonardo Gatica Date: Thu, 17 Dec 2020 11:42:08 -0300 Subject: [PATCH] fix(docker): allow set base image tag (default latest) fix #66 --- README.md | 1 + src/prepare.js | 7 ++++--- src/publish.js | 3 ++- src/types.d.ts | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 00b13ff6..1b880a71 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht | Variable | Description | | -------------------- | ----------------------------------------------------------------- | | `baseImageName` | Name of the previously constructed docker image. Required. | +| `baseImageTag` | Name of the previously constructed docker image tag. Optional. Default `"latest"` | | `registries` | Array of objects with username, password, url and imageName. "username" and "password" are environment variables. Required. Example: `{"username": "DOCKER_USER", "password": "DOCKER_PASSWORD", "url": "docker.pkg.github.com", "imageName": "docker.pkg.github.com/myuser/myrepo/myapp"}` | | `additionalTags` | Array of addiotional tags to push. Optional. Example: `["beta", "next"]` | diff --git a/src/prepare.js b/src/prepare.js index c7e5d34c..2846d052 100644 --- a/src/prepare.js +++ b/src/prepare.js @@ -22,16 +22,17 @@ module.exports = async (pluginConfig, ctx) => { if (pluginConfig.additionalTags && pluginConfig.additionalTags.length > 0) { tags.push(...pluginConfig.additionalTags) } + const baseImageTag = pluginConfig.baseImageTag || 'latest' for (const tag of tags) { ctx.logger.log( - `Tagging docker image ${pluginConfig.baseImageName}:latest to ${pluginConfig.baseImageName}:${tag}` + `Tagging docker image ${pluginConfig.baseImageName}:${baseImageTag} to ${pluginConfig.baseImageName}:${tag}` ) await image.tag({ repo: pluginConfig.baseImageName, tag }) } for (const { imageName } of pluginConfig.registries) { - for (const tag of [...tags, 'latest']) { + for (const tag of [...tags, baseImageTag]) { ctx.logger.log( - `Tagging docker image ${pluginConfig.baseImageName}:latest to ${imageName}:${tag}` + `Tagging docker image ${pluginConfig.baseImageName}:${baseImageTag} to ${imageName}:${tag}` ) await image.tag({ repo: imageName, tag }) } diff --git a/src/publish.js b/src/publish.js index dcc94908..a460421e 100644 --- a/src/publish.js +++ b/src/publish.js @@ -47,7 +47,8 @@ const pushImage = response => { module.exports = async (pluginConfig, ctx) => { try { const docker = new Dockerode() - const tags = ['latest', ctx.nextRelease.version] + const baseImageTag = pluginConfig.baseImageTag || 'latest' + const tags = [baseImageTag, ctx.nextRelease.version] if (pluginConfig.additionalTags && pluginConfig.additionalTags.length > 0) { tags.push(...pluginConfig.additionalTags) } diff --git a/src/types.d.ts b/src/types.d.ts index 2d33c9e8..8d3b7c77 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -17,6 +17,7 @@ export interface Config extends SemanticReleaseConfig { additionalTags?: string[] registries?: Registry[] baseImageName?: string + baseImageTag?: string } export interface ExecOptions {