-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
.gitlab-ci.yml
88 lines (72 loc) · 2.27 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
image: registry.gitlab.com/openbeta/openbeta-nodejs-docker:16.3
variables:
GIT_DEPTH: 1
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
IMAGE_LATEST: $CI_REGISTRY_IMAGE:latest
IMAGE_CURRENT: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
docker-build-staging:
stage: build
only: # Only run for these branches
- staging
tags:
- docker
image: docker:20.10.10
services:
- docker:20.10.10-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $IMAGE_STAGING || true
- docker build --cache-from $IMAGE_STAGING --tag $IMAGE_CURRENT --tag $IMAGE_STAGING .
- docker push $IMAGE_CURRENT
- docker push $IMAGE_STAGING
docker-build:
stage: build
only: # Only run for these branches
- develop
- main
tags:
- docker
image: docker:20.10.10
services:
- docker:20.10.10-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $IMAGE_LATEST || true
- docker build --cache-from $IMAGE_LATEST --tag $IMAGE_CURRENT --tag $IMAGE_LATEST .
- docker push $IMAGE_CURRENT
- docker push $IMAGE_LATEST
deploy:
stage: deploy
tags:
- docker
only: # Only run for these branches
- develop
- main
needs:
- job: docker-build
artifacts: true
image:
name: bitnami/git:latest
before_script:
- mkdir -p ~/.bin
- curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- ~/.bin
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- git clone --quiet --depth 1 --branch main [email protected]:openbeta/devops/graphql-api.git
- cd graphql-api
- ~/.bin/kustomize edit set image $IMAGE_CURRENT
- git diff
- if [[ ! -n $(git status --porcelain) ]]; then echo "No new changes. Skipping deployment."; exit 0; fi
- git config --global user.name $GITLAB_USER_NAME
- git config --global user.email $GITLAB_USER_EMAIL
- git commit -am "Update deployment. Code=${CI_COMMIT_SHORT_SHA}"
- git push