forked from gigalixir/gigalixir-getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
97 lines (91 loc) · 3.13 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
image: ubuntu:16.04
stages:
- deploy
deploy_review:
stage: deploy
script:
- echo "Deploy a review app"
- apt-get update
- apt-get install -y python-pip git
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e $GIGALIXIR_EMAIL -y -p $GIGALIXIR_PASSWORD
- APP_NAME="$GIGALIXIR_APP_NAME-$CI_ENVIRONMENT_SLUG"
- echo "Creating gigalixir app $APP_NAME"
- gigalixir create --name $APP_NAME || gigalixir set_git_remote $APP_NAME
- echo "Creating database"
- if [ "$(gigalixir databases $APP_NAME)" = "[]" ]; then gigalixir create_database $APP_NAME; fi
- echo "Pushing"
- git push -f gigalixir HEAD:refs/heads/master
- echo "Databases may take some time to create. You can check the status by running gigalixir databases $APP_NAME"
- echo "To run migrations automatically, see http://gigalixir.readthedocs.io/en/latest/main.html#how-to-set-up-continuous-integration-ci-cd"
- echo "Don't forget to set config variables here if needed by running gigalixir set_config $APP_NAME KEY VALUE"
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$GIGALIXIR_APP_NAME-$CI_ENVIRONMENT_SLUG.gigalixirapp.com
on_stop: stop_review
only:
- branches
except:
- master
deploy_staging:
stage: deploy
script:
- echo "Deploy to staging server"
- apt-get update
- apt-get install -y python-pip git
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e $GIGALIXIR_EMAIL -y -p $GIGALIXIR_PASSWORD
- echo "Setting git remote"
- gigalixir set_git_remote $GIGALIXIR_APP_NAME-staging
- echo "Pushing"
- git push -f gigalixir HEAD:refs/heads/master
environment:
name: staging
url: https://$GIGALIXIR_APP_NAME-staging.gigalixirapp.com
only:
- master
deploy_prod:
stage: deploy
script:
- echo "Deploy to production server"
- apt-get update
- apt-get install -y python-pip git
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e $GIGALIXIR_EMAIL -y -p $GIGALIXIR_PASSWORD
- echo "Setting git remote"
- gigalixir set_git_remote $GIGALIXIR_APP_NAME
- echo "Pushing"
- git push -f gigalixir HEAD:refs/heads/master
environment:
name: production
url: https://$GIGALIXIR_APP_NAME.gigalixirapp.com
when: manual
only:
- master
stop_review:
stage: deploy
variables:
GIT_STRATEGY: none
script:
- apt-get update
- apt-get install -y python-pip jq
- pip install gigalixir
- echo "Logging into gigalixir"
- gigalixir login -e $GIGALIXIR_EMAIL -y -p $GIGALIXIR_PASSWORD
- APP_NAME="$GIGALIXIR_APP_NAME-$CI_ENVIRONMENT_SLUG"
- echo "Scaling app $APP_NAME to 0 replicas"
- gigalixir scale --replicas=0 $APP_NAME
- echo "Looking for databases"
- DATABASE_IDS=$(gigalixir databases $APP_NAME | jq -r '.[] | select(.state == "AVAILABLE") | .id')
- for db in $DATABASE_IDS; do echo "Deleting database ${DATABASE_IDS}"; echo 'y' | gigalixir delete_database $APP_NAME $db; done
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
only:
- branches
except:
- master