This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
134 lines (128 loc) · 4.31 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
variables:
# Job and build settings
CI_BUILD_IMAGE: "debian:stable-slim"
CI_BUILDX_ARCHS: 'linux/amd64,linux/arm64,linux/arm/7'
# Docker and BuildKit variables
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_CERT_PATH: "/certs/client"
DOCKER_TLS: 'true'
DOCKER_HOST: tcp://docker:2376/
BUILDKIT_INLINE_CACHE: '1'
DOCKER_CLI_EXPERIMENTAL: 'enabled'
# Dockerhub variables
DOCKERHUB_REPO_NAME: docker-buildx-qemu
# Debian variables
DEBIAN_FRONTEND: 'noninteractive'
TERM: 'linux'
stages:
- build
- release
services:
- docker:dind
.init:
interruptible: true
image: ${CI_BUILD_IMAGE}
before_script:
- cp debian-backports-pin-600.pref /etc/apt/preferences.d/
- cp debian-backports.list /etc/apt/sources.list.d/
- apt-get update
- |
apt-get install -y --no-install-recommends \
apt-transport-https \
gnupg2 \
software-properties-common \
\
ca-certificates \
\
git \
jq \
curl \
\
binfmt-support \
qemu-user-static
# Workaround for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=923479
- c_rehash
- curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
- add-apt-repository "deb https://download.docker.com/linux/debian $(lsb_release -cs) stable"
- apt-get update
- |
apt-get install -y --no-install-recommends \
docker-ce-cli
- export BUILDX_NAME="buildx-$(tr -cd '[:alnum:]' < /dev/urandom | fold -w6 | head -n1)"
- docker version && docker buildx version && qemu-x86_64-static --version
- docker context create "${BUILDX_NAME}"
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
- docker buildx create --driver docker-container --name "${BUILDX_NAME}" --use "${BUILDX_NAME}"
- docker buildx inspect --bootstrap
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
- |
if [ -n "${DOCKERHUB_USERNAME:-}" ] \
&& [ -n "${DOCKERHUB_PASSWORD:-}" ] \
&& [ -n "${DOCKERHUB_REPO_NAME:-}" ] \
; then \
echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin; \
fi
build:dev:
extends:
- .init
stage: build
except:
refs:
- tags
script:
- find . -name build.sh -maxdepth 1 -exec sh {} ';'
- export TAG="dev-master"
# Use the tag `dev-master` if there's a commit to master, else use `dev-branch` for feature branches
- if [ ! "${CI_COMMIT_REF_NAME}" == "master" ]; then export TAG="dev-branch"; fi
- export IMAGE="${CI_REGISTRY_IMAGE}:${TAG}"
- export DESTINATION="--tag=${IMAGE}"
- |
if [[ ( -n "${DOCKERHUB_REPO_NAME:-}" ) && ( -n "${DOCKERHUB_PASSWORD:-}" ) ]]; then \
export DESTINATION="${DESTINATION} --tag=${DOCKERHUB_REPO_PREFIX}/${DOCKERHUB_REPO_NAME}:${TAG}"; \
fi
- |
set -x; \
docker buildx build \
--platform=$CI_BUILDX_ARCHS \
--progress=plain \
${DESTINATION} \
--push .
build:release:
extends:
- .init
stage: release
only:
refs:
- tags
script:
- find . -name build.sh -maxdepth 1 -exec sh {} \;
# Use the tag `latest` and the actual git tag for all the tags
- export IMAGE="${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}"
- export DESTINATION="--tag=${IMAGE}"
- export DESTINATION="${DESTINATION} --tag=${CI_REGISTRY_IMAGE}:latest"
- |
if [[ ( -n "${DOCKERHUB_REPO_NAME:-}" ) && ( -n "${DOCKERHUB_PASSWORD:-}" ) ]]; then \
export DESTINATION="${DESTINATION} --tag=${DOCKERHUB_REPO_PREFIX}/${DOCKERHUB_REPO_NAME}:${CI_COMMIT_REF_NAME}"; \
export DESTINATION="${DESTINATION} --tag=${DOCKERHUB_REPO_PREFIX}/${DOCKERHUB_REPO_NAME}:latest"; \
fi
- |
set -x; \
docker buildx build \
--platform=$CI_BUILDX_ARCHS \
--progress=plain \
${DESTINATION} \
--push .
dockerhub:readme:
stage: release
variables:
README_PATH: ${CI_PROJECT_DIR}/README.md
rules:
- if: '$CI_COMMIT_REF_NAME == "master" && $DOCKERHUB_REPO_NAME =~ /.+/ && $DOCKERHUB_PASSWORD =~ /.+/'
when: on_success
image:
name: sheogorath/readme-to-dockerhub:latest
entrypoint: ['']
script:
- node /app/index.js