-
Notifications
You must be signed in to change notification settings - Fork 55
/
.gitlab-ci.yml
82 lines (74 loc) · 2.18 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
variables:
REGISTRY: d.nyodev.xyz
SERVICE: lets
IMAGE: ripple/$SERVICE
SOURCE_BRANCH: master
PRODUCTION_BRANCH: production
GIT_SUBMODULE_STRATEGY: recursive
default:
before_script:
- TAG=$(cat version | tr -d '\n')
stages:
- build-docker
- release
- deploy
build-docker:
stage: build-docker
image: docker:20
services:
- docker:20-dind
variables:
DOCKERFILE: lets.Dockerfile
before_script:
# prep steps
- docker info
- docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD $REGISTRY
# fetches the latest image for this branch (not failing if image is not found)
- BRANCH_FOR_DOCKER=$(echo $CI_COMMIT_BRANCH | sed s#/#__#g)
- docker pull $REGISTRY/$IMAGE:$BRANCH_FOR_DOCKER || true
# get Dockerfile
- apk update
- apk add git
- git clone https://${GIT_USERNAME:-gitlab-ci-token}:${GIT_PASSWORD:-$CI_JOB_TOKEN}@zxq.co/ripple/dockerfiles.git /dockerfiles
- cp /dockerfiles/dockerfiles/$DOCKERFILE $(pwd)/Dockerfile
script:
- >
docker build
--pull
--build-arg http_proxy=$http_proxy
--build-arg https_proxy=$https_proxy
--build-arg no_proxy=$no_proxy
--build-arg VCS_REF=$CI_COMMIT_SHA
--build-arg VCS_URL=$CI_PROJECT_URL
--build-arg GIT_COMMIT_SHA=$CI_COMMIT_SHA
--cache-from $REGISTRY/$IMAGE:latest
--tag $REGISTRY/$IMAGE:$CI_COMMIT_SHA
.
# Tag and push (tags: "git commit hash" and "branch name")
- docker tag $REGISTRY/$IMAGE:$CI_COMMIT_SHA $REGISTRY/$IMAGE:$BRANCH_FOR_DOCKER
- docker push $REGISTRY/$IMAGE:$CI_COMMIT_SHA
- docker push $REGISTRY/$IMAGE:$BRANCH_FOR_DOCKER
rules:
- if: $CI_COMMIT_BRANCH == $SOURCE_BRANCH
release:
stage: release
needs: ["build-docker"]
image: d.nyodev.xyz/ripple/gitlab-ci-tools
script:
- merge-into-production
rules:
- if: $CI_COMMIT_BRANCH == $SOURCE_BRANCH
when: manual
deploy:
stage: deploy
image: d.nyodev.xyz/ripple/gitlab-ci-tools
services:
- docker:20-dind
variables:
DEPLOY_URL: https://deploy.ripple.moe
DEPLOY_SECRET: $DEPLOY_SECRET
script:
- tag-image-with-version $TAG
- deploy $SERVICE $TAG
rules:
- if: $CI_COMMIT_BRANCH == $PRODUCTION_BRANCH