forked from InseeFrLab/utilitR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
121 lines (108 loc) · 3.18 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
variables:
GITLAB_BASE_IMAGE: rocker/geospatial:latest
ONYXIA_BASE_IMAGE: git-registry.stable.innovation.insee.eu/innovation/rstudio
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
BUILD_IMAGE: $CI_REGISTRY_IMAGE:master
stages:
- install
- build
- deploy
build_image:
stage: install
image: gitlab/dind
services:
- docker:dind
only:
- master
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# Check where the project is hosted to define the base image
- if [[ $CI_SERVER_HOST == "gitlab.com" ]]; then export BASE_IMAGE=$GITLAB_BASE_IMAGE; else export BASE_IMAGE=$ONYXIA_BASE_IMAGE; fi
- docker build --build-arg BASE_IMAGE=$BASE_IMAGE -t $BUILD_IMAGE .
- docker push $BUILD_IMAGE
bookdown:
stage: build
image: $BUILD_IMAGE
script:
- Rscript -e "remotes::install_deps(dependencies = TRUE, upgrade = FALSE)"
- Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all', output_dir = '_public')"
artifacts:
paths:
- _public
expire_in: 1 week
pages:
stage: deploy
image: alpine:3
script:
- mv _public public
artifacts:
paths:
- public
expire_in: 1 week
only:
- master
pagedown:
stage: build
image: $BUILD_IMAGE
script:
- Rscript -e "install.packages('pagedown')"
# artifacts:
# paths:
# - _public
# expire_in: 1 week
netlify-master:
stage: deploy
image: node:latest
script:
- npm install
- npm install netlify-cli -g
- netlify deploy --prod --dir _public --site "$NETLIFY_SITE_ID_MASTER" --auth "$NETLIFY_AUTH_TOKEN_MASTER"
only:
- master
netlify:
stage: deploy
image: node:latest
script:
- npm install
- npm install netlify-cli -g
- netlify deploy --alias ${CI_COMMIT_REF_NAME} --dir _public --site "$NETLIFY_SITE_ID" --auth "$NETLIFY_AUTH_TOKEN"
except:
- master
- binder
# The purpose of this job is to invalidate the Binder cache
# by pushing a new commit to the `binder` branch
binder:
stage: deploy
only:
refs:
- master
variables:
- $CI_SERVER_HOST == "gitlab.com"
environment:
name: Binder
url: https://mybinder.org/v2/gl/linogaliana%2FdocumentationR/binder?urlpath=rstudio
image:
name: alpine/git:v2.24.1
entrypoint: [""]
dependencies: []
script:
# configure ssh
- eval $(ssh-agent -s)
# DEPLOY_PRIVATE_KEY is a base64 encoded ssh private key for deployment
# the corresponding public key is stored as a deploy key with write access
- echo "$DEPLOY_PRIVATE_KEY" | base64 -d | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan "$CI_SERVER_HOST" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# configure git
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$GITLAB_USER_NAME"
- git remote set-url origin "git@${CI_SERVER_HOST}:${CI_PROJECT_PATH}.git"
# push a new commit to the binder branch to invalidate Binder cache
- git fetch origin binder
- git checkout origin/binder
- git checkout -b binder
- git commit --allow-empty -m "Update for ${CI_PIPELINE_URL} [skip ci]"
- git push origin binder