-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
67 lines (61 loc) · 2.17 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
stages:
- build
- test
- release
- deploy
variables:
DJANGO_TEST_IMAGE: $CI_REGISTRY_IMAGE:DJANGO_$CI_COMMIT_REF_SLUG
DJANGO_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:DJANGO_latest
django-build:
stage: build
image: docker:stable
services:
- docker:stable-dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build --pull -t $DJANGO_TEST_IMAGE . -f docker/django/Dockerfile
- docker push $DJANGO_TEST_IMAGE
django-test:
stage: test
image: docker:stable
services:
- docker:stable-dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker pull $DJANGO_TEST_IMAGE
- printenv | grep '^DJANGO_' > env.list
- docker run --env-file env.list $DJANGO_TEST_IMAGE ./manage.py test
django-release-image:
stage: release
image: docker:stable
services:
- docker:stable-dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker pull $DJANGO_TEST_IMAGE
- docker tag $DJANGO_TEST_IMAGE $DJANGO_RELEASE_IMAGE
- docker push $DJANGO_RELEASE_IMAGE
only:
- master
deploy:
stage: deploy
image: gitlab/dind:latest
services:
- docker:stable-dind
before_script:
- which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
- ssh ${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER_IP} "docker-compose -f ${PROJECT_PATH}/docker-compose.prod.yml stop"
- ssh ${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER_IP} "bash -c 'cd ${PROJECT_PATH} && git fetch && git checkout ${CI_COMMIT_SHA:0:8}'"
- ssh ${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER_IP} "docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} && docker pull ${DJANGO_RELEASE_IMAGE}"
- ssh ${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER_IP} "docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} && docker-compose -f ${PROJECT_PATH}/docker-compose.prod.yml up -d"
only:
- master