@codedependant/semantic-release-docker 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +47 -27
- package/lib/build-config.js +2 -0
- package/lib/docker/image.js +17 -2
- package/lib/verify.js +48 -35
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Semantic Release Docker
|
|
2
2
|
|
|
3
|
+
# [4.1.0](https://github.com/esatterwhite/semantic-release-docker/compare/v4.0.0...v4.1.0) (2022-04-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Chores
|
|
7
|
+
|
|
8
|
+
* **deps**: semantic-release/error@3.0.0 [d55ff11](https://github.com/esatterwhite/semantic-release-docker/commit/d55ff1108a0130ce10932e409683fb741fb315d3) - Eric Satterwhite
|
|
9
|
+
* **deps**: tap@16.0.0 [94d3340](https://github.com/esatterwhite/semantic-release-docker/commit/94d3340dba42ed702b71325ea5afc2f627df1fcc) - Eric Satterwhite
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **docker**: allow command to be run via docker in verify step [4646bd6](https://github.com/esatterwhite/semantic-release-docker/commit/4646bd681cb4d7ee4a48a9187fbe7dfe88686b78) - Eric Satterwhite, closes: [#20](https://github.com/esatterwhite/semantic-release-docker/issues/20)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Miscellaneous
|
|
18
|
+
|
|
19
|
+
* add prerelease example [90158fd](https://github.com/esatterwhite/semantic-release-docker/commit/90158fdaa65b35a861ce40ca2c3a660f28446f72) - Eric Satterwhite
|
|
20
|
+
* Update Readme [74f9910](https://github.com/esatterwhite/semantic-release-docker/commit/74f99107723223a67009c96a762b200f8d25621d) - GitHub
|
|
21
|
+
|
|
3
22
|
# [4.0.0](https://github.com/esatterwhite/semantic-release-docker/compare/v3.1.2...v4.0.0) (2021-12-31)
|
|
4
23
|
|
|
5
24
|
|
package/README.md
CHANGED
|
@@ -42,17 +42,18 @@ omitted, it is assumed the docker daemon is already authenticated with the targe
|
|
|
42
42
|
|
|
43
43
|
### Options
|
|
44
44
|
|
|
45
|
-
| Option
|
|
46
|
-
|
|
47
|
-
| `dockerTags`
|
|
48
|
-
| `dockerImage`
|
|
49
|
-
| `dockerRegistry`
|
|
50
|
-
| `dockerProject`
|
|
51
|
-
| `dockerFile`
|
|
52
|
-
| `dockerContext`
|
|
53
|
-
| `dockerLogin`
|
|
54
|
-
| `dockerArgs`
|
|
55
|
-
| `dockerPublish`
|
|
45
|
+
| Option | Description | Default |
|
|
46
|
+
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
|
|
47
|
+
| `dockerTags` | _Optional_. An array of strings allowing to specify additional tags to apply to the image. Supports templating | [`latest`, `{{major}}-latest`, `{{version}}`] |
|
|
48
|
+
| `dockerImage` | _Optional_. The name of the image to release. | Parsed from package.json `name` property |
|
|
49
|
+
| `dockerRegistry` | _Optional_. The hostname and port used by the the registry in format `hostname[:port]`. Omit the port if the registry uses the default port | `null` (dockerhub) |
|
|
50
|
+
| `dockerProject` | _Optional_. The project or repository name to publish the image to | For scoped packages, the scope will be used, otherwise `null` |
|
|
51
|
+
| `dockerFile` | _Optional_. The path, relative to `$PWD` to a Docker file to build the target image with | `Dockerfile` |
|
|
52
|
+
| `dockerContext` | _Optional_. A path, relative to `$PWD` to use as the build context A | `.` |
|
|
53
|
+
| `dockerLogin` | _Optional_. Set to false it by pass docker login if the docker daemon is already authorized | `true` |
|
|
54
|
+
| `dockerArgs` | _Optional_. Include additional values for docker's `build-arg`. Supports templating | |
|
|
55
|
+
| `dockerPublish` | _Optional_. Automatically push image tags during the publish phase. | `true` |
|
|
56
|
+
| `dockerVerifyCmd` | _Optional_. If specified, during the verify stage, the specified command will execute in a container of the build image. If the command errors, the release will fail. | `false` |
|
|
56
57
|
|
|
57
58
|
### Build Arguments
|
|
58
59
|
|
|
@@ -77,21 +78,22 @@ secrets and other sensitive information
|
|
|
77
78
|
|
|
78
79
|
String template will be passed these
|
|
79
80
|
|
|
80
|
-
| Variable name | Description | Type
|
|
81
|
-
|
|
82
|
-
| `git_sha` | The commit SHA of the current release | `String`
|
|
83
|
-
| `git_tag` | The git tag of the current release | `String`
|
|
84
|
-
| `release_type` | The severity type of the current build (`major`, `minor`, `patch`) | `String`
|
|
85
|
-
| `relase_notes` | The release notes blob associated with the release | `String`
|
|
86
|
-
| `next` | Semver object representing the next release | `Object`
|
|
87
|
-
| `previous` | Semver object representing the previous release | `Object`
|
|
88
|
-
| `major` | The major version of the next release | `Number`
|
|
89
|
-
| `minor` | The minor version of the next release | `Number`
|
|
90
|
-
| `patch` | The patch version of the next release | `Number`
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
81
|
+
| Variable name | Description | Type |
|
|
82
|
+
|----------------|--------------------------------------------------------------------|-----------------|
|
|
83
|
+
| `git_sha` | The commit SHA of the current release | `String` |
|
|
84
|
+
| `git_tag` | The git tag of the current release | `String` |
|
|
85
|
+
| `release_type` | The severity type of the current build (`major`, `minor`, `patch`) | `String` |
|
|
86
|
+
| `relase_notes` | The release notes blob associated with the release | `String` |
|
|
87
|
+
| `next` | Semver object representing the next release | `Object` |
|
|
88
|
+
| `previous` | Semver object representing the previous release | `Object` |
|
|
89
|
+
| `major` | The major version of the next release | `Number` |
|
|
90
|
+
| `minor` | The minor version of the next release | `Number` |
|
|
91
|
+
| `patch` | The patch version of the next release | `Number` |
|
|
92
|
+
| `prerelease` | The prerelease versions of the next release | `Array<Number>` |
|
|
93
|
+
| `env` | Environment variables that were set at build time | `Object` |
|
|
94
|
+
| `pkg` | Values parsed from `package.json` | `Object` |
|
|
95
|
+
| `build` | A Random build hash representing the current execution context | `String` |
|
|
96
|
+
| `now` | Current timestamp is ISO 8601 format | `String` |
|
|
95
97
|
|
|
96
98
|
### Template Helpers
|
|
97
99
|
|
|
@@ -101,7 +103,7 @@ The following handlebars template helpers are pre installed
|
|
|
101
103
|
|:------------:|------------------------------------------------------------------------|:-----------:|--------------------------------------------------------------------------------------------|
|
|
102
104
|
| `endswith` | returns true if a string ends with another | [Boolean][] | <pre lang="hbs">{{#if (endswith myvar 'ing')}}{{ othervar }}{{/if}}</pre> |
|
|
103
105
|
| `eq` | returns true if two values are strictly equal to each other | [Boolean][] | <pre lang="hbs">{{#if (eq var_one var_two)}}{{ var_three }}{{/if}}</pre> |
|
|
104
|
-
| `gt` | returns true if the first value is greater than the second |
|
|
106
|
+
| `gt` | returns true if the first value is greater than the second | [Boolean][] | <pre lang="hbs">{{#if (gt var_one var_two)}}{{ var_three }}{{/if}}</pre> |
|
|
105
107
|
| `gte` | returns true if the first value is greater than or equal to the second | [Boolean][] | <pre lang="hbs">{{#if (gte var_one var_two)}}{{ var_three }}{{/if}}</pre> |
|
|
106
108
|
| `includes` | returns true if the input (string \| array) includes the second value | [Boolean][] | <pre lang="hbs">{{#if (includes some_array 'one')}}{{ var_one }}{{/if}}</pre> |
|
|
107
109
|
| `lower` | returns the lower cased varient of the input string | [String][] | <pre lang="hbs">{{ lower my_var }}</pre> |
|
|
@@ -191,6 +193,24 @@ $ docker push quay.io/codedependant/my-image
|
|
|
191
193
|
|
|
192
194
|
the default docker image tags for the 1.0.0 release would be `1.0.0`, `1-latest`, `latest`
|
|
193
195
|
|
|
196
|
+
**example prerelease configuration**:
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"release": {
|
|
201
|
+
"dockerTags": [
|
|
202
|
+
"{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}",
|
|
203
|
+
"{{major}}-{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}",
|
|
204
|
+
"{{major}}.{{minor}}-{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}",
|
|
205
|
+
"{{version}}"
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
the docker tags for version `1.2.3` will be `1.2.3`, `1.2-latest`, `1-latest` and `latest`
|
|
212
|
+
the docker tags for version `2.3.4-beta.6` will be `2.3.4-beta.6`, `2.3-beta`, `2-beta` and `beta`
|
|
213
|
+
|
|
194
214
|
## Development
|
|
195
215
|
|
|
196
216
|
### Docker Registry
|
package/lib/build-config.js
CHANGED
|
@@ -20,6 +20,7 @@ async function buildConfig(build_id, config, context) {
|
|
|
20
20
|
, dockerImage: image
|
|
21
21
|
, dockerPublish: publish = true
|
|
22
22
|
, dockerContext = '.'
|
|
23
|
+
, dockerVerifyCmd: verifycmd = null
|
|
23
24
|
} = config
|
|
24
25
|
|
|
25
26
|
let name = null
|
|
@@ -44,6 +45,7 @@ async function buildConfig(build_id, config, context) {
|
|
|
44
45
|
, project
|
|
45
46
|
, publish
|
|
46
47
|
, tags: array.toArray(tags)
|
|
48
|
+
, verifycmd
|
|
47
49
|
, args: {
|
|
48
50
|
SRC_DIRECTORY: path.basename(context.cwd)
|
|
49
51
|
, TARGET_PATH: target
|
package/lib/docker/image.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const crypto = require('crypto')
|
|
5
5
|
const execa = require('execa')
|
|
6
|
+
const array = require('../lang/array/index.js')
|
|
6
7
|
|
|
7
8
|
class Image {
|
|
8
9
|
constructor(opts) {
|
|
@@ -79,7 +80,7 @@ class Image {
|
|
|
79
80
|
args.push('--build-arg', `${name}=${value}`)
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
return [
|
|
83
84
|
'build'
|
|
84
85
|
, '--quiet'
|
|
85
86
|
, '--tag'
|
|
@@ -89,7 +90,21 @@ class Image {
|
|
|
89
90
|
, this.dockerfile
|
|
90
91
|
, this.context
|
|
91
92
|
]
|
|
92
|
-
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async run(cmd) {
|
|
96
|
+
const stream = execa('docker', [
|
|
97
|
+
'run'
|
|
98
|
+
, '--rm'
|
|
99
|
+
, this.name
|
|
100
|
+
, ...array.toArray(cmd)
|
|
101
|
+
], {all: true})
|
|
102
|
+
|
|
103
|
+
stream.stdout.pipe(process.stdout)
|
|
104
|
+
stream.stderr.pipe(process.stderr)
|
|
105
|
+
|
|
106
|
+
const {all} = await stream
|
|
107
|
+
return all
|
|
93
108
|
}
|
|
94
109
|
|
|
95
110
|
async build() {
|
package/lib/verify.js
CHANGED
|
@@ -4,12 +4,13 @@ const {promises: fs} = require('fs')
|
|
|
4
4
|
const execa = require('execa')
|
|
5
5
|
const debug = require('debug')('semantic-release:semantic-release-docker:verify')
|
|
6
6
|
const SemanticError = require('@semantic-release/error')
|
|
7
|
+
const prepare = require('./prepare.js')
|
|
7
8
|
const docker = require('./docker/index.js')
|
|
8
9
|
|
|
9
10
|
module.exports = verify
|
|
10
11
|
|
|
11
12
|
async function verify(opts, context) {
|
|
12
|
-
const {env,
|
|
13
|
+
const {env, cwd} = context
|
|
13
14
|
const PASSWORD = env.DOCKER_REGISTRY_PASSWORD || env.GITHUB_TOKEN
|
|
14
15
|
const USERNAME = env.DOCKER_REGISTRY_USER
|
|
15
16
|
|
|
@@ -51,47 +52,59 @@ async function verify(opts, context) {
|
|
|
51
52
|
debug('image to build', image.repo)
|
|
52
53
|
if (!USERNAME && !PASSWORD) {
|
|
53
54
|
debug('No docker credentials found. Skipping login')
|
|
54
|
-
|
|
55
|
+
} else {
|
|
56
|
+
await doLogin({...opts, USERNAME, PASSWORD}, context)
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
if (!opts.verifycmd) return true
|
|
60
|
+
|
|
61
|
+
const img = await prepare(opts, context)
|
|
62
|
+
const output = await img.run(opts.verifycmd)
|
|
63
|
+
if (opts.dryRun) await img.clean()
|
|
64
|
+
return output
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function doLogin(opts, context) {
|
|
68
|
+
const {USERNAME, PASSWORD} = opts
|
|
69
|
+
const {logger} = context
|
|
70
|
+
|
|
57
71
|
if (opts.login === false) {
|
|
58
72
|
debug('docker login === false. Skipping login')
|
|
59
|
-
|
|
60
|
-
|
|
73
|
+
} else {
|
|
74
|
+
let set = 0
|
|
75
|
+
if (USERNAME) set += 1
|
|
76
|
+
if (PASSWORD) set += 1
|
|
61
77
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
if (set !== 2) {
|
|
79
|
+
const error = new SemanticError(
|
|
80
|
+
'Docker authentication failed'
|
|
81
|
+
, 'EAUTH'
|
|
82
|
+
, 'Both ENV vars DOCKER_REGISTRY_USER and DOCKER_REGISTRY_PASSWORD must be set'
|
|
83
|
+
)
|
|
84
|
+
throw error
|
|
85
|
+
}
|
|
65
86
|
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
'
|
|
69
|
-
, '
|
|
70
|
-
, '
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const passwd = execa('echo', [PASSWORD])
|
|
76
|
-
const login = execa('docker', [
|
|
77
|
-
'login'
|
|
78
|
-
, opts.registry || ''
|
|
79
|
-
, '-u', USERNAME
|
|
80
|
-
, '--password-stdin'
|
|
81
|
-
])
|
|
87
|
+
const passwd = execa('echo', [PASSWORD])
|
|
88
|
+
const login = execa('docker', [
|
|
89
|
+
'login'
|
|
90
|
+
, opts.registry || ''
|
|
91
|
+
, '-u', USERNAME
|
|
92
|
+
, '--password-stdin'
|
|
93
|
+
])
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
passwd.stdout.pipe(login.stdin)
|
|
84
96
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
try {
|
|
98
|
+
await login
|
|
99
|
+
} catch (err) {
|
|
100
|
+
logger.fatal(err)
|
|
101
|
+
const error = new SemanticError(
|
|
102
|
+
'Docker authentication failed'
|
|
103
|
+
, 'EAUTH'
|
|
104
|
+
, `Authentication to ${opts.registry || 'dockerhub'} failed`
|
|
105
|
+
)
|
|
106
|
+
throw error
|
|
107
|
+
}
|
|
108
|
+
logger.success('docker login successful')
|
|
94
109
|
}
|
|
95
|
-
logger.success('docker login successful')
|
|
96
|
-
return true
|
|
97
110
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codedependant/semantic-release-docker",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"description": "docker package",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"url": "git+ssh://git@github.com/esatterwhite/semantic-release-docker.git"
|
|
37
37
|
},
|
|
38
38
|
"tap": {
|
|
39
|
-
"esm": false,
|
|
40
39
|
"ts": false,
|
|
41
40
|
"jsx": false,
|
|
42
41
|
"timeout": 60,
|
|
@@ -54,6 +53,7 @@
|
|
|
54
53
|
"text",
|
|
55
54
|
"text-summary",
|
|
56
55
|
"json",
|
|
56
|
+
"json-summary",
|
|
57
57
|
"html"
|
|
58
58
|
],
|
|
59
59
|
"nyc-arg": [
|
|
@@ -73,10 +73,10 @@
|
|
|
73
73
|
"eslint-config-codedependant": "^3.0.0",
|
|
74
74
|
"semantic-release": "17",
|
|
75
75
|
"sinon": "^9.0.2",
|
|
76
|
-
"tap": "^
|
|
76
|
+
"tap": "^16.0.0"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@semantic-release/error": "^
|
|
79
|
+
"@semantic-release/error": "^3.0.0",
|
|
80
80
|
"debug": "^4.1.1",
|
|
81
81
|
"execa": "^4.0.2",
|
|
82
82
|
"handlebars": "^4.7.7",
|