-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitlab-ci.yml
104 lines (93 loc) · 3.62 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Tweaked from https://gitlab.com/moos-ivp/moosdocker/blob/c2b5919cfeb885f85e8fbec75e5ff4f540ef1c89/.gitlab-ci.yml
image: jonoh/docker-buildx-qemu@sha256:3099978f865c0a92182c5bb0744a4b9ad764072196e5af745acd040efec394d8
services:
- docker:dind
stages:
- build
- deploy
variables:
GIT_SUBMODULE_STRATEGY: recursive
DOCKER_HOST: tcp://docker:2375/
DEPLOY_ARCHS: "amd64 arm64 armv7"
INDEV_IMAGE_NAME: "${CI_REGISTRY_IMAGE}/${CI_COMMIT_REF_SLUG}:${CI_COMMIT_SHORT_SHA}"
# Build
.build_generic:
stage: build
script:
- update-binfmts --enable
- docker buildx create --use
- docker buildx inspect --bootstrap
- export BUILD_ARCH_NICE="$(echo $BUILD_ARCH | sed 's/^[^\/]*\///g' | sed 's/\///')"
- echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- export NEW_IMAGE_NAME="${INDEV_IMAGE_NAME}-${BUILD_ARCH_NICE}" && echo $NEW_IMAGE_NAME
- docker buildx build --push --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from "${CI_REGISTRY_IMAGE}:latest" --platform "${BUILD_ARCH}" -t "$NEW_IMAGE_NAME" .
- echo "Checking for existance of image ${INDEV_IMAGE_NAME}"
- docker buildx imagetools inspect "${INDEV_IMAGE_NAME}" || export IMAGE_EXISTS="false"
- if [[ "$IMAGE_EXISTS" == "false" ]]; then echo "Creating image..."; docker buildx imagetools create -t "${INDEV_IMAGE_NAME}" "$NEW_IMAGE_NAME"; fi
- if [[ "$IMAGE_EXISTS" != "false" ]]; then echo "Appending to image..."; docker buildx imagetools create --append -t "${INDEV_IMAGE_NAME}" "$NEW_IMAGE_NAME"; fi
build-multiarch:
extends: .build_generic
timeout: 3h
parallel:
matrix:
- BUILD_ARCH: [linux/amd64, linux/arm64, linux/arm/v7]
# Deploy
.deploy_generic_manifest: &deploy_generic_manifest
stage: deploy
except:
- merge_requests
- external_pull_requests
script:
- update-binfmts --enable
- docker buildx create --use
- docker buildx inspect --bootstrap
- echo "$REGISTRY_PASSWD" | docker login --username $REGISTRY_USER --password-stdin $REGISTRY_URL
- export DOCKER_CLI_EXPERIMENTAL=enabled
# TODO dynamically get matching tags via registry API
- >
for arch in $DEPLOY_ARCHS; do
docker pull "${INDEV_IMAGE_NAME}-${arch}"
export ARCH_IMAGES_CACHE="$ARCH_IMAGES_CACHE --cache-from ${INDEV_IMAGE_NAME}-${arch}"
done
- docker buildx build --push --pull $ARCH_IMAGES_CACHE --build-arg BUILDKIT_INLINE_CACHE=1 --platform="linux/amd64,linux/arm64,linux/arm/v7" -t "${REPO_PATH}:${CI_COMMIT_SHORT_SHA}" -t "${REPO_PATH}:latest" .
#deploy-gitlab-registry:
# extends: .deploy_generic_manifest
# variables:
# REGISTRY_URL: "$CI_REGISTRY"
# REGISTRY_USER: "$CI_REGISTRY_USER"
# REGISTRY_PASSWD: "$CI_REGISTRY_PASSWORD"
# REPO_PATH: "$CI_REGISTRY_IMAGE"
deploy-quay-registry:
extends: .deploy_generic_manifest
variables:
REGISTRY_URL: "quay.io"
REGISTRY_USER: "$QUAY_USERNAME"
REGISTRY_PASSWD: "$QUAY_PUSH_KEY"
REPO_PATH: "${REGISTRY_URL}/herocc/moos-ivp-cc"
deploy-docker-hub-registry:
extends: .deploy_generic_manifest
only:
refs:
- master
- schedules
variables:
REGISTRY_URL: "docker.io"
REGISTRY_USER: "$DOCKER_HUB_USERNAME"
REGISTRY_PASSWD: "$DOCKER_HUB_PUSH_KEY"
REPO_PATH: "${REGISTRY_URL}/herocc/moos-ivp-cc"
save-artifacts:
stage: deploy
services: []
image: "${INDEV_IMAGE_NAME}"
variables:
GIT_STRATEGY: none
GIT_SUBMODULE_STRATEGY: none
script:
- cd /home/moos/moos-ivp-cc/
- echo "Saving Artifacts..."
- echo "bin:" && cp -rv bin "$CI_PROJECT_DIR"
- echo "lib:" && cp -rv lib "$CI_PROJECT_DIR"
artifacts:
paths:
- bin/
- lib/