Skip to content

Commit

Permalink
fix(docker): allow set base image tag (default latest)
Browse files Browse the repository at this point in the history
fix #66
  • Loading branch information
lgaticaq committed Dec 17, 2020
1 parent 2d9f780 commit ac6e42f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]` |

Expand Down
7 changes: 4 additions & 3 deletions src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
3 changes: 2 additions & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Config extends SemanticReleaseConfig {
additionalTags?: string[]
registries?: Registry[]
baseImageName?: string
baseImageTag?: string
}

export interface ExecOptions {
Expand Down

0 comments on commit ac6e42f

Please sign in to comment.