-
Notifications
You must be signed in to change notification settings - Fork 36
/
.gitlab-ci.yml
106 lines (96 loc) · 2.68 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
variables:
REGISTRY: d.nyodev.xyz
SERVICE: api
IMAGE: ripple/$SERVICE
SOURCE_BRANCH: master
PRODUCTION_BRANCH: production
GIT_SUBMODULE_STRATEGY: recursive
default:
before_script:
- TAG=$(grep "const version" doc.go | cut -d'"' -f 2 | cut -c 2- | tr -d '\n')
stages:
- test
- build-docker
- release
- deploy
.go-cache:
image: golang:1.20.4-bullseye
variables:
GOPATH: $CI_PROJECT_DIR/.go/path
GOCACHE: $CI_PROJECT_DIR/.go/cache
CGO_ENABLED: 0
before_script:
- mkdir -p .go/path .go/cache
cache:
paths:
- .go/path/pkg/mod/
- .go/cache
test:
stage: test
extends: .go-cache
script:
- go mod download -x
- go test -cover ./...
rules:
- if: $CI_COMMIT_BRANCH != $PRODUCTION_BRANCH
build-docker:
stage: build-docker
needs: ["test"]
image: docker:20
services:
- docker:20-dind
variables:
DOCKERFILE: rippleapi.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