-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path.gitlab-ci.yml
57 lines (51 loc) · 2.06 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
# Server currently not online. If we want to re-enable this, we would need to move to
# centralized CI repository https://gitlab.msu.edu/msu-libraries/ci-cd/ci-cd
# and create an encoded ssh key as documented there and commented in the ENCODED_PRIVATE_KEY below
# then this file would be deleted.
image: docker:latest
stages:
- build
- deploy
variables:
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
REPO_PATH: "/home/deploy/DomainAccessibilityAudit"
SERVER: "da11y.lib.msu.edu"
ENCODED_PRIVATE_KEY: $KEY_11369_PROD # does not exist
build:
stage: build
tags:
- msul-shared
only:
- master
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --pull -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
deploy:
stage: deploy
extends: .setup_ssh
environment:
name: prod
url: "https://$SERVER"
only:
- master
when: manual
script:
- apk add curl
- ssh deploy@$SERVER git -C $REPO_PATH reset HEAD --hard
- ssh deploy@$SERVER git -C $REPO_PATH fetch gitlab
- ssh deploy@$SERVER git -C $REPO_PATH checkout $CI_COMMIT_SHORT_SHA
- ssh deploy@$SERVER "sed -i 's|^\( *\)accessibility_audit:$|&\n\1 image:\ registry.gitlab.msu.edu\/msu-libraries\/devops\/domainaccessibilityaudit:$CI_COMMIT_SHORT_SHA|' $REPO_PATH/docker-compose.yml"
- ssh deploy@$SERVER docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- ssh deploy@$SERVER "(cd $REPO_PATH && docker-compose -f $REPO_PATH/docker-compose.yml config)"
- ssh deploy@$SERVER "(cd $REPO_PATH && docker-compose -f $REPO_PATH/docker-compose.yml pull)"
- ssh deploy@$SERVER sudo /bin/systemctl restart daa
- sleep 30
- ssh deploy@$SERVER sudo /bin/systemctl status daa
- ssh deploy@$SERVER docker container prune -f
- ssh deploy@$SERVER docker image prune -f -a
- ssh deploy@$SERVER "[[ $( curl -s -o /dev/null -k -I -w \"%{http_code}\" $CI_ENVIRONMENT_URL ) -eq 200 ]]"
include:
- project: 'msu-libraries/public/cicd-templates'
ref: main
file: 'SSH.gitlab-ci.yml'