-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
62 lines (54 loc) · 1.46 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
image: so0k/docker-ansible:1.12.3-alpine
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
IMMUTABLE_TAG: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
MUTABLE_TAG: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- echo $CI_PROJECT_DIR
stages:
- build
- release
- deploy
- grading
build:
stage: build
script:
- docker build -t $IMMUTABLE_TAG .
- docker push $IMMUTABLE_TAG
release-image:
stage: release
script:
- docker pull $IMMUTABLE_TAG
- docker tag $IMMUTABLE_TAG $MUTABLE_TAG
- docker push $MUTABLE_TAG
only:
- master
ansible-deploy:
stage: deploy
script:
# Add the SSH key from SSH_PRIVATE_KEY variable
- mkdir -p ~/.ssh && chmod 700 ~/.ssh
- echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
# disable strict host checking - beware MitM! :(
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- ssh -i ~/.ssh/id_rsa ubuntu@$DEPLOY_TARGET sudo docker version
# add $DEPLOY_TARGET to ansible inventory
- echo -e
"${DEPLOY_TARGET}\tansible_connection=ssh\tansible_user=ubuntu" > inventory
- ansible-playbook -vv
--key-file ~/.ssh/id_rsa
--inventory-file inventory
-e "USER=gitlab-ci-token"
-e "PASSWORD=$CI_BUILD_TOKEN"
-e "REGISTRY=$CI_REGISTRY"
playbooks/deploy-compose.yaml
only:
- master
scoreme:
stage: grading
script:
- ./scripts/grademe.sh