This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
74 lines (62 loc) · 2.01 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
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# ssh
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
variables:
PROJECT_KEY: ch-openbroadcast
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
DOKKU_IMAGE_TAG: dokku/$PROJECT_KEY:$CI_COMMIT_REF_NAME
stages:
- build
- deploy
- deploy-sites
- post-deploy
build:
stage: build
only:
- branches
script:
- echo "IMAGE_TAG:" $IMAGE_TAG
- echo "PROJECT_KEY:" $PROJECT_KEY
- echo "DOKKU_IMAGE_TAG:" $DOKKU_IMAGE_TAG
- echo "DOKKU_HOST:" $DOKKU_HOST
- echo "CI_DEPLOY_USER:" $CI_DEPLOY_USER
- echo "CI_DEPLOY_PASSWORD:" $CI_DEPLOY_PASSWORD
# build and add image for internal registry
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
deploy-image:
stage: deploy
only:
- master
script:
- echo "CI_DEPLOY_USER:" $CI_DEPLOY_USER
- echo "CI_DEPLOY_PASSWORD:" $CI_DEPLOY_PASSWORD
- echo "CI_REGISTRY:" $CI_REGISTRY
- echo "IMAGE_TAG:" $IMAGE_TAG
- echo "PROJECT_KEY:" $PROJECT_KEY
- echo "CI_COMMIT_REF_NAME:" $CI_COMMIT_REF_NAME
- echo "DOKKU_HOST:" $DOKKU_HOST
# pull image on dokku host
- ssh root@$DOKKU_HOST "docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY"
- ssh root@$DOKKU_HOST "docker pull $IMAGE_TAG"
- ssh root@$DOKKU_HOST "docker tag $IMAGE_TAG $DOKKU_IMAGE_TAG"
deploy-sites:
stage: deploy-sites
only:
- master
script:
# openbroadcast.ch
- ssh root@$DOKKU_HOST "docker tag dokku/ch-openbroadcast:master dokku/ch-openbroadcast:master"
- ssh root@$DOKKU_HOST "dokku tags:deploy ch-openbroadcast master"
post-deploy:
stage: post-deploy
only:
- master
script:
- ssh root@$DOKKU_HOST "dokku cleanup --global"