Skip to content

Commit e1cef9d

Browse files
authored
Container image build for ARM + semantic tags (#386)
* try a build * separate file * remove anchors * only login on push * fix syntax * simpler * test tags * ref_name * bookworm * remove vars * use login action * versioning * remove line * conditionals * new versioner + temp disable login * try this * more tags * readd login * reliable ifs * better permissions * default CMD --help * remove duplicate tags + simplify tag variables * v-less + distro
1 parent d9fbb9b commit e1cef9d

File tree

7 files changed

+114
-117
lines changed

7 files changed

+114
-117
lines changed

.github/workflows/build-dev.yaml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,34 @@ jobs:
2121
- os: linux
2222
arch: amd64
2323
artifact_name: dasel_linux_amd64
24-
build_docker: true
2524
test_version: true
2625
- os: linux
2726
arch: 386
2827
artifact_name: dasel_linux_386
29-
build_docker: false
3028
test_version: false
3129
- os: darwin
3230
arch: amd64
3331
artifact_name: dasel_darwin_amd64
34-
build_docker: false
3532
test_version: false
3633
- os: darwin
3734
arch: arm64
3835
artifact_name: dasel_darwin_arm64
39-
build_docker: false
4036
test_version: false
4137
- os: windows
4238
arch: amd64
4339
artifact_name: dasel_windows_amd64.exe
44-
build_docker: false
4540
test_version: false
4641
- os: windows
4742
arch: 386
4843
artifact_name: dasel_windows_386.exe
49-
build_docker: false
5044
test_version: false
5145
- os: linux
5246
arch: arm64
5347
artifact_name: dasel_linux_arm64
54-
build_docker: false
5548
test_version: false
5649
- os: linux
5750
arch: arm
5851
artifact_name: dasel_linux_arm32
59-
build_docker: false
6052
test_version: false
6153
exclude:
6254
- os: darwin
@@ -81,28 +73,3 @@ jobs:
8173
- name: Test version
8274
if: matrix.test_version == true
8375
run: ./target/release/${{ matrix.artifact_name }} --version
84-
- name: Build docker image
85-
if: matrix.build_docker == true
86-
run: |
87-
docker build --build-arg daselpath=target/release/${{ matrix.artifact_name }} -f docker/Dockerfile -t tomwright/dasel:latest .
88-
docker build --build-arg daselpath=target/release/${{ matrix.artifact_name }} -f docker/alpine.Dockerfile -t tomwright/dasel:alpine .
89-
- name: Test docker image
90-
if: matrix.build_docker == true
91-
run: |
92-
echo '{"hello": "World"}' | docker run -i --rm tomwright/dasel:latest -r json 'hello'
93-
echo '{"hello": "World"}' | docker run -i --rm tomwright/dasel:alpine -r json 'hello'
94-
- name: Docker login
95-
if: matrix.build_docker == true
96-
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u TomWright --password-stdin
97-
- name: Docker tag release
98-
if: matrix.build_docker == true
99-
run: |
100-
docker tag tomwright/dasel:latest ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}
101-
docker tag tomwright/dasel:latest ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-buster-slim
102-
docker tag tomwright/dasel:alpine ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-alpine
103-
- name: Docker push release
104-
if: matrix.build_docker == true
105-
run: |
106-
docker push ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}
107-
docker push ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-buster-slim
108-
docker push ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-alpine

.github/workflows/build-test.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,41 @@ jobs:
2525
- os: linux
2626
arch: amd64
2727
artifact_name: dasel_linux_amd64
28-
build_docker: true
2928
test_version: true
3029
test_execution: true
3130
- os: linux
3231
arch: 386
3332
artifact_name: dasel_linux_386
34-
build_docker: false
3533
test_version: false
3634
test_execution: false
3735
- os: darwin
3836
arch: amd64
3937
artifact_name: dasel_darwin_amd64
40-
build_docker: false
4138
test_version: false
4239
test_execution: false
4340
- os: darwin
4441
arch: arm64
4542
artifact_name: dasel_darwin_arm64
46-
build_docker: false
4743
test_version: false
4844
test_execution: false
4945
- os: windows
5046
arch: amd64
5147
artifact_name: dasel_windows_amd64.exe
52-
build_docker: false
5348
test_version: false
5449
test_execution: false
5550
- os: windows
5651
arch: 386
5752
artifact_name: dasel_windows_386.exe
58-
build_docker: false
5953
test_version: false
6054
test_execution: false
6155
- os: linux
6256
arch: arm64
6357
artifact_name: dasel_linux_arm64
64-
build_docker: false
6558
test_version: false
6659
test_execution: false
6760
- os: linux
6861
arch: arm
6962
artifact_name: dasel_linux_arm32
70-
build_docker: false
7163
test_version: false
7264
test_execution: false
7365
exclude:
@@ -97,13 +89,3 @@ jobs:
9789
if: matrix.test_execution == true
9890
run: |
9991
echo '{"hello": "World"}' | ./target/release/${{ matrix.artifact_name }} -r json 'hello'
100-
- name: Build docker image
101-
if: matrix.build_docker == true
102-
run: |
103-
docker build --build-arg daselpath=target/release/${{ matrix.artifact_name }} -f docker/Dockerfile -t tomwright/dasel:latest .
104-
docker build --build-arg daselpath=target/release/${{ matrix.artifact_name }} -f docker/alpine.Dockerfile -t tomwright/dasel:alpine .
105-
- name: Test docker image
106-
if: matrix.build_docker == true
107-
run: |
108-
echo '{"hello": "World"}' | docker run -i --rm tomwright/dasel:latest -r json 'hello'
109-
echo '{"hello": "World"}' | docker run -i --rm tomwright/dasel:alpine -r json 'hello'

.github/workflows/build.yaml

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ on:
22
push:
33
tags:
44
- 'v*.*.*'
5+
56
name: Build
67
jobs:
78
publish:
@@ -21,49 +22,41 @@ jobs:
2122
arch: amd64
2223
artifact_name: dasel_linux_amd64
2324
asset_name: dasel_linux_amd64
24-
build_docker: true
2525
test_version: true
2626
- os: linux
2727
arch: 386
2828
artifact_name: dasel_linux_386
2929
asset_name: dasel_linux_386
30-
build_docker: false
3130
test_version: false
3231
- os: darwin
3332
arch: amd64
3433
artifact_name: dasel_darwin_amd64
3534
asset_name: dasel_darwin_amd64
36-
build_docker: false
3735
test_version: false
3836
- os: darwin
3937
arch: arm64
4038
artifact_name: dasel_darwin_arm64
4139
asset_name: dasel_darwin_arm64
42-
build_docker: false
4340
test_version: false
4441
- os: windows
4542
arch: amd64
4643
artifact_name: dasel_windows_amd64.exe
4744
asset_name: dasel_windows_amd64.exe
48-
build_docker: false
4945
test_version: false
5046
- os: windows
5147
arch: 386
5248
artifact_name: dasel_windows_386.exe
5349
asset_name: dasel_windows_386.exe
54-
build_docker: false
5550
test_version: false
5651
- os: linux
5752
arch: arm64
5853
artifact_name: dasel_linux_arm64
5954
asset_name: dasel_linux_arm64
60-
build_docker: false
6155
test_version: false
6256
- os: linux
6357
arch: arm
6458
artifact_name: dasel_linux_arm32
6559
asset_name: dasel_linux_arm32
66-
build_docker: false
6760
test_version: false
6861
exclude:
6962
- os: darwin
@@ -80,7 +73,7 @@ jobs:
8073
- uses: actions/checkout@v3
8174
- uses: actions/setup-go@v4
8275
with:
83-
go-version: '^1.21.0' # The Go version to download (if necessary) and use.
76+
go-version: '^1.21.0'
8477
- name: Set env
8578
run: echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV
8679
- name: Build
@@ -104,40 +97,3 @@ jobs:
10497
file: target/release/${{ matrix.artifact_name }}.gz
10598
asset_name: ${{ matrix.asset_name }}.gz
10699
tag: ${{ github.ref }}
107-
- name: Build docker image
108-
if: matrix.build_docker == true
109-
run: |
110-
docker build --build-arg daselpath=target/release/${{ matrix.artifact_name }} -f docker/Dockerfile -t tomwright/dasel:latest .
111-
docker build --build-arg daselpath=target/release/${{ matrix.artifact_name }} -f docker/alpine.Dockerfile -t tomwright/dasel:alpine .
112-
- name: Test docker image
113-
if: matrix.build_docker == true
114-
run: |
115-
echo '{"hello": "World"}' | docker run -i --rm tomwright/dasel:latest -r json 'hello'
116-
echo '{"hello": "World"}' | docker run -i --rm tomwright/dasel:alpine -r json 'hello'
117-
- name: Docker login
118-
if: matrix.build_docker == true
119-
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u TomWright --password-stdin
120-
- name: Docker tag latest
121-
if: matrix.build_docker == true
122-
run: |
123-
docker tag tomwright/dasel:latest ghcr.io/tomwright/dasel:latest
124-
docker tag tomwright/dasel:latest ghcr.io/tomwright/dasel:buster-slim
125-
docker tag tomwright/dasel:alpine ghcr.io/tomwright/dasel:alpine
126-
- name: Docker tag release
127-
if: matrix.build_docker == true
128-
run: |
129-
docker tag tomwright/dasel:latest ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}
130-
docker tag tomwright/dasel:latest ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-buster-slim
131-
docker tag tomwright/dasel:alpine ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-alpine
132-
- name: Docker push latest
133-
if: matrix.build_docker == true
134-
run: |
135-
docker push ghcr.io/tomwright/dasel:latest
136-
docker push ghcr.io/tomwright/dasel:buster-slim
137-
docker push ghcr.io/tomwright/dasel:alpine
138-
- name: Docker push release
139-
if: matrix.build_docker == true
140-
run: |
141-
docker push ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}
142-
docker push ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-buster-slim
143-
docker push ghcr.io/tomwright/dasel:${{ env.RELEASE_VERSION }}-alpine

.github/workflows/container.yaml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
on: [push, pull_request]
2+
3+
env:
4+
GOLANG_VERSION: 1
5+
IMAGE_NAME: ghcr.io/tomwright/dasel
6+
7+
name: Container build, test and publish
8+
jobs:
9+
container:
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
include:
14+
- distro: alpine
15+
distro-tag: latest
16+
- distro: debian
17+
distro-tag: bookworm-slim
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
- name: Process version tag
27+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
28+
uses: nowsprinting/check-version-format-action@v4
29+
id: version
30+
with:
31+
prefix: 'v'
32+
- name: Build and Export
33+
uses: docker/build-push-action@v5
34+
with:
35+
context: .
36+
load: true
37+
build-args: |
38+
GOLANG_VERSION=${{ env.GOLANG_VERSION }}
39+
RELEASE_VERSION=${{ github.ref_name }}
40+
MAJOR_VERSION=${{ steps.version.outputs.major || 'v2' }}
41+
TARGET_BASE_IMAGE=${{ matrix.distro }}:${{ matrix.distro-tag }}
42+
tags: dasel:test
43+
- name: Test
44+
run: |
45+
echo '{"hello": "World"}' | docker run -i --rm dasel:test -r json 'hello'
46+
- name: Set version tag variables
47+
if: ${{ steps.version.outputs.is_valid == 'true' }}
48+
run: |
49+
IMAGE=${{ env.IMAGE_NAME }}
50+
MAJOR=${{ steps.version.outputs.major_without_prefix }}
51+
MINOR=${{ steps.version.outputs.minor }}
52+
PATCH=${{ steps.version.outputs.patch }}
53+
54+
if [ "${{ matrix.distro }}" = "alpine" ]; then
55+
echo "VERSIONED_TAGS<<EOF" >> $GITHUB_ENV
56+
echo "${IMAGE}:alpine" >> $GITHUB_ENV
57+
echo "${IMAGE}:${{ github.ref_name }}-alpine" >> $GITHUB_ENV
58+
echo "${IMAGE}:${MAJOR}-alpine" >> $GITHUB_ENV
59+
echo "${IMAGE}:${MAJOR}.${MINOR}-alpine" >> $GITHUB_ENV
60+
echo "${IMAGE}:${MAJOR}.${MINOR}.${PATCH}-alpine" >> $GITHUB_ENV
61+
echo "EOF" >> $GITHUB_ENV
62+
else
63+
echo "VERSIONED_TAGS<<EOF" >> $GITHUB_ENV
64+
echo "${IMAGE}:latest" >> $GITHUB_ENV
65+
echo "${IMAGE}:${{ github.ref_name }}" >> $GITHUB_ENV
66+
echo "${IMAGE}:${{ github.ref_name }}-${{ matrix.distro-tag }}" >> $GITHUB_ENV
67+
echo "${IMAGE}:${MAJOR}-${{ matrix.distro-tag }}" >> $GITHUB_ENV
68+
echo "${IMAGE}:${MAJOR}.${MINOR}-${{ matrix.distro-tag }}" >> $GITHUB_ENV
69+
echo "${IMAGE}:${MAJOR}.${MINOR}.${PATCH}-${{ matrix.distro-tag }}" >> $GITHUB_ENV
70+
echo "${IMAGE}:${MAJOR}" >> $GITHUB_ENV
71+
echo "${IMAGE}:${MAJOR}.${MINOR}" >> $GITHUB_ENV
72+
echo "${IMAGE}:${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_ENV
73+
echo "EOF" >> $GITHUB_ENV
74+
fi
75+
- name: Login to GitHub Container Registry
76+
if: ${{ steps.version.outputs.is_valid == 'true' }}
77+
uses: docker/login-action@v3
78+
with:
79+
registry: ghcr.io
80+
username: TomWright
81+
password: ${{ secrets.GHCR_PAT }}
82+
- name: Build and Push
83+
if: ${{ steps.version.outputs.is_valid == 'true' }}
84+
uses: docker/build-push-action@v5
85+
with:
86+
context: .
87+
platforms: linux/amd64,linux/arm64
88+
push: true
89+
build-args: |
90+
GOLANG_VERSION=${{ env.GOLANG_VERSION }}
91+
RELEASE_VERSION=${{ github.ref_name }}
92+
MAJOR_VERSION=${{ steps.version.outputs.major }}
93+
TARGET_BASE_IMAGE=${{ matrix.distro }}:${{ matrix.distro-tag }}
94+
tags: ${{ env.VERSIONED_TAGS }}

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ARG GOLANG_VERSION=1
2+
ARG TARGET_BASE_IMAGE=debian:bookworm-slim
3+
FROM golang:${GOLANG_VERSION} AS builder
4+
5+
ARG MAJOR_VERSION=v2
6+
ARG RELEASE_VERSION=master
7+
ARG CGO_ENABLED=0
8+
9+
COPY . .
10+
11+
RUN go build -o /dasel -ldflags="-X 'github.com/tomwright/dasel/${MAJOR_VERSION}/internal.Version=${RELEASE_VERSION}'" ./cmd/dasel
12+
13+
FROM ${TARGET_BASE_IMAGE}
14+
15+
COPY --from=builder --chmod=755 /dasel /usr/local/bin/dasel
16+
17+
ENTRYPOINT ["/usr/local/bin/dasel"]
18+
CMD ["--help"]

docker/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

docker/alpine.Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)