You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
260 lines
13 KiB
260 lines
13 KiB
name: Production CI/CD Pipeline |
|
|
|
on: |
|
release: |
|
types: [released] |
|
workflow_dispatch: |
|
|
|
env: |
|
REPO_URL: communitiesuk/submit-social-housing-lettings-and-sales-data |
|
CLOUDFOUNDRY_KEY_BASE64: LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUlOQkZ1YXFiMEJFQURQSGlOeUFGNFhuZUNOTGN1c210dzNTTHlLaGhNbTgzNm9WOVBhSk4xUkE2emFxbFlqCmFDZUYyVDhCcmd2a2MwSXNxTzdCUVBQZW53M0RnZWZKNG1NR2tCTHRhODJwcGNDYkRCaFo2bXpRV3V2bmZhRGgKZ3JmdE5obVoyY09PSkdkNE5TdVdUYWQ0bkZiL1lESkJuVTB0UXc4cW5jYlVrd3RQbGZ5MkRjaXd3SHpNZFJGYwpWSnlWVjY5S2orWDVTUWhlZDBQSFdOTG1yVVRHOGw3MVpUMVhPTWZmekFURHFRN2JaTFlobExCOVFWVEx0UUJFCm9nU1pndXVZNXhHZStDZnE2SWJPaHVtMjFpTkxnKzJ0RGxldkdrV0RCWFFDU29kZFlyY2ZOM0t2R0NOZW5vclMKNEQ0VHp5M1Ric0p4eWcxM1YwYWc1c1lWYnBCZ3hzeFVsSXJLcE1uWjNHUDEvclRyVXY5MWxmbFIrWlpqanNqYwpnS2VnNHEwUWh3M291L2xlL2lkSERkNXlxZ3NidjIwZXc3dkxyelZucEdZanZHMHk4bEZ1MlFQRDl6alRvKzVMCnFWS0RCL0JZWi9zOUxybzhGZ1dleFlxTkZXSHhBUVk1Y28vbVlldkFIM3VHNzVDNTRXV2t3RWgyRjlYRHNMbEIKRWFYeXdDMGs2Q09rb3RHdit1V29HWWtUeUF2eWYydkE0TGFRMURVZWJHT3dyTEJpYnVmbjRVdTRQWHYxVThuRwpaV0JxazRyNFhtbEVvZU5nMDZaSWNLQ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E14dWd4VjBNb1orR0oxaTBvVEdyCnc2Z3FjVCsyMWhoSzlUY1ZsdnQ5UkNZejlCZG5YQjFSRzd2TWdpdEY2LzhEUTVRY29SOEcrb0xsZ1A0RUVmWDUKUTJSWGJyMGVrNkNvTERYRnhYM0xwV0xRTXpRZjdXZThtenlyZGlUd2dMTnAxUT09Cj1YeDdkCi0tLS0tRU5EIFBHUCBQVUJMSUMgS0VZIEJMT0NLLS0tLS0K |
|
|
|
defaults: |
|
run: |
|
shell: bash |
|
|
|
jobs: |
|
test: |
|
name: Test |
|
runs-on: ubuntu-latest |
|
|
|
services: |
|
postgres: |
|
image: postgres:13.5 |
|
env: |
|
POSTGRES_PASSWORD: password |
|
POSTGRES_USER: postgres |
|
POSTGRES_DB: data_collector |
|
ports: |
|
- 5432:5432 |
|
# Needed because the Postgres container does not provide a health check |
|
# tmpfs makes database faster by using RAM |
|
options: >- |
|
--mount type=tmpfs,destination=/var/lib/postgresql/data |
|
--health-cmd pg_isready |
|
--health-interval 10s |
|
--health-timeout 5s |
|
--health-retries 5 |
|
env: |
|
RAILS_ENV: test |
|
GEMFILE_RUBY_VERSION: 3.1.1 |
|
DB_HOST: localhost |
|
DB_DATABASE: data_collector |
|
DB_USERNAME: postgres |
|
DB_PASSWORD: password |
|
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} |
|
PARALLEL_TEST_PROCESSORS: 4 |
|
|
|
steps: |
|
- name: Get latest release with tag |
|
id: latestrelease |
|
run: | |
|
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" |
|
|
|
- name: Confirm release tag |
|
run: | |
|
echo ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Checkout tag |
|
uses: actions/checkout@v3 |
|
with: |
|
ref: ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Set up Ruby |
|
uses: ruby/setup-ruby@v1 |
|
with: |
|
bundler-cache: true |
|
|
|
- name: Set up node |
|
uses: actions/setup-node@v3 |
|
with: |
|
cache: yarn |
|
node-version: 16 |
|
|
|
- name: Create database |
|
run: | |
|
bundle exec rake parallel:setup |
|
|
|
- name: Compile Assets |
|
run: | |
|
bundle exec rake assets:precompile |
|
|
|
- name: Run tests |
|
run: | |
|
bundle exec rake parallel:spec['spec\/(?!features)'] |
|
|
|
feature_test: |
|
name: Feature Tests |
|
if: '!github.event.pull_request.draft' |
|
runs-on: ubuntu-latest |
|
|
|
services: |
|
postgres: |
|
image: postgres:13.5 |
|
env: |
|
POSTGRES_PASSWORD: password |
|
POSTGRES_USER: postgres |
|
POSTGRES_DB: data_collector |
|
ports: |
|
- 5432:5432 |
|
# Needed because the Postgres container does not provide a health check |
|
# tmpfs makes database faster by using RAM |
|
options: >- |
|
--mount type=tmpfs,destination=/var/lib/postgresql/data |
|
--health-cmd pg_isready |
|
--health-interval 10s |
|
--health-timeout 5s |
|
--health-retries 5 |
|
|
|
env: |
|
RAILS_ENV: test |
|
GEMFILE_RUBY_VERSION: 3.1.1 |
|
DB_HOST: localhost |
|
DB_DATABASE: data_collector |
|
DB_USERNAME: postgres |
|
DB_PASSWORD: password |
|
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} |
|
|
|
steps: |
|
- name: Checkout |
|
uses: actions/checkout@v3 |
|
|
|
- name: Set up Ruby |
|
uses: ruby/setup-ruby@v1 |
|
with: |
|
bundler-cache: true |
|
|
|
- name: Set up Node.js |
|
uses: actions/setup-node@v3 |
|
with: |
|
cache: yarn |
|
node-version: 16 |
|
|
|
- name: Create database |
|
run: | |
|
bundle exec rake db:prepare |
|
|
|
- name: Compile assets |
|
run: | |
|
bundle exec rake assets:precompile |
|
|
|
- name: Run tests |
|
run: | |
|
bundle exec rspec spec/features --fail-fast |
|
|
|
lint: |
|
name: Lint |
|
runs-on: ubuntu-latest |
|
|
|
steps: |
|
- name: Get latest release with tag |
|
id: latestrelease |
|
run: | |
|
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" |
|
|
|
- name: Confirm release tag |
|
run: | |
|
echo ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Checkout tag |
|
uses: actions/checkout@v3 |
|
with: |
|
ref: ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Set up Ruby |
|
uses: ruby/setup-ruby@v1 |
|
with: |
|
bundler-cache: true |
|
|
|
- name: Rubocop |
|
run: | |
|
bundle exec rubocop |
|
|
|
audit: |
|
name: Audit dependencies |
|
runs-on: ubuntu-latest |
|
|
|
steps: |
|
- name: Get latest release with tag |
|
id: latestrelease |
|
run: | |
|
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" |
|
|
|
- name: Confirm release tag |
|
run: | |
|
echo ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Checkout tag |
|
uses: actions/checkout@v3 |
|
with: |
|
ref: ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Set up Ruby |
|
uses: ruby/setup-ruby@v1 |
|
with: |
|
bundler-cache: true |
|
|
|
- name: Audit |
|
run: | |
|
bundle exec bundler-audit |
|
|
|
deploy: |
|
name: Deploy |
|
concurrency: "production" |
|
runs-on: ubuntu-latest |
|
environment: "production" |
|
needs: [lint, test, feature_test, audit] |
|
|
|
steps: |
|
- name: Get latest release with tag |
|
id: latestrelease |
|
run: | |
|
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" |
|
|
|
- name: Confirm release tag |
|
run: | |
|
echo ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Checkout tag |
|
uses: actions/checkout@v3 |
|
with: |
|
ref: ${{ steps.latestrelease.outputs.releasetag }} |
|
|
|
- name: Install Cloud Foundry CLI |
|
run: | |
|
echo $CLOUDFOUNDRY_KEY_BASE64 | base64 -d | sudo apt-key add - |
|
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list |
|
sudo apt-get update |
|
sudo apt-get install cf8-cli |
|
|
|
- name: Deploy |
|
env: |
|
CF_USERNAME: ${{ secrets.CF_USERNAME }} |
|
CF_PASSWORD: ${{ secrets.CF_PASSWORD }} |
|
CF_API_ENDPOINT: ${{ secrets.CF_API_ENDPOINT }} |
|
CF_SPACE: ${{ secrets.CF_SPACE }} |
|
CF_ORG: ${{ secrets.CF_ORG }} |
|
APP_NAME: dluhc-core-production |
|
GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }} |
|
APP_HOST: ${{ secrets.APP_HOST }} |
|
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} |
|
OS_DATA_KEY: ${{ secrets.OS_DATA_KEY }} |
|
IMPORT_PAAS_INSTANCE: ${{ secrets.IMPORT_PAAS_INSTANCE }} |
|
EXPORT_PAAS_INSTANCE: ${{ secrets.EXPORT_PAAS_INSTANCE }} |
|
S3_CONFIG: ${{ secrets.S3_CONFIG }} |
|
CSV_DOWNLOAD_PAAS_INSTANCE: ${{ secrets.CSV_DOWNLOAD_PAAS_INSTANCE }} |
|
SENTRY_DSN: ${{ secrets.SENTRY_DSN }} |
|
run: | |
|
cf api $CF_API_ENDPOINT |
|
cf auth |
|
cf target -o $CF_ORG -s $CF_SPACE |
|
cf set-env $APP_NAME GOVUK_NOTIFY_API_KEY $GOVUK_NOTIFY_API_KEY |
|
cf set-env $APP_NAME APP_HOST $APP_HOST |
|
cf set-env $APP_NAME RAILS_MASTER_KEY $RAILS_MASTER_KEY |
|
cf set-env $APP_NAME OS_DATA_KEY $OS_DATA_KEY |
|
cf set-env $APP_NAME IMPORT_PAAS_INSTANCE $IMPORT_PAAS_INSTANCE |
|
cf set-env $APP_NAME EXPORT_PAAS_INSTANCE $EXPORT_PAAS_INSTANCE |
|
cf set-env $APP_NAME S3_CONFIG $S3_CONFIG |
|
cf set-env $APP_NAME CSV_DOWNLOAD_PAAS_INSTANCE $CSV_DOWNLOAD_PAAS_INSTANCE |
|
cf set-env $APP_NAME SENTRY_DSN $SENTRY_DSN |
|
cf push $APP_NAME --strategy rolling
|
|
|