-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
105 lines (98 loc) · 3.3 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
image: ruby:2.5.7
services:
- postgres:9.5
- docker:dind
variables:
REGISTRY_URL: registry.gitlab.com/fiuba-memo2/tp2
POSTGRES_DB: db_test
POSTGRES_USER: webapi
POSTGRES_PASSWORD: Passw0rd!
TEST_DB_URL: postgres://webapi:Passw0rd!@postgres/db_test
DB_HOST: postgres
stages:
- build
- package
- deploy_test
- acceptance_test
- deploy_prod
build_job:
stage: build
script:
- apt-get update -qq && apt-get install -y -qq postgresql postgresql-contrib libpq-dev cmake # todo check si es necesario
- gem install bundler --no-document
- bundle install --without staging production
- RACK_ENV=test bundle exec rake
- RACK_ENV=ci bundle exec rake version > VERSION.txt
artifacts:
paths:
- VERSION.txt
- reports/
package_job:
stage: package
image: docker:stable
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- VERSION=$(cat VERSION.txt)
- echo $VERSION
- docker build -f Dockerfile.prod --build-arg GIT_COMMIT=$CI_COMMIT_SHORT_SHA -t $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION .
- docker tag $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION $REGISTRY_URL/$CI_PROJECT_NAME:latest
- docker push $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION
- docker push $REGISTRY_URL/$CI_PROJECT_NAME:latest
only:
- tags
deploy_test_job:
stage: deploy_test
environment: test
image: docker:stable
before_script:
- apk add curl
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
- docker login -u _ -p $HEROKU_TOKEN registry.heroku.com
script:
- VERSION=$(cat VERSION.txt)
- docker pull $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION
- docker tag $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION registry.heroku.com/$HEROKU_APP/web
- docker push registry.heroku.com/$HEROKU_APP/web
- export IMAGE_ID=`docker inspect registry.heroku.com/$HEROKU_APP/web --format={{.Id}}`
- echo $IMAGE_ID
- ./scripts/deploy_config.sh
- ./scripts/deploy_app.sh
- ./scripts/smoke_test.sh $HEROKU_APP.herokuapp.com $VERSION
only:
- tags
acceptance_test_job:
stage: acceptance_test
environment: test
needs: ["deploy_test_job"]
script:
- apt-get update -qq && apt-get install -y -qq postgresql postgresql-contrib libpq-dev cmake # todo check si es necesario
- gem install bundler --no-document
- bundle install --without staging production
- ./scripts/acceptance_test.sh https://$HEROKU_APP.herokuapp.com
only:
- tags
artifacts:
paths:
- reports
deploy_prod_job:
stage: deploy_prod
environment: prod
image: docker:stable
before_script:
- apk add curl
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
- docker login -u _ -p $HEROKU_TOKEN registry.heroku.com
script:
- VERSION=$(cat VERSION.txt)
- docker pull $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION
- docker tag $REGISTRY_URL/$CI_PROJECT_NAME:$VERSION registry.heroku.com/$HEROKU_APP/web
- docker push registry.heroku.com/$HEROKU_APP/web
- export IMAGE_ID=`docker inspect registry.heroku.com/$HEROKU_APP/web --format={{.Id}}`
- echo $IMAGE_ID
- ./scripts/deploy_config.sh
- ./scripts/deploy_app.sh
- ./scripts/smoke_test.sh $HEROKU_APP.herokuapp.com $VERSION
only:
- tags
when: manual