forked from lpotthast/leptonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
140 lines (130 loc) · 4.1 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
stages:
- test
- package
- deploy
variables:
CARGO_HOME: "${CI_PROJECT_DIR}/cargo" # Move cargo data into the project directory so it can be cached!
RULES_CHANGES_PATH: "**/*"
RULES_ONLY: "ALL"
GIT_SUBMODULE_STRATEGY: recursive
.deploy-configuration: &deploy_configuration
image: registry.gitlab.com/lukaspotthast/docker-images/nomad-deployment:1.6.3
before_script:
- export NOMAD_ADDR=${NOMAD_ADDR}
- export NOMAD_CACERT=${NOMAD_CA_PEM}
- export NOMAD_CLIENT_CERT=${NOMAD_CLI_PEM}
- export NOMAD_CLIENT_KEY=${NOMAD_CLI_KEY_PEM}
# Required as of: https://github.com/hashicorp/nomad/issues/7529
# We otherwise get the error: x509: certificate is valid for 127.0.0.1, not [...]
- export NOMAD_TLS_SERVER_NAME="server.global.nomad"
.base-rules:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $RULES_ONLY == "ALL"
when: always
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $RULES_ONLY == $RULES_SUBJECT
when: always
- if: '$CI_PIPELINE_SOURCE == "push"'
when: never
- if: $CI_COMMIT_TAG
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- $RULES_CHANGES_PATH
- when: manual
allow_failure: true
.book:
extends: .base-rules
variables:
RULES_SUBJECT: "book"
RULES_CHANGES_PATH: "*"
.book-with-cache:
extends: .book
cache:
key:
files:
- Cargo.lock
- examples/book-ssr/Cargo.lock
paths:
- cargo/
- target/
- examples/book-ssr/target/
book-test:
stage: test
extends: .book-with-cache
image: registry.gitlab.com/lukaspotthast/docker-images/rust-wasm-builder:latest
needs: []
script:
- cd examples/book-ssr
- cargo test --target x86_64-unknown-linux-gnu
book-build-and-package:
stage: package
extends: .book
image: docker:latest
services:
- docker:dind
needs:
- book-test
artifacts:
paths:
- examples/book-ssr/deployment/leptonic-book.jobspec.final.hcl
before_script:
- echo -n "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
script:
- cd examples/book-ssr
- timestamp=$(date +%s)
- image="${CI_REGISTRY_IMAGE}/leptonic-book"
- tag="${CI_COMMIT_SHA}"
- docker pull "${image}:latest" || true
- cat "${LEPTONIC_DEV_CERT_PEM_FILE}" > "certs/ssl_cert.pem"
- cat "${LEPTONIC_DEV_KEY_PEM_FILE}" > "certs/ssl_key.pem"
- echo "Building docker image '${image}:${tag}'"
- >
docker build
--pull
--cache-from "${image}:${tag}"
--tag "${image}:${tag}"
--build-arg DEFAULT_LEPTOS_OUTPUT_NAME="leptonic-book-${timestamp}"
.
- docker tag "${image}:${tag}" "${image}:latest"
- docker push "${image}:${tag}"
- docker push "${image}:latest"
- echo "Creating final deployment spec..."
- cp deployment/leptonic-book.jobspec.hcl deployment/leptonic-book.jobspec.final.hcl
- sed -i "s/{{TAG}}/${tag}/g" "deployment/leptonic-book.jobspec.final.hcl"
- sed -i "s/{{REGISTRY_USERNAME}}/${REGISTRY_USERNAME}/g" "deployment/leptonic-book.jobspec.final.hcl"
- sed -i "s/{{REGISTRY_TOKEN}}/${REGISTRY_TOKEN}/g" "deployment/leptonic-book.jobspec.final.hcl"
book-validate-deployment:
<<: *deploy_configuration
stage: deploy
extends: .book
needs:
- book-build-and-package
script:
- cd examples/book-ssr/deployment
- nomad job validate leptonic-book.jobspec.final.hcl
book-plan-deployment:
<<: *deploy_configuration
stage: deploy
extends: .book
needs:
- book-build-and-package
- book-validate-deployment
script:
- cd examples/book-ssr/deployment
# Plan will return one of the following exit codes:
# 0: No allocations created or destroyed.
# 1: Allocations created or destroyed.
# 255: Error determining plan results.
- nomad job plan leptonic-book.jobspec.final.hcl
allow_failure:
exit_codes: 1
book-run-deployment:
<<: *deploy_configuration
stage: deploy
extends: .book
needs:
- book-build-and-package
- book-plan-deployment
script:
- cd examples/book-ssr/deployment
- nomad job run leptonic-book.jobspec.final.hcl