Skip to content

Commit 7cb8983

Browse files
committed
Create multi-arch build template
Signed-off-by: Federico Busetti <[email protected]>
1 parent 8bee950 commit 7cb8983

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

.gitlab_ci/_templates.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build Docker image for test
2+
.build-and-push-gitlab:
3+
image: docker:24.0.2
4+
services:
5+
- docker:24.0.2-dind
6+
variables:
7+
DOCKER_BUILDKIT: 1
8+
DOCKER_IMAGE_NAME: $CI_PROJECT_NAME
9+
DOCKER_IMAGE_TAG: $CI_COMMIT_SHA
10+
DOCKER_IMAGE_TAG_SUFFIX: ""
11+
DOCKER_PLATFORM: "linux/arm64,linux/amd64"
12+
DOCKER_TARGET: dev
13+
before_script:
14+
- apk add --no-cache qemu bash git
15+
script:
16+
- docker buildx create --use
17+
- docker buildx inspect --bootstrap
18+
- |
19+
docker buildx build --load \
20+
--target=$DOCKER_TARGET \
21+
--tag=$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG$DOCKER_IMAGE_TAG_SUFFIX \
22+
--platform=$DOCKER_PLATFORM \
23+
--cache-to=type=local,dest=/tmp/.buildx-cache \
24+
--cache-from=type=local,src=/tmp/.buildx-cache \
25+
.
26+
artifacts:
27+
paths:
28+
- /tmp/.buildx-cache
29+
expire_in: 1h

.gitlab_ci/build.yml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
# Build Docker image for test
22
build-test:
33
stage: build
4-
image: docker:24.0.2
5-
services:
6-
- docker:24.0.2-dind
74
variables:
8-
DOCKER_BUILDKIT: 1
9-
before_script:
10-
- apk add --no-cache qemu bash git
11-
script:
12-
- docker buildx create --use
13-
- docker buildx inspect --bootstrap
14-
- |
15-
docker buildx build --load --target=dev --tag=$TEST_TAG \
16-
--cache-to=type=local,dest=/tmp/.buildx-cache \
17-
--cache-from=type=local,src=/tmp/.buildx-cache \
18-
.
19-
artifacts:
20-
paths:
21-
- /tmp/.buildx-cache
22-
expire_in: 1h
23-
24-
5+
DOCKER_IMAGE_TAG_SUFFIX: "-test"
6+
rules:
7+
# We run the pipeline only on merge requests or the `main` branch
8+
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
9+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
10+
extends:
11+
- .build-and-push-gitlab

0 commit comments

Comments
 (0)