-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
128 lines (118 loc) · 4.03 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
stages:
- version
- build
- release
- push
- deploy
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_REGISTRY: docker.io
CI_REGISTRY_IMAGE: index.docker.io/derfabianpeter/www.peter.saarland
HUGO_VERSION: "0.60.1"
.deployment: &deployment |
# Setup SSH deploy keys
which ssh-agent || ( apk add --no-cache openssh-client )
eval $(ssh-agent -s)
##
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
##
echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add - > /dev/null 2>&1
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
ssh-keyscan -H ${DEPLOYMENT_TARGET} >> ~/.ssh/known_hosts
version:
stage: version
image: registry.gitlab.com/juhani/go-semrel-gitlab:v0.21.1
variables:
GSG_INITIAL_DEVELOPMENT: "false"
script:
- release test-git || true
- release test-api
- release next-version --allow-current
- release next-version --allow-current > .next-version
- echo "RELEASE_URL=https://gitlab.com/derfabianpeter/www.peter.saarland/-/releases/v$(<.next-version)" > build_info
- echo "RELEASE_DESC=\"Fabian Peter | DevOps Consultant\"" >> build_info
- echo "RELEASE_SHA=$CI_COMMIT_SHA" >> build_info
- echo "RELEASE_VERSION=$(<.next-version)" >> build_info
artifacts:
paths:
- build_info
- .next-version
except:
- tags
Build:
stage: build
image: docker:19.03.5-git
services:
- docker:19.03.5-dind
# fetching submodules here because usually themes are git submodules
before_script:
- echo -n $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USER --password-stdin $DOCKER_REGISTRY
- wget -O hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz
- tar -zxvf hugo.tar.gz
- ./hugo
- ./hugo version
#- apk add curl
#- ls -lah */*
#- "curl --request POST --url https://gotenberg.devops-projects.de/convert/html --header 'Content-Type: multipart/form-data' --form files=@public/about/index.html -o public/cv.pdf"
script:
- . build_info
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') -t $CI_REGISTRY_IMAGE:v$RELEASE_VERSION .
- docker push $CI_REGISTRY_IMAGE:v$RELEASE_VERSION
artifacts:
paths:
- public
# Release new Version
Release:
stage: release
image: registry.gitlab.com/juhani/go-semrel-gitlab:v0.21.1
variables:
GSG_INITIAL_DEVELOPMENT: "false"
script:
- rm -f release_info
- mv build_info release_info
- . release_info
- release changelog
- release commit-and-tag CHANGELOG.md release_info
- release --ci-commit-tag v$RELEASE_VERSION add-download-link -n release -u $RELEASE_URL -d "$RELEASE_DESC"
only:
- master
artifacts:
paths:
- release_info
Push Dockerhub:
stage: push
image: docker:19.03.5-git
services:
- docker:19.03.5-dind
variables:
GIT_STRATEGY: none
before_script:
- echo -n $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_USER --password-stdin $DOCKER_REGISTRY
script:
- . release_info
- docker pull $CI_REGISTRY_IMAGE:v$RELEASE_VERSION || true
- docker tag $CI_REGISTRY_IMAGE:v$RELEASE_VERSION $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
only:
- master
Deploy:
stage: deploy
image: tiangolo/docker-with-compose
script:
- *deployment
- DOCKER_HOST=ssh://${DEPLOYMENT_TARGET} docker-compose -f ci/docker-compose.yml rm -f
- DOCKER_HOST=ssh://${DEPLOYMENT_TARGET} docker-compose -f ci/docker-compose.yml pull
- DOCKER_HOST=ssh://${DEPLOYMENT_TARGET} docker-compose -f ci/docker-compose.yml -p peter-www up --remove-orphans -d
allow_failure: false
only:
- master
environment:
name: production
url: https://www.peter.saarland