generated from DFE-Digital/govuk-rails-boilerplate
180 lines (159 loc) · 6.43 KB
/
review.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Create Review App
on:
pull_request:
branches: [ develop ]
types: [ opened, synchronize, reopened ]
paths-ignore:
- 'documentation/**'
jobs:
deploy:
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-20.04
steps:
- uses: softprops/turnstyle@v1
name: Check workflow concurrency
with:
poll-interval-seconds: 20
same-branch-only: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: setup-inputs
run: |
echo "ENVIRONMENT=review-pr-${{ github.event.number }}" >> $GITHUB_ENV
- uses: actions/checkout@v3
name: Checkout Code
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Pin Terraform version
uses: hashicorp/setup-terraform@v1.4.0
with:
terraform_version: 0.14.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_DEV_PASSWORD }}
- name: Build and push docker image from builder target
uses: docker/build-push-action@v2
with:
context: .
build-args: BUILDKIT_INLINE_CACHE=1
cache-from: |
dfedigital/early-careers-framework-dev:builder
push: true
tags: dfedigital/early-careers-framework-dev:builder
target: builder
provenance: false
- name: Build and push docker image from early-careers-framework-gems-node-modules target
uses: docker/build-push-action@v2
with:
context: .
build-args: BUILDKIT_INLINE_CACHE=1
cache-from: |
dfedigital/early-careers-framework-dev:gems-node-modules
push: true
tags: dfedigital/early-careers-framework-dev:gems-node-modules
target: early-careers-framework-gems-node-modules
- name: Build and push docker image from assets-precompile target
uses: docker/build-push-action@v2
with:
context: .
build-args: BUILDKIT_INLINE_CACHE=1
cache-from: |
dfedigital/early-careers-framework-dev:assets-precompile
push: true
tags: dfedigital/early-careers-framework-dev:assets-precompile
target: assets-precompile
- name: Build and push docker image from production target
uses: docker/build-push-action@v2
with:
context: .
build-args: |
BUILDKIT_INLINE_CACHE=1
SHA=${{ github.event.pull_request.head.sha }}
cache-from: |
dfedigital/early-careers-framework-dev:${{ env.ENVIRONMENT }}
dfedigital/early-careers-framework-dev:latest
push: true
tags: |
dfedigital/early-careers-framework-dev:${{ github.event.pull_request.head.sha }}
dfedigital/early-careers-framework-dev:${{ env.ENVIRONMENT }}
dfedigital/early-careers-framework-dev:latest
target: production
- name: Deploy review app to dev
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_paas_user: ${{ secrets.GOVPAAS_DEV_USERNAME }}
TF_VAR_paas_password: ${{ secrets.GOVPAAS_DEV_PASSWORD }}
TF_VAR_statuscake_api_token: ${{ secrets.STATUSCAKE_API_TOKEN }}
run: |
export TF_VAR_paas_app_docker_image=dfedigital/early-careers-framework-dev:${{ github.event.pull_request.head.sha }}
cd terraform/app
terraform init -reconfigure -input=false -backend-config="bucket=paas-s3-broker-prod-lon-7f2ca242-9929-4662-a79c-c454ea56ea7b" -backend-config="key=${{ env.ENVIRONMENT }}/terraform.tfstate"
terraform apply -input=false -auto-approve -var-file ../workspace-variables/review.tfvars -var='secret_paas_app_env_values={"RAILS_MASTER_KEY":"${{secrets.RAILS_MASTER_KEY_DEV}}"}' -var='environment=${{env.ENVIRONMENT}}' -var 'docker_username=${{ secrets.DOCKER_USERNAME }}' -var 'docker_password=${{ secrets.DOCKER_DEV_PASSWORD }}'
- name: comment on PR
uses: unsplash/comment-on-pr@v1.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: "Created review app at https://ecf-review-pr-${{ github.event.number }}.london.cloudapps.digital"
check_for_duplicate_msg: true
duplicate_msg_pattern: Created review app at*
smoke-test:
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-20.04
needs: [deploy]
# Our rspec is deeply coupled with a database. I had a go at decoupling it for smoke tests, and gave up.
# This database is provided as a hacky way to get rspec to run, and should not be populated in smoke tests.
env:
RAILS_ENV: test
DB_USERNAME: postgres
DB_PASSWORD: ''
DB_HOSTNAME: 127.0.0.1
DB_PORT: 5432
ANALYTICS_DB_USERNAME: postgres
ANALYTICS_DB_PASSWORD: ''
ANALYTICS_DB_HOSTNAME: 127.0.0.1
ANALYTICS_DB_PORT: 5432
services:
postgres:
image: postgres:11.6-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ''
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: setup-inputs
run: |
echo "ENVIRONMENT=review-pr-${{ github.event.number }}" >> $GITHUB_ENV
- name: Set up Ruby
uses: ruby/setup-ruby@v1.133.2
with:
bundler-cache: true
ruby-version: '3.1.2'
- name: Set up Node
uses: actions/setup-node@v2.5.1
with:
node-version: '16.17.x'
cache: 'yarn'
- name: Set up test database
run: bin/rails db:create db:schema:load
- name: Run deployment smoke test
run: bundle exec rspec spec/smoke_tests/*_spec.rb --tag smoke_test
- name: comment on PR
uses: unsplash/comment-on-pr@v1.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: "Smoke tests passed against the review app."
check_for_duplicate_msg: true
duplicate_msg_pattern: Smoke tests passed against the review app*