-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
75 lines (69 loc) · 2.33 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
stages:
- test
- build
- deploy
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
REGISTRY_HOST: localhost:5000
TAG_LATEST: $REGISTRY_HOST/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:latest
TAG_DRAFT: $REGISTRY_HOST/$CI_PROJECT_NAME-draft/$CI_COMMIT_REF_NAME:latest
cache:
paths:
- .cache/pip
# This job tests if the book compiles gracefully after a new addition
test-build:
stage: test
image: python:3.11-bullseye
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- pip install -r requirements.txt
- jupyter-book clean book/
- jupyter-book build book/
# This job builds the Docker container
build-book:
stage: build
image: docker
rules:
- if: $CI_COMMIT_BRANCH == "publish" && $CI_PIPELINE_SOURCE == "push"
variables:
TAG: $TAG_LATEST
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
variables:
TAG: $TAG_DRAFT
before_script:
- docker info
script:
- if [ "$TAG" = "$TAG_LATEST" ]; then sed --in-place=".bak" '/# START DRAFT/,/# END DRAFT/{//!d}' book/_config.yml; fi
- docker build -t $TAG .
- docker push $TAG
# This job takes down the existing container and starts the new one
deploy-book:
stage: deploy
image: docker
rules:
- if: $CI_COMMIT_BRANCH == "publish" && $CI_PIPELINE_SOURCE == "push"
before_script:
- docker info
- docker stop $CI_PROJECT_NAME || exit_code=$?
- if [ $exit_code -ne 0 ]; then echo "Container not found, cannot stop"; else docker rm $CI_PROJECT_NAME; fi
script:
- docker run -d --restart always -p 8005:8000 --name $CI_PROJECT_NAME $TAG_LATEST # Make sure to use a different port for each book!
environment:
name: production
url: https://interactivetextbooks.citg.tudelft.nl/$CI_PROJECT_NAME
# Deploy the draft version of the book
deploy-draft:
stage: deploy
image: docker
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
before_script:
- docker info
- docker stop $CI_PROJECT_NAME-draft || exit_code=$?
- if [ $exit_code -ne 0 ]; then echo "Container not found, cannot stop"; else docker rm $CI_PROJECT_NAME-draft; fi
script:
- docker run -d --restart always -p 8006:8000 --name $CI_PROJECT_NAME-draft $TAG_DRAFT
environment:
name: draft
url: https://interactivetextbooks.citg.tudelft.nl/$CI_PROJECT_NAME-draft