-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
115 lines (103 loc) · 2.26 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
image: docker:19.03.1
stages:
- build
- test
- review
- stage
- production
variables:
DOCKER_TLS_CERTDIR: ''
DATABASE_URL: 'mongodb://mongo/user_posts'
DOCKER_IMAGE_NAME: $DOCKER_HUB_LOGIN/gitlab-reddit:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA
before_script:
- cd reddit
build_job:
stage: build
services:
- docker:19.03.1-dind
script:
- docker build --tag $DOCKER_IMAGE_NAME .
- docker login --username $DOCKER_HUB_LOGIN --password $DOCKER_HUB_PASSWD
- docker push $DOCKER_IMAGE_NAME
# Old unit tests implementation. Left here for OTUS CI checks.
#
# test_unit_job:
# image: ruby:2.4.2
# stage: test
# services:
# - mongo:latest
# script:
# - bundle install
# - ruby simpletest.rb
test_unit_job:
stage: test
services:
- docker:19.03.1-dind
- mongo:latest
script:
- docker run $DOCKER_IMAGE_NAME ruby simpletest.rb
test_integration_job:
stage: test
script:
- echo 'Testing 2'
deploy_dev_job:
stage: review
script:
- echo 'Deploy'
environment:
name: dev
url: http://dev.example.com
branch review:
stage: review
image: ubuntu:18.04
before_script:
- echo "Deploy to $CI_ENVIRONMENT_SLUG"
- cd gitlab-ci/environment
- ./scripts/init-terraform.sh
script:
- terraform apply -auto-approve
- echo "ENV_IP=$(terraform output | grep env_instance_ip | awk '{ print $3 }')" > deploy.env
artifacts:
reports:
dotenv: gitlab-ci/environment/deploy.env
environment:
name: branch/$CI_COMMIT_REF_NAME
url: "http://$ENV_IP:9292/"
on_stop: stop branch preview
only:
- branches
except:
- master
stop branch preview:
stage: review
image: ubuntu:18.04
before_script:
- echo "Destroy $CI_ENVIRONMENT_SLUG"
- cd gitlab-ci/environment
- ./scripts/init-terraform.sh
script:
- terraform destroy -auto-approve
when: manual
environment:
name: branch/$CI_COMMIT_REF_NAME
action: stop
staging:
stage: stage
when: manual
only:
- /^\d+\.\d+\.\d+/
script:
- echo 'Deploy'
environment:
name: stage
url: https://beta.example.com
production:
stage: production
when: manual
only:
- /^\d+\.\d+\.\d+/
script:
- echo 'Deploy'
environment:
name: production
url: https://example.com