Skip to content

Commit cccd903

Browse files
committed
Make target and platform optional
Signed-off-by: Federico Busetti <[email protected]>
1 parent 1310c54 commit cccd903

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

.gitlab_ci/_templates.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ variables:
1212
- docker:$DOCKER_VERSION-dind
1313
variables:
1414
DOCKER_BUILDKIT: 1
15-
DOCKER_PLATFORM: "linux/amd64"
16-
# TODO: Make target optional
17-
DOCKER_TARGET: dev
15+
DOCKER_PLATFORM: ""
16+
DOCKER_TARGET: ""
1817
before_script:
1918
- apk add --no-cache bash git
2019
script:
2120
- docker buildx create --use
2221
- docker buildx inspect --bootstrap
2322
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
2423
- echo "Building $DOCKER_IMAGE_FULL_TAG - Cache from $DOCKER_IMAGE_NAME:cache"
24+
- if [[ -n "$DOCKER_TARGET" ]]; then export TARGET_ARG="--target $DOCKER_TARGET"; fi;
25+
- if [[ -n "$DOCKER_PLATFORM" ]]; then export PLATFORM_ARG="--platform $DOCKER_PLATFORM"; fi;
26+
- if [[ -n "$DOCKER_PLATFORM" ]]; then export PLATFORM_SUFFIX="-$(echo $DOCKER_PLATFORM | sed 's/\///')"; fi;
2527
# remove \ from platform to
2628
- export SUFFIX=$(echo $DOCKER_PLATFORM | sed 's/\///')
2729
- |
2830
docker buildx build --push \
29-
--target $DOCKER_TARGET \
30-
--tag $DOCKER_IMAGE_FULL_TAG-$SUFFIX \
31-
--platform $DOCKER_PLATFORM \
31+
$TARGET_ARG \
32+
--tag $DOCKER_IMAGE_FULL_TAG$PLATFORM_SUFFIX \
33+
$PLATFORM_ARG \
3234
--cache-from type=registry,ref=$DOCKER_IMAGE_NAME:cache \
3335
--cache-to type=registry,ref=$DOCKER_IMAGE_NAME:cache \
3436
.

0 commit comments

Comments
 (0)