Skip to content

Commit

Permalink
feat(docker)!: include support for buildx
Browse files Browse the repository at this point in the history
when the dockerPlatform array option is supplied and has a non zero
number of items, buildx will be used to build and push images rather
than the standard docker builder.

BREAKING CHANGE: images built with buildx will not be stored locally
BREAKING CHANGE: dockerVerifyCmd will only take effect during dry runs (--dry-run)

Fixes: #44
Fixes: #39
  • Loading branch information
esatterwhite committed Mar 22, 2024
1 parent 1a86e77 commit d0cddfa
Show file tree
Hide file tree
Showing 19 changed files with 456 additions and 189 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 0000-BASE
FROM docker:latest
ARG SRC_DIR='.'
RUN apk update && apk upgrade && apk add nodejs npm git
RUN apk update && apk upgrade && apk add nodejs npm git curl
WORKDIR /opt/app
COPY ${SRC_DIR}/package.json /opt/app/
RUN npm install
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Run `npm i --save-dev @codedependant/semantic-release-docker` to install this se

### Docker registry authentication

The `docker registry` authentication set via environment variables. It is not required, and if
Authentication to a `docker registry` is set via environment variables. It is not required, and if
omitted, it is assumed the docker daemon is already authenticated with the target registry.

### Environment variables
Expand All @@ -48,6 +48,7 @@ omitted, it is assumed the docker daemon is already authenticated with the targe
| `dockerImage` | _Optional_. The name of the image to release. | [String][] | Parsed from package.json `name` property |
| `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 | [String][] | `null` (dockerhub) |
| `dockerProject` | _Optional_. The project or repository name to publish the image to | [String][] | For scoped packages, the scope will be used, otherwise `null` |
| `dockerPlatform` | _Optional_. A list of target platofmrs to build for. If specified, [buildx][] Will be used to generate the final images | [Array][]<[String][]> | `null` (default docker build behavior) |
| `dockerFile` | _Optional_. The path, relative to `$PWD` to a Docker file to build the target image with | [String][] | `Dockerfile` |
| `dockerContext` | _Optional_. A path, relative to `$PWD` to use as the build context A | [String][] | `.` |
| `dockerLogin` | _Optional_. Set to false it by pass docker login if the docker daemon is already authorized | [String][] | `true` |
Expand All @@ -59,6 +60,19 @@ omitted, it is assumed the docker daemon is already authenticated with the targe
| `dockerBuildFlags` | _Optional_. An object containing additional flags to the `docker build` command. Values can be strings or an array of strings | [Object][] | `{}` |
| `dockerBuildCacheFrom` | _Optional_. A list of external cache sources. See [--cache-from][] | [String][] | [Array][]<[String][]> | |


### BuildX Support

Version 5.X includes initial and experimental support for multi-platform images via the [buildx][] plugin.
This plugin assumes that the docker daemon and buildx have already been setup correctly.
Platform specific builder must be setup and selected for this plugin to utilize [buildx][]

> [!WARNING]
>
> When using buildx via the dockerPlatform option, images are not kept locally
> and normal docker commands targeting those images will not work.
> The `dockerVerifyCmd` behavior will only trigger a build and is unable to execute local command
### Build Arguments

By default several build arguments will be included when the docker images is being built.
Expand Down Expand Up @@ -180,6 +194,7 @@ module.exports = {
dockerFile: 'Dockerfile',
dockerRegistry: 'quay.io',
dockerProject: 'codedependant',
dockerPlatform: ['linux/amd64', 'linux/arm64']
dockerBuildFlags: {
pull: null
, target: 'release'
Expand Down Expand Up @@ -209,7 +224,7 @@ Alternatively, using global options w/ root configuration
"dockerFile": "Dockerfile",
"dockerRegistry": "quay.io",
"dockerArgs": {
"GITHUB_TOKEN": true
"GITHUB_TOKEN": null
, "SOME_VALUE": '{{git_sha}}'
}
}
Expand Down Expand Up @@ -283,3 +298,4 @@ $ openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server.key -o
[Object]: https://mdn.io/object
[Number]: https://mdn.io/number
[--cache-from]: https://docs.docker.com/engine/reference/commandline/build/#cache-from
[buildx]: https://docs.docker.com/reference/cli/docker/buildx/build
10 changes: 10 additions & 0 deletions compose/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ services:
volumes:
- $PWD/compose/certs:/certs
- $PWD/compose/auth:/auth
docker:
privileged: true
image: docker:25-dind
environment:
DOCKER_TLS_CERTDIR: ''
DOCKER_BUILDKIT: 1
command: [
"--insecure-registry=registry:5000"
]

41 changes: 20 additions & 21 deletions compose/certs/server.crt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
-----BEGIN CERTIFICATE-----
MIID3TCCAsWgAwIBAgIUREN25M+jBRPPygoJXM4UITdE02EwDQYJKoZIhvcNAQEL
BQAwfjELMAkGA1UEBhMCVVMxEjAQBgNVBAgMCVdpc2NvbnNpbjESMBAGA1UEBwwJ
RnJhbmtsaW5lMRAwDgYDVQQKDAdjb21wYW55MRcwFQYDVQQDDA5sb2NhbGhvc3Q6
NTAwMDEcMBoGCSqGSIb3DQEJARYNdGVzdEBtYWlsLmNvbTAeFw0yNDAzMTIxODI3
MzBaFw0yNTAzMTIxODI3MzBaMH4xCzAJBgNVBAYTAlVTMRIwEAYDVQQIDAlXaXNj
b25zaW4xEjAQBgNVBAcMCUZyYW5rbGluZTEQMA4GA1UECgwHY29tcGFueTEXMBUG
A1UEAwwObG9jYWxob3N0OjUwMDAxHDAaBgkqhkiG9w0BCQEWDXRlc3RAbWFpbC5j
b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRg74DHZd3zIyO+Yy6
eWXNt1CfO17iEGauCE8xWulsdoxh1g5cphA7lICsdrMTm/2pAMnqXCg/i8Zd2gqD
kNbwk1CnMbB/zTTscMnRRLnNVp6Bm1IPtO42IiNo17ZhVBgMMol+pGWj0ytZNyNg
d+rTYS1VjIRnWl8jEKWlyEBFLRxEsBYxuv15dUiWb76XZmi8201SIwJNM82rqCoL
Qqb/StJIGT1SHtKuFi/FYNaZ1kqoQdUWQk/nLo8zt9Ml31tTebEBcShAkB2hqT/e
o0loEuGr1OVovvBSkCPf+tHit+dstmtL/5EnQGeQOXIadD/F8DKLCukLqWj5X6F3
Cn7NAgMBAAGjUzBRMB0GA1UdDgQWBBQgLEK2+ZhH6dYifsxNCo062iVBrjAfBgNV
HSMEGDAWgBQgLEK2+ZhH6dYifsxNCo062iVBrj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xkwc7INUcnIP5ZqEn5xJrTI7DjwfE/M9qArdoieOo+4UNEpxhdY
wm99IDLGkKyVUEIYKR7FG9fmedcCqdz+JKQoR/gBFAm2P2XXZQUcYc3MdhB14l8C
AwEAAaNTMFEwHQYDVR0OBBYEFCdItgsrVNAQxNOxJ1oLK0n4feCbMB8GA1UdIwQY
MBaAFCdItgsrVNAQxNOxJ1oLK0n4feCbMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI
hvcNAQELBQADggEBAE1jZt3Mgv2FkTncd5GoXFfH7zJp6d/Yq1JTckpdDLndviV/
j+q5cK1xxMFLMqqEbya8qMfrc7DeyZCTZiFZQ0BiQfR6zKm83ZsJ16aEaR8zVvRu
gdfrj9jlWZvTYpWM5G6bPTMGtcYwPBjPd/zSR+xbMSlHk5JeCSE/17evSc3Jd6i9
m7OR0SHfQD82us5VZEfZKqXUwn9frE0cLJ0PuEPOQq5914QBzrr99UWF6XMeURD0
9MZP+y9MhNK5ltTxI4wIhVNbyPFV+9g0Xfbfo8yV5evN0veUlMHwVAfm4xhMrqoW
z+kBlf7dGTzAHdqRI2KhI1nA3mrykaCe/WX2wuU=
-----END CERTIFICATE-----
52 changes: 26 additions & 26 deletions compose/certs/server.key
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDRg74DHZd3zIyO
+Yy6eWXNt1CfO17iEGauCE8xWulsdoxh1g5cphA7lICsdrMTm/2pAMnqXCg/i8Zd
2gqDkNbwk1CnMbB/zTTscMnRRLnNVp6Bm1IPtO42IiNo17ZhVBgMMol+pGWj0ytZ
NyNgd+rTYS1VjIRnWl8jEKWlyEBFLRxEsBYxuv15dUiWb76XZmi8201SIwJNM82r
qCoLQqb/StJIGT1SHtKuFi/FYNaZ1kqoQdUWQk/nLo8zt9Ml31tTebEBcShAkB2h
qT/eo0loEuGr1OVovvBSkCPf+tHit+dstmt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TAFkJnYzGiH91FN/v7VJ6MfsS6FA6OWZcj8wCpBmbzQ0djoy0RWj
fOq61tq6mnQ3sIHkh2J7ZvDycwKBgQDAtumOHJT7tpnVYeGLkI4yTh57J9SY8rR2
fw2VDoGDBt72q+vXe3dK5rALdBEw6u9OH/BH/GbeAU3vLkoPrCMDTb3gFGLKPWDF
5D6PPjhybyCgCaXA7rabfgKKmCUp5LeV9uVz2WADPP41tJVZUHHxsjxXIGuFSvi1
8UB5oiMZZQKBgGlQqn+DxKB2BadbR69nAgB0i8ApXxTWicqgPtiM28M1vWJepwLN
U/wlO7G/MxCeeQWqcq3D45b1RQlsO9/rMyIcLYWh48IFePPRzsznW6fjP03HP1ok
cV7OOia7BDjA537nABlK4a4plD276bYU10o9Xa6XjL8sZWevx9zLwa9hAoGAITRi
8ZWDJgvEXbvLvNxfY9OJ9PZb7y6CYZhqorApKIZajG366NnhKAqvconBHIieSvu9
zulyX/Yhk4CKSkECl2MhwCZDD02cCvzUuqGh4DW9jVWcNa3r0MbZcT/dx2YdK72q
s1dU77nmoyJGSWlO+LIZK3nujLzqNY8n6M1C9vECgYB01R0KZZxYmHRRoLSywWqg
1XHGk7YDXuWW7BNc4Ury023od6W+C07XEmw0rN7deubLZ+8oa7NEPKJid0K1q4HZ
f8oGTIYA0y7lLjCbYNhHafjr/iOyY/ElaHAKHtnD/EGwP2V3JLw4VTm6Jx4HtR9U
hpS4211uPw+qovrzCulLuA==
-----END PRIVATE KEY-----
10 changes: 1 addition & 9 deletions compose/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
version: '2.4'
services:
docker:
privileged: true
image: docker:stable-dind
environment:
DOCKER_TLS_CERTDIR: ''
command: [
"--insecure-registry=registry:5000"
]

semantic-release:
build:
context: ../
environment:
DOCKER_HOST: tcp://docker:2375
DOCKER_BUILDKIT: 1
TEST_DOCKER_REGISTRY: registry:5000
command: npm run tap
depends_on:
Expand Down
2 changes: 2 additions & 0 deletions lib/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function buildConfig(build_id, config, context) {
, dockerRegistry: registry = null
, dockerLogin: login = true
, dockerImage: image
, dockerPlatform: platform = null
, dockerPublish: publish = true
, dockerContext = '.'
, dockerVerifyCmd: verifycmd = null
Expand Down Expand Up @@ -75,5 +76,6 @@ async function buildConfig(build_id, config, context) {
, network: network
, quiet: typeCast(quiet) === true
, clean: typeCast(clean) === true
, platform: array.toArray(platform)
}
}
Loading

0 comments on commit d0cddfa

Please sign in to comment.