-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
51 lines (45 loc) · 2.75 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
stages:
- build
- push
- deploy
variables:
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_CLI_EXPERIMENTAL: enabled
default:
retry: 2
image: registry.gitlab.com/adi90x/docker-buildx-qemu
services:
- docker:dind
before_script:
- if [ $CI_BUILD_REF_NAME == "master" ]; then tag="latest"; else tag=$CI_BUILD_REF_NAME; fi
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Use docker-container driver to allow useful features (push/multi-platform)
#- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker run --privileged --rm registry.gitlab.com/adi90x/multiarch --install all
- docker buildx create --driver docker-container --use
- kap_version=`echo "$(echo $CI_COMMIT_REF_NAME)"@"$(echo $CI_COMMIT_SHA | cut -c -7)"`
- version_available=$(curl --write-out %{http_code} --silent --output /dev/null https://gitlab.com/adi90x/kube-template-kap/builds/artifacts/$CI_BUILD_REF_NAME/browse?job=compile-go)
- if [ $version_available == "302" ]; then build_version=artifacts/$CI_BUILD_REF_NAME; else build_version="artifacts/master"; fi
- if [ $FORCE_KUBE_GEN_VERSION != "" ]; then build_version=$FORCE_KUBE_GEN_VERSION/artifacts; fi
#- docker buildx inspect --bootstrap # Not need only for debug
#- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel => Move to host setup
# Set USE_CACHE=--no-cache if need to force rebuild
build-amd64:
stage: build
script:
- docker buildx build $USE_CACHE --compress --progress plain --build-arg VERSION_KUBE_GEN=$build_version --build-arg KAP_VERSION=$kap_version --platform linux/amd64 --cache-from="$CI_REGISTRY_IMAGE"/cache/amd64 --cache-to=type=registry,ref="$CI_REGISTRY_IMAGE"/cache/amd64,mode=max --pull -t "$CI_REGISTRY_IMAGE"/amd64:$tag --push .
build-arm64:
stage: build
script:
- docker buildx build $USE_CACHE --compress --progress plain --build-arg VERSION_KUBE_GEN=$build_version --build-arg KAP_VERSION=$kap_version --platform linux/arm64 --cache-from="$CI_REGISTRY_IMAGE"/cache/amd64 --cache-to=type=registry,ref="$CI_REGISTRY_IMAGE"/cache/arm64,mode=max --pull -t "$CI_REGISTRY_IMAGE"/arm64:$tag --push .
push-image:
stage: push
script:
- docker buildx build --compress --progress plain --build-arg VERSION_KUBE_GEN=$build_version --build-arg KAP_VERSION=$kap_version --platform linux/arm64,linux/amd64 --cache-from="$CI_REGISTRY_IMAGE"/cache/amd64,"$CI_REGISTRY_IMAGE"/cache/arm64 --pull -t "$CI_REGISTRY_IMAGE":$tag --push .
deploy-k3s:
stage: deploy
script:
- mkdir -p ~/.kube/ && echo $KUBE_CONFIG_64 | base64 -d > ~/.kube/config
- kubectl -n default rollout restart deploy/kube-active-proxy