Skip to content

Commit 2bd35d0

Browse files
build (docker.yml): add buildx tasks
1 parent b5c7627 commit 2bd35d0

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

{{cookiecutter.project_slug}}/taskfiles/docker.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,73 @@ tasks:
115115
cmds:
116116
- docker system prune --all --force
117117
- docker builder prune --all --force
118+
119+
create-builder:
120+
desc: "Create a local docker buildx builder"
121+
cmds:
122+
- |
123+
docker buildx create \
124+
--name multi-platform \
125+
--node multi-platform \
126+
--platform linux/arm64/v8,linux/amd64 \
127+
--driver=docker-container \
128+
--use \
129+
--bootstrap
130+
status:
131+
- docker buildx inspect multi-platform > /dev/null 2>&1
132+
133+
validate:
134+
desc: Validate the docker-bake.hcl file
135+
vars:
136+
BAKE_OUTPUT:
137+
sh: docker buildx bake --file docker-bake.hcl --print 2>&1 || true
138+
VALIDATION_ERROR:
139+
sh: echo "{{.BAKE_OUTPUT}}" | grep -q "ERROR:" && echo "true" || echo "false"
140+
preconditions:
141+
- sh: "test {{.VALIDATION_ERROR}} = false"
142+
msg: |
143+
Docker bake file is invalid. Error details:
144+
{{.BAKE_OUTPUT}}
145+
cmds:
146+
- cmd: echo "Docker bake file is valid"
147+
silent: true
148+
149+
buildx:
150+
desc: "Build using docker buildx bake"
151+
summary: |
152+
Build using docker buildx bake with the specified target.
153+
154+
AVAILABLE TARGETS
155+
- build (default): Builds the main image
156+
- amd64: Builds specifically for AMD64 platform
157+
- arm64: Builds specifically for ARM64 platform
158+
- multi-platform: Builds for both AMD64 and ARM64 platforms
159+
160+
USAGE
161+
task docker:buildx
162+
task docker:buildx -- amd64
163+
task docker:buildx -- arm64
164+
task docker:buildx -- multi-platform
165+
deps:
166+
- validate
167+
- create-builder
168+
cmds:
169+
- |
170+
if [ -z "{{.CLI_ARGS}}" ]; then
171+
TARGET="build"
172+
else
173+
case "{{.CLI_ARGS}}" in
174+
build|amd64|arm64|multi-platform)
175+
TARGET="{{.CLI_ARGS}}"
176+
;;
177+
*)
178+
echo "Error: Invalid target '{{.CLI_ARGS}}'"
179+
echo "Valid targets are: build, amd64, arm64, multi-platform"
180+
exit 1
181+
;;
182+
esac
183+
fi
184+
185+
docker buildx bake \
186+
--file docker-bake.hcl \
187+
$TARGET

0 commit comments

Comments
 (0)