-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
131 lines (104 loc) · 3.23 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
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- open-tacos/node_modules/
- open-tacos/.cache
- public
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
# Job name must be 'pages' in order for GitLab to deploy build to static site
gatsby-build:
only: # Only run for these branches
- develop
- main
- merge_requests
- gitlab-debug
stage: build
tags:
- docker
before_script:
- mkdir -p open-tacos
- mv content open-tacos
# we need to move build output dir back down 1 level for GitLab pages to work
- '[ -d public ] && mv public open-tacos'
- cd open-tacos && ls -la
- git init . && git remote add origin https://github.com/OpenBeta/open-tacos
- git pull --depth $GIT_DEPTH origin develop
- git checkout develop
- git show --summary
# Record SHA of code
- echo "CODE_SHA=$(git rev-parse --short HEAD)" >> ../build.env
- if [ "$FORCE_CLEAN" == "true" ]; then rm -rf node_modules; fi;
- yarn install --no-progress
- if [ "$FORCE_CLEAN" == "true" ]; then ./node_modules/.bin/gatsby clean; fi;
script:
- ./node_modules/.bin/gatsby build
- mv public $CI_PROJECT_DIR
artifacts:
reports:
dotenv: build.env
docker-build:
only: # Only run for these branches
- develop
- main
- gitlab-debug
stage: build
tags:
- docker
needs:
- job: gatsby-build
artifacts: true
image: docker:20.10.10
services:
- docker:20.10.10-dind
variables:
# Form image tag with most recent code SHA and content SHA
IMAGE_CURRENT: $CI_REGISTRY_IMAGE:${CODE_SHA}-$CI_COMMIT_SHORT_SHA
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- echo "IMAGE_CURRENT=$IMAGE_CURRENT" >> build.env
- echo "CODE_SHA=$CODE_SHA" >> build.env
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
artifacts:
reports:
dotenv: build.env
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 [email protected]:openbeta/devops/opentacos-k8s.git
- cd opentacos-k8s
- ~/.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=${CODE_SHA}, Content=${CI_COMMIT_SHORT_SHA}"
- git push