-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
135 lines (124 loc) · 3.2 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
image: docker:stable
services:
- docker:dind
stages:
- build
- test
- create_infra
- review
- stage
- production
- clear_infra
variables:
DATABASE_URL: 'mongodb://mongo/user_posts'
CI_SHORT_COMMIT_SHA: '$${CI_COMMIT_SHA:0:8}'
DOCKER_IMAGE: '${CI_COMMIT_REF_NAME}:1.0'
build_job:
stage: build
before_script:
- cd reddit
- echo CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
- echo DOCKER_IMAGE=$DOCKER_IMAGE
- docker login -u $HUB_USER -p $HUB_PASS
script:
- docker build -t $DOCKER_IMAGE .
- docker tag $DOCKER_IMAGE $HUB_USER/$DOCKER_IMAGE
- docker push $HUB_USER/$DOCKER_IMAGE
test_unit_job:
stage: test
image:
name: $HUB_USER/$DOCKER_IMAGE
script:
- echo DOCKER_IMAGE=$DOCKER_IMAGE
- cd /reddit
- ruby simpletest.rb
test_integration_job:
stage: test
script:
- echo 'Testing 2'
create_infra_job:
stage: create_infra
image:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
- cd gitlab-ci/infra/terraform
- rm -rf .terraform
- terraform --version
- mkdir -p ./credentials
- echo $SERVICEACCOUNT | base64 -d > ./credentials/project.json
- mv terraform.tfvars.example terraform.tfvars
- echo CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
- export TF_VAR_vm_name=$CI_COMMIT_REF_NAME
- export TF_VAR_hub_docker_image=$HUB_USER/$DOCKER_IMAGE
- terraform init
- terraform destroy -auto-approve
script:
- terraform validate
- terraform plan -out "planfile"
- terraform apply -input=false "planfile"
branch_review:
stage: review
image:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
- echo VM_IP=$VM_IP
- cd gitlab-ci/infra/terraform
- mkdir -p ./credentials
- echo $SERVICEACCOUNT | base64 -d > ./credentials/project.json
- mv terraform.tfvars.example terraform.tfvars
- terraform init
- export DOCKER_IP=$(terraform output docker_external_ip)
- echo DOCKER_IP=$DOCKER_IP
script:
- echo 'Deploy'
environment:
name: branch/$CI_COMMIT_REF_NAME
url: http://$DOCKER_IP:9292
only:
- branches
except:
- master
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
clear_infra:
stage: clear_infra
image:
name: hashicorp/terraform:light
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
when: manual
before_script:
- cd gitlab-ci/infra/terraform
- mkdir -p ./credentials
- echo $SERVICEACCOUNT | base64 -d > ./credentials/project.json
- mv terraform.tfvars.example terraform.tfvars
- export TF_VAR_vm_name=$CI_COMMIT_REF_NAME
- export TF_VAR_hub_docker_image=$HUB_USER/$DOCKER_IMAGE
script:
- terraform init
- terraform destroy -auto-approve