@codedependant/semantic-release-docker 4.0.0 → 4.2.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 CHANGED
@@ -1,5 +1,43 @@
1
1
  # Semantic Release Docker
2
2
 
3
+ # [4.2.0](https://github.com/esatterwhite/semantic-release-docker/compare/v4.1.0...v4.2.0) (2022-12-19)
4
+
5
+
6
+ ### Chores
7
+
8
+ * **ci**: downgrade github actions runner version [c6f1935](https://github.com/esatterwhite/semantic-release-docker/commit/c6f1935aec63e21a85c8e513dd74fed29a84562b) - Eric Satterwhite
9
+ * **test**: regenerate the local docker registry certs [4cfa6e2](https://github.com/esatterwhite/semantic-release-docker/commit/4cfa6e2a912b69ff3cfc496b88dae449a982e5f4) - Eric Satterwhite
10
+ * **test**: remove ci test temporarily [c28f199](https://github.com/esatterwhite/semantic-release-docker/commit/c28f199ab3d2e9bb85846e562c936c782f9440a5) - Eric Satterwhite
11
+
12
+
13
+ ### Documentation
14
+
15
+ * fix broken table in readme [e85e6f3](https://github.com/esatterwhite/semantic-release-docker/commit/e85e6f38f48e3c11ef88953e0cfa74276aab09a6) - Eric Satterwhite
16
+
17
+
18
+ ### Features
19
+
20
+ * added dockerNetwork config option [d6f2def](https://github.com/esatterwhite/semantic-release-docker/commit/d6f2defa0a4cfa3a36b1b63e7cdfe13c700e632a) - Eric Satterwhite, closes: [#29](https://github.com/esatterwhite/semantic-release-docker/issues/29)
21
+
22
+ # [4.1.0](https://github.com/esatterwhite/semantic-release-docker/compare/v4.0.0...v4.1.0) (2022-04-10)
23
+
24
+
25
+ ### Chores
26
+
27
+ * **deps**: semantic-release/error@3.0.0 [d55ff11](https://github.com/esatterwhite/semantic-release-docker/commit/d55ff1108a0130ce10932e409683fb741fb315d3) - Eric Satterwhite
28
+ * **deps**: tap@16.0.0 [94d3340](https://github.com/esatterwhite/semantic-release-docker/commit/94d3340dba42ed702b71325ea5afc2f627df1fcc) - Eric Satterwhite
29
+
30
+
31
+ ### Features
32
+
33
+ * **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)
34
+
35
+
36
+ ### Miscellaneous
37
+
38
+ * add prerelease example [90158fd](https://github.com/esatterwhite/semantic-release-docker/commit/90158fdaa65b35a861ce40ca2c3a660f28446f72) - Eric Satterwhite
39
+ * Update Readme [74f9910](https://github.com/esatterwhite/semantic-release-docker/commit/74f99107723223a67009c96a762b200f8d25621d) - GitHub
40
+
3
41
  # [4.0.0](https://github.com/esatterwhite/semantic-release-docker/compare/v3.1.2...v4.0.0) (2021-12-31)
4
42
 
5
43
 
package/README.md CHANGED
@@ -42,17 +42,19 @@ omitted, it is assumed the docker daemon is already authenticated with the targe
42
42
 
43
43
  ### Options
44
44
 
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` |
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` |
57
+ | `dockerNetwork` | _Optional_. Specify the Docker network to use while the image is building. | `default` |
56
58
 
57
59
  ### Build Arguments
58
60
 
@@ -62,36 +64,37 @@ build argument is explicitly `true`, the value will be omitted and the value fro
62
64
  a matching environment variable will be utilized instead. This can be useful when trying to include
63
65
  secrets and other sensitive information
64
66
 
65
- | Argument Name | Description | Default |
66
- |---------------------|--------------------------------------------------------------------------------------------|------------------------------|
67
- | `SRC_DIRECTORY` | The of the directory the build was triggered from | The directory name of CWD |
67
+ | Argument Name | Description | Default |
68
+ |---------------------|-------------------------------------------------------------------------------------------|------------------------------|
69
+ | `SRC_DIRECTORY` | The of the directory the build was triggered from | The directory name of CWD |
68
70
  | `TARGET_PATH` | Path relative to the execution root. Useful for Sharing a Single Docker file in monorepos | |
69
- | `NPM_PACKAGE_NAME` | The `name` property extracted from `package.json` - if present | |
70
- | `NPM_PACKAGE_SCOPE` | The parsed scope from the `name` property from `package.json` - sans `@` | |
71
- | `CONFIG_NAME` | The configured name of the docker image. | The parsed package name |
72
- | `CONFIG_PROJECT` | The configured docker repo project name | The package scope if present |
73
- | `GIT_SHA` | The commit SHA of the current release | |
74
- | `GIT_TAG` | The git tag of the current release | |
71
+ | `NPM_PACKAGE_NAME` | The `name` property extracted from `package.json` - if present | |
72
+ | `NPM_PACKAGE_SCOPE` | The parsed scope from the `name` property from `package.json` - sans `@` | |
73
+ | `CONFIG_NAME` | The configured name of the docker image. | The parsed package name |
74
+ | `CONFIG_PROJECT` | The configured docker repo project name | The package scope if present |
75
+ | `GIT_SHA` | The commit SHA of the current release | |
76
+ | `GIT_TAG` | The git tag of the current release | |
75
77
 
76
78
  ### Template Variables
77
79
 
78
80
  String template will be passed these
79
81
 
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
- | `env` | Environment variables that were set at build time | `Object` |
92
- | `pkg` | Values parsed from `package.json` | `Object` |
93
- | `build` | A Random build hash representing the current execution context | `String` |
94
- | `now` | Current timestamp is ISO 8601 format | `String` |
82
+ | Variable name | Description | Type |
83
+ |----------------|--------------------------------------------------------------------|-----------------|
84
+ | `git_sha` | The commit SHA of the current release | `String` |
85
+ | `git_tag` | The git tag of the current release | `String` |
86
+ | `release_type` | The severity type of the current build (`major`, `minor`, `patch`) | `String` |
87
+ | `relase_notes` | The release notes blob associated with the release | `String` |
88
+ | `next` | Semver object representing the next release | `Object` |
89
+ | `previous` | Semver object representing the previous release | `Object` |
90
+ | `major` | The major version of the next release | `Number` |
91
+ | `minor` | The minor version of the next release | `Number` |
92
+ | `patch` | The patch version of the next release | `Number` |
93
+ | `prerelease` | The prerelease versions of the next release | `Array<Number>` |
94
+ | `env` | Environment variables that were set at build time | `Object` |
95
+ | `pkg` | Values parsed from `package.json` | `Object` |
96
+ | `build` | A Random build hash representing the current execution context | `String` |
97
+ | `now` | Current timestamp is ISO 8601 format | `String` |
95
98
 
96
99
  ### Template Helpers
97
100
 
@@ -101,7 +104,7 @@ The following handlebars template helpers are pre installed
101
104
  |:------------:|------------------------------------------------------------------------|:-----------:|--------------------------------------------------------------------------------------------|
102
105
  | `endswith` | returns true if a string ends with another | [Boolean][] | <pre lang="hbs">{{#if (endswith myvar 'ing')}}{{ othervar }}{{/if}}</pre> |
103
106
  | `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 | | [Boolean][] | <pre lang="hbs">{{#if (gt var_one var_two)}}{{ var_three }}{{/if}}</pre> |
107
+ | `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
108
  | `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
109
  | `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
110
  | `lower` | returns the lower cased varient of the input string | [String][] | <pre lang="hbs">{{ lower my_var }}</pre> |
@@ -191,6 +194,24 @@ $ docker push quay.io/codedependant/my-image
191
194
 
192
195
  the default docker image tags for the 1.0.0 release would be `1.0.0`, `1-latest`, `latest`
193
196
 
197
+ **example prerelease configuration**:
198
+
199
+ ```json
200
+ {
201
+ "release": {
202
+ "dockerTags": [
203
+ "{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}",
204
+ "{{major}}-{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}",
205
+ "{{major}}.{{minor}}-{{#if prerelease.[0]}}{{prerelease.[0]}}{{else}}latest{{/if}}",
206
+ "{{version}}"
207
+ ]
208
+ }
209
+ }
210
+ ```
211
+
212
+ the docker tags for version `1.2.3` will be `1.2.3`, `1.2-latest`, `1-latest` and `latest`
213
+ the docker tags for version `2.3.4-beta.6` will be `2.3.4-beta.6`, `2.3-beta`, `2-beta` and `beta`
214
+
194
215
  ## Development
195
216
 
196
217
  ### Docker Registry
@@ -20,6 +20,8 @@ async function buildConfig(build_id, config, context) {
20
20
  , dockerImage: image
21
21
  , dockerPublish: publish = true
22
22
  , dockerContext = '.'
23
+ , dockerVerifyCmd: verifycmd = null
24
+ , dockerNetwork: network = 'default'
23
25
  } = config
24
26
 
25
27
  let name = null
@@ -44,6 +46,7 @@ async function buildConfig(build_id, config, context) {
44
46
  , project
45
47
  , publish
46
48
  , tags: array.toArray(tags)
49
+ , verifycmd
47
50
  , args: {
48
51
  SRC_DIRECTORY: path.basename(context.cwd)
49
52
  , TARGET_PATH: target
@@ -60,5 +63,6 @@ async function buildConfig(build_id, config, context) {
60
63
  , login: login
61
64
  , env: context.env
62
65
  , context: dockerContext
66
+ , network: network
63
67
  }
64
68
  }
@@ -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) {
@@ -15,6 +16,7 @@ class Image {
15
16
  , dockerfile = 'Dockerfile'
16
17
  , cwd = process.cwd()
17
18
  , context = '.'
19
+ , network = 'default'
18
20
  } = opts || {}
19
21
 
20
22
  if (!name || typeof name !== 'string') {
@@ -32,6 +34,7 @@ class Image {
32
34
  , dockerfile: dockerfile
33
35
  , context: context
34
36
  , cwd: cwd
37
+ , network: network
35
38
  }
36
39
  }
37
40
 
@@ -65,6 +68,10 @@ class Image {
65
68
  return path.resolve(this.opts.cwd, this.opts.dockerfile)
66
69
  }
67
70
 
71
+ get network() {
72
+ return this.opts.network
73
+ }
74
+
68
75
  arg(key, val) {
69
76
  this.opts.args.set(key, val)
70
77
  return this
@@ -79,8 +86,9 @@ class Image {
79
86
  args.push('--build-arg', `${name}=${value}`)
80
87
  }
81
88
  }
82
- const cmd = [
89
+ return [
83
90
  'build'
91
+ , `--network=${this.network}`
84
92
  , '--quiet'
85
93
  , '--tag'
86
94
  , this.name
@@ -89,7 +97,21 @@ class Image {
89
97
  , this.dockerfile
90
98
  , this.context
91
99
  ]
92
- return cmd
100
+ }
101
+
102
+ async run(cmd) {
103
+ const stream = execa('docker', [
104
+ 'run'
105
+ , '--rm'
106
+ , this.name
107
+ , ...array.toArray(cmd)
108
+ ], {all: true})
109
+
110
+ stream.stdout.pipe(process.stdout)
111
+ stream.stderr.pipe(process.stderr)
112
+
113
+ const {all} = await stream
114
+ return all
93
115
  }
94
116
 
95
117
  async build() {
package/lib/prepare.js CHANGED
@@ -17,6 +17,7 @@ async function dockerPrepare(opts, context) {
17
17
  , build_id: opts.build
18
18
  , cwd: cwd
19
19
  , context: opts.context
20
+ , network: opts.network
20
21
  })
21
22
 
22
23
  const args = {
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, logger, cwd} = context
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
 
@@ -31,6 +32,7 @@ async function verify(opts, context) {
31
32
  , build_id: opts.build
32
33
  , cwd: cwd
33
34
  , context: opts.context
35
+ , network: opts.network
34
36
  })
35
37
 
36
38
  debug('docker options', opts)
@@ -51,47 +53,59 @@ async function verify(opts, context) {
51
53
  debug('image to build', image.repo)
52
54
  if (!USERNAME && !PASSWORD) {
53
55
  debug('No docker credentials found. Skipping login')
54
- return false
56
+ } else {
57
+ await doLogin({...opts, USERNAME, PASSWORD}, context)
55
58
  }
56
59
 
60
+ if (!opts.verifycmd) return true
61
+
62
+ const img = await prepare(opts, context)
63
+ const output = await img.run(opts.verifycmd)
64
+ if (opts.dryRun) await img.clean()
65
+ return output
66
+ }
67
+
68
+ async function doLogin(opts, context) {
69
+ const {USERNAME, PASSWORD} = opts
70
+ const {logger} = context
71
+
57
72
  if (opts.login === false) {
58
73
  debug('docker login === false. Skipping login')
59
- return false
60
- }
74
+ } else {
75
+ let set = 0
76
+ if (USERNAME) set += 1
77
+ if (PASSWORD) set += 1
61
78
 
62
- let set = 0
63
- if (USERNAME) set += 1
64
- if (PASSWORD) set += 1
79
+ if (set !== 2) {
80
+ const error = new SemanticError(
81
+ 'Docker authentication failed'
82
+ , 'EAUTH'
83
+ , 'Both ENV vars DOCKER_REGISTRY_USER and DOCKER_REGISTRY_PASSWORD must be set'
84
+ )
85
+ throw error
86
+ }
65
87
 
66
- if (set !== 2) {
67
- const error = new SemanticError(
68
- 'Docker authentication failed'
69
- , 'EAUTH'
70
- , 'Both ENV vars DOCKER_REGISTRY_USER and DOCKER_REGISTRY_PASSWORD must be set'
71
- )
72
- throw error
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
- ])
88
+ const passwd = execa('echo', [PASSWORD])
89
+ const login = execa('docker', [
90
+ 'login'
91
+ , opts.registry || ''
92
+ , '-u', USERNAME
93
+ , '--password-stdin'
94
+ ])
82
95
 
83
- passwd.stdout.pipe(login.stdin)
96
+ passwd.stdout.pipe(login.stdin)
84
97
 
85
- try {
86
- await login
87
- } catch (err) {
88
- const error = new SemanticError(
89
- 'Docker authentication failed'
90
- , 'EAUTH'
91
- , `Authentication to ${opts.registry || 'dockerhub'} failed`
92
- )
93
- throw error
98
+ try {
99
+ await login
100
+ } catch (err) {
101
+ logger.fatal(err)
102
+ const error = new SemanticError(
103
+ 'Docker authentication failed'
104
+ , 'EAUTH'
105
+ , `Authentication to ${opts.registry || 'dockerhub'} failed`
106
+ )
107
+ throw error
108
+ }
109
+ logger.success('docker login successful')
94
110
  }
95
- logger.success('docker login successful')
96
- return true
97
111
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codedependant/semantic-release-docker",
3
3
  "private": false,
4
- "version": "4.0.0",
4
+ "version": "4.2.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": "^14.10.7"
76
+ "tap": "^16.0.0"
77
77
  },
78
78
  "dependencies": {
79
- "@semantic-release/error": "^2.2.0",
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",