forked from amethyst/amethyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
187 lines (160 loc) · 6.5 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
image: rust:latest
stages:
- build-docs
- deploy-docs
- invalidate-aws
before_script:
# We need to make a copy of the script, in case we
# checkout a branch somewhere that doesn't contain it
- cp gitlab-ci-helper.sh .gitlab-ci-helper.sh
- chmod +x .gitlab-ci-helper.sh
prepare:
stage: .pre
only:
- master
script:
- cargo --version
- rustc --version
# Check if required deploy vars are set
- if [[ -z "$TAG_STABLE" ]]; then echo "TAG_STABLE must be set!"; exit 1; fi;
- if [[ -z "$BRANCH_WASM" ]]; then echo "BRANCH_WASM must be set!"; exit 1; fi;
- if [[ -z "$DOCS_SERVER" ]]; then echo "DOCS_SERVER must be set!"; exit 1; fi;
- if [[ -z "$DOCS_APP" ]]; then echo "DOCS_APP must be set!"; exit 1; fi;
- if [[ -z "$BOOK_APP" ]]; then echo "BOOK_APP must be set!"; exit 1; fi;
# For the docs and book build, we output the built sites as artifacts and cache them.
# A file containing the revision hash is output into the directory, so we can check
# if we need to rebuild and redeploy. If we detect an existing cached version, we check
# the revision and rebuild appropriately.
# Additionally, we output the paths that were rebuilt into docs-paths-updated and
# book-paths-updated, so that we can later trigger invalidations in cloudfront for
# the relevant paths.
docs:
stage: build-docs
only:
- master
cache:
key: docs-cache
paths:
- docs-public-master/
- docs-public-stable/
- docs-public-wasm/
artifacts:
paths:
- docs-public-master/
- docs-public-stable/
- docs-public-wasm/
- docs-paths-updated
script:
# Install dependencies
# We need git lfs to clone all examples
# See https://github.com/git-lfs/git-lfs/wiki/Installation
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
- apt-get install git-lfs
- git lfs install
- apt-get update && apt-get install -y libasound2-dev libcurl4-openssl-dev libdw-dev libelf-dev libexpat1-dev libfreetype6-dev libiberty-dev libsdl2-dev libssl-dev libx11-xcb-dev libxcb1-dev && apt-get clean
# Build stable, master and wasm docs
- ./.gitlab-ci-helper.sh build-docs master docs-public-master "/master/*"
- ./.gitlab-ci-helper.sh build-docs $TAG_STABLE docs-public-stable "/stable/*"
- ./.gitlab-ci-helper.sh build-docs-wasm $BRANCH_WASM docs-public-wasm "/wasm/*"
book:
image: hrektts/mdbook:latest
stage: build-docs
only:
- master
cache:
key: book-cache
paths:
- book-public-master/
- book-public-stable/
- book-public-wasm/
artifacts:
paths:
- book-public-master/
- book-public-stable/
- book-public-wasm/
- book-paths-updated
script:
# Install dependencies
- apt-get update && apt-get install git curl -y
# We need git lfs to clone all examples
# See https://github.com/git-lfs/git-lfs/wiki/Installation
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
- apt-get install git-lfs
- git lfs install
# Build stable, master and wasm book
- ./.gitlab-ci-helper.sh build-book master book-public-master "/master/*"
- ./.gitlab-ci-helper.sh build-book $TAG_STABLE book-public-stable "/stable/*"
- ./.gitlab-ci-helper.sh build-book $BRANCH_WASM book-public-wasm "/wasm/*"
deploy-docs:
image: alpine:latest
stage: deploy-docs
only:
- master
dependencies:
- docs
- book
script:
# Install dependencies
- apk update && apk add --no-cache bash git openssh ca-certificates
- echo "Adding docs deploy SSH key..."
# Add the key for dokku deployment and set permissions
# See https://docs.gitlab.com/ee/ci/ssh_keys/
- eval $(ssh-agent -s)
- echo "$DOCS_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# These are the folders we'll package and deploy as tarballs
- mkdir docs-public && mkdir book-public
# Move our static files, mark the directory as the root directory
# by creating .static and copy our custom nginx config
- mv docs-public-stable docs-public/stable
- mv docs-public-master docs-public/master
- mv docs-public-wasm docs-public/wasm
- touch docs-public/.static
- cp docs-nginx.conf.sigil docs-public/app-nginx.conf.sigil
# Check if the index file contains the package name to validate the deployment
- echo "/stable/amethyst/ amethyst" >> docs-public/CHECKS
- echo "/master/amethyst/ amethyst" >> docs-public/CHECKS
# - echo "/wasm/amethyst/ amethyst" >> docs-public/CHECKS
# Check if the revision file contains the revisions we just deployed
- echo "/master/.rev $(cat docs-public/master/.rev)" >> docs-public/CHECKS
- echo "/stable/.rev $(cat docs-public/stable/.rev)" >> docs-public/CHECKS
# - echo "/wasm/.rev $(cat docs-public/wasm/.rev)" >> docs-public/CHECKS
# Move our static files, mark the directory as the root directory
# by creating .static and copy our custom nginx config
- mv book-public-stable book-public/stable
- mv book-public-master book-public/master
- mv book-public-wasm book-public/wasm
- touch book-public/.static
- cp docs-nginx.conf.sigil book-public/app-nginx.conf.sigil
# Check if the index file contains the package name to validate the deployment
- echo "/stable/ Amethyst" >> book-public/CHECKS
- echo "/master/ Amethyst" >> book-public/CHECKS
# - echo "/wasm/ Amethyst" >> book-public/CHECKS
# Check if the revision file contains the revisions we just deployed
- echo "/master/.rev $(cat book-public/master/.rev)" >> book-public/CHECKS
- echo "/stable/.rev $(cat book-public/stable/.rev)" >> book-public/CHECKS
# - echo "/wasm/.rev $(cat book-public/wasm/.rev)" >> book-public/CHECKS
# Deploy!
- echo "Deploying docs..."
- tar c docs-public | ssh -o StrictHostKeyChecking=no dokku@${DOCS_SERVER} tar:in ${DOCS_APP}
- echo "Deploying book..."
- tar c book-public | ssh -o StrictHostKeyChecking=no dokku@${DOCS_SERVER} tar:in ${BOOK_APP}
invalidate-aws:
image: frolvlad/alpine-glibc:latest
stage: invalidate-aws
only:
- master
dependencies:
- docs
- book
- deploy-docs
script:
# Install dependencies
- apk update && apk add --no-cache bash curl ca-certificates unzip
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip -qq awscliv2.zip
- ./aws/install
- /usr/local/bin/aws --version
# Create invalidations for changed paths
- ./.gitlab-ci-helper.sh invalidate-aws