-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
80 lines (76 loc) · 2.73 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
stages:
- ci_image
- updatedata
- build
docker build:
stage: ci_image
image: nixos/nix:latest
resource_group: registry
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "web"'
when: never
- changes:
- nix/*
# - .gitlab-ci.yml
script:
# For pinning:
# - export NIX_PATH="nixpkgs=https://github.com/NixOS/nixpkgs/archive/ab593d46dc38b9f0f23964120912138c77fa9af4.tar.gz"
- nix-channel --update
- nix-build -o image.tar.gz ./nix/docker_container.nix
- |
nix-shell -p skopeo --command 'skopeo \
--insecure-policy \
copy \
--dest-creds $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD \
docker-archive:image.tar.gz \
docker://$CI_REGISTRY_IMAGE/c2-website-builder:latest'
update data:
stage: updatedata
image: "$CI_REGISTRY_IMAGE/c2-website-builder:latest"
resource_group: repo
before_script:
- git config user.email "ci@campus-cneipe.de"
- git config user.name "C2 CI"
- git remote remove ssh_origin || true # Local repo state may be cached
- git remote add ssh_origin "https://c2:$CI_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
script:
- ./scripts/update_menu.py > data/menu_data.json
- echo $TOKEN_JSON > token.json
- ./scripts/update_calendar.py
- |
set -eux
if [ -n "$(git status --porcelain data/menu_data.json data/event_data.json src/lib/assets/images/events/)" ]; then
git add data/menu_data.json data/event_data.json src/lib/assets/images/events/
git commit -m "Update data from APIs"
git push ssh_origin HEAD:master
sleep 5
echo "Cancelling this pipeline, new one will be triggered by push"
curl --request POST --header "PRIVATE-TOKEN: ${CI_API_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/cancel"
fi
deploy website:
stage: build
image: "$CI_REGISTRY_IMAGE/c2-website-builder:latest"
resource_group: build
artifacts:
paths:
- c2-website.tar.gz
- scripts/menu.pdf
expire_in: 3 days
cache:
key:
files:
- package-lock.json
paths:
- .npm/
before_script:
- npm ci --cache .npm --prefer-offline
script:
- scripts/pdfmenu.sh
- if [ "$CI_COMMIT_REF_NAME" = "master" ]; then export DEPLOY_PREFIX=""; else export DEPLOY_PREFIX="/staging/${CI_COMMIT_REF_SLUG}"; fi
- export BASE="${DEPLOY_PREFIX}"
- npm run build
- tar -czf c2-website.tar.gz build/
- echo -e "\n${HTACCESS_SECRETS}\n" >> build/.htaccess
- rsync -zrl --delete --exclude={staging/,typo3temp_lrz_old/} --mkpath -e "sshpass -p $DEPLOY_PW ssh -o StrictHostKeyChecking=no -l $DEPLOY_USER" build/ "${DEPLOY_HOST}:~/webserver/htdocs${DEPLOY_PREFIX}/"