-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (98 loc) · 3.55 KB
/
deploy.yaml
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
---
# This workflow will run unit tests and deploy the application to a
# target environment
name: Deploy
on:
push:
branches:
- main
tags:
- '*'
paths-ignore:
- '**.md' # All markdown files in the repository
jobs:
unit-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with Django unit tests
env:
# For unit tests, secret_key just needs to be populated.
# It will only ever access a temporary Django test database.
SECRET_KEY: unit-test-fake-secret-key-#5TY90
run: python manage.py test --debug-mode
deploy:
if: github.repository_owner == '18F'
needs: unit-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install CloudFoundry CLI
run: |
curl -L "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=v7&source=github" | sudo tar -zx --directory=/usr/local/bin
cf --version
- name: Setup CF CLI auth
run: |
cf api https://api.fr.cloud.gov
cf auth ${{ secrets.CF_USERNAME }} ${{ secrets.CF_PASSWORD }}
- name: Determine deployment target
id: deployment-target
env:
GITHUB_REF: ${{ github.ref }}
run: |
# Use the Github reference to determine environment values
if [[ $GITHUB_REF == "refs/heads/main" ]]; then
# Pushes to main are deployed to dev
target_environment=give-dev
service_route=identity-give-idemia-dev.apps.internal
transaction_route=identity-give-transaction-log-dev.apps.internal
elif [[ $GITHUB_REF =~ refs/tags/* ]]; then
# Tags on main are deployed to test
target_environment=give-test
service_route=identity-give-idemia-test.apps.internal
transaction_route=identity-give-transaction-log-test.apps.internal
else
echo 'Unknown deployment target'
exit 1
fi
# Set the outputs for this step
echo "::set-output name=SPACE::$target_environment"
echo "::set-output name=ROUTE::$service_route"
echo "::set-output name=TRANSACTION_ROUTE::$transaction_route"
echo "Deploying to $target_environment"
- name: Set CF CLI Target
run: cf target -o ${{ secrets.CF_ORG }} -s ${{ steps.deployment-target.outputs.SPACE }}
- name: Ensure DB Available
run: .cloud-gov/ensure_db_available.sh idemia-db
- name: Deploy application
run: cf push --vars-file vars.yaml
--var SECRET_KEY=${{ secrets.SECRET_KEY }}
--var ROUTE=${{ steps.deployment-target.outputs.ROUTE }}
--var TRANSACTION_ROUTE=${{ steps.deployment-target.outputs.TRANSACTION_ROUTE }}
--strategy rolling