Skip to content

Commit e114ece

Browse files
committed
refactor: Improve CI/CD workflow with Docker Buildx and GitHub Container Registry setup
Build the containers before the release is created as a part of semantic-release process. Signed-off-by: Eden Reich <eden.reich@gmail.com>
1 parent 02dd3dd commit e114ece

File tree

2 files changed

+32
-54
lines changed

2 files changed

+32
-54
lines changed

internal/templates/common/config/releaserc.yaml.tmpl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,26 @@ plugins:
5050
verifyConditions: true
5151
5252
- - '@semantic-release/exec'
53-
- prepareCmd: 'sed -i "/^metadata:/,/^spec:/ s/version: \"[^\"]*\"/version: \"${nextRelease.version}\"/" agent.yaml'
53+
- prepareCmd: |
54+
sed -i "/^metadata:/,/^spec:/ s/version: \"[^\"]*\"/version: \"${nextRelease.version}\"/" agent.yaml
55+
task generate
56+
publishCmd: |
57+
echo "Building and pushing Docker image for version ${nextRelease.version}"
58+
docker buildx build --platform linux/amd64,linux/arm64 \
59+
--tag ghcr.io/${GITHUB_REPOSITORY,,}:${nextRelease.version} \
60+
--tag ghcr.io/${GITHUB_REPOSITORY,,}:latest \
61+
--push .
5462
5563
- - '@semantic-release/git'
5664
- assets:
5765
- CHANGELOG.md
5866
- agent.yaml
67+
- AGENTS.md
68+
- Dockerfile
69+
- main.go
70+
- README.md
71+
- Taskfile.yml
72+
- .well-known/agent.json
5973
message: "chore(release): 🔖 ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
6074
6175
- - '@semantic-release/github'

internal/templates/common/github/workflows/cd.yaml.tmpl

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ jobs:
132132
- name: Build
133133
run: task build
134134
{{- end }}
135+
- name: Set up QEMU
136+
uses: docker/setup-qemu-action@v3
137+
with:
138+
platforms: all
139+
140+
- name: Set up Docker Buildx
141+
uses: docker/setup-buildx-action@v3
142+
with:
143+
version: latest
144+
145+
- name: Log in to GitHub Container Registry
146+
uses: docker/login-action@v3
147+
with:
148+
registry: ghcr.io
149+
username: ${{`{{ github.actor }}`}}
150+
password: ${{`{{ secrets.GITHUB_TOKEN }}`}}
135151

136152
- name: Set up Node.js for semantic-release
137153
uses: actions/setup-node@v4.4.0
@@ -157,6 +173,7 @@ jobs:
157173
{{- else }}
158174
GITHUB_TOKEN: ${{`{{ secrets.GITHUB_TOKEN }}`}}
159175
{{- end }}
176+
GITHUB_REPOSITORY: ${{`{{ github.repository }}`}}
160177
run: |
161178
# Create first release if not exists - Initial Release Version 0.1.0
162179
if ! gh release view v0.1.0 >/dev/null 2>&1; then
@@ -191,59 +208,6 @@ jobs:
191208
echo "Release failed"
192209
exit 1
193210
fi
194-
195-
build_and_push_image:
196-
name: Build and Push Container Image
197-
runs-on: ubuntu-24.04
198-
needs: release
199-
if: needs.release.outputs.new_release_published == 'true'
200-
steps:
201-
- name: Checkout code
202-
uses: actions/checkout@v4.2.2
203-
with:
204-
ref: ${{`{{ github.ref }}`}}
205-
fetch-depth: 0
206-
207-
- name: Set up QEMU
208-
uses: docker/setup-qemu-action@v3
209-
with:
210-
platforms: all
211-
212-
- name: Set up Docker Buildx
213-
uses: docker/setup-buildx-action@v3
214-
with:
215-
version: latest
216-
217-
- name: Log in to GitHub Container Registry
218-
uses: docker/login-action@v3
219-
with:
220-
registry: ghcr.io
221-
username: ${{`{{ github.actor }}`}}
222-
password: ${{`{{ secrets.GITHUB_TOKEN }}`}}
223-
224-
- name: Extract metadata
225-
id: meta
226-
uses: docker/metadata-action@v5
227-
with:
228-
images: ghcr.io/${{`{{ github.repository_owner }}`}}/${{`{{ github.event.repository.name }}`}}
229-
tags: |
230-
type=ref,event=branch
231-
type=ref,event=pr
232-
type=semver,pattern={{`{{version}}`}},value=${{`{{ needs.release.outputs.new_release_version }}`}}
233-
type=semver,pattern={{`{{major}}.{{minor}}`}},value=${{`{{ needs.release.outputs.new_release_version }}`}}
234-
type=raw,value=latest
235-
236-
- name: Build and push Docker image
237-
uses: docker/build-push-action@v6
238-
with:
239-
context: .
240-
platforms: linux/amd64,linux/arm64
241-
push: true
242-
tags: ${{`{{ steps.meta.outputs.tags }}`}}
243-
labels: ${{`{{ steps.meta.outputs.labels }}`}}
244-
cache-from: type=gha
245-
cache-to: type=gha,mode=max
246-
247211
{{- if .ADL.Spec.Deployment }}
248212

249213
deploy:

0 commit comments

Comments
 (0)