Browse Source

Update workflows

pull/503/head
Paul Robert Lloyd 3 years ago
parent
commit
5feb225505
  1. 125
      .github/workflows/production_pipeline.yml
  2. 114
      .github/workflows/staging_pipeline.yml

125
.github/workflows/production_pipeline.yml

@ -1,4 +1,4 @@
name: 'Production CI/CD Pipeline' name: Production CI/CD Pipeline
on: on:
release: release:
@ -26,8 +26,8 @@ jobs:
POSTGRES_DB: data_collector POSTGRES_DB: data_collector
ports: ports:
- 5432:5432 - 5432:5432
# needed because the postgres container does not provide a healthcheck # Needed because the Postgres container does not provide a health check
# tmpfs makes DB faster by using RAM # tmpfs makes database faster by using RAM
options: >- options: >-
--mount type=tmpfs,destination=/var/lib/postgresql/data --mount type=tmpfs,destination=/var/lib/postgresql/data
--health-cmd pg_isready --health-cmd pg_isready
@ -47,25 +47,28 @@ jobs:
id: latestrelease id: latestrelease
run: | run: |
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" 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 - name: Confirm release tag
run: | run: |
echo ${{ steps.latestrelease.outputs.releasetag }} echo ${{ steps.latestrelease.outputs.releasetag }}
- name: Checkout tag - name: Checkout tag
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
ref: ${{ steps.latestrelease.outputs.releasetag }} ref: ${{ steps.latestrelease.outputs.releasetag }}
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true bundler-cache: true
- name: Set up node - name: Set up node
uses: actions/setup-node@v2 uses: actions/setup-node@v3
with: with:
node-version: '16' cache: yarn
node-version: 16
- name: Create DB - name: Create database
run: | run: |
bundle exec rake db:prepare bundle exec rake db:prepare
@ -80,23 +83,25 @@ jobs:
lint: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Get latest release with tag - name: Get latest release with tag
id: latestrelease id: latestrelease
run: | run: |
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" 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 - name: Confirm release tag
run: | run: |
echo ${{ steps.latestrelease.outputs.releasetag }} echo ${{ steps.latestrelease.outputs.releasetag }}
- name: Checkout tag - name: Checkout tag
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
ref: ${{ steps.latestrelease.outputs.releasetag }} ref: ${{ steps.latestrelease.outputs.releasetag }}
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true bundler-cache: true
- name: Rubocop - name: Rubocop
@ -106,23 +111,25 @@ jobs:
audit: audit:
name: Audit dependencies name: Audit dependencies
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Get latest release with tag - name: Get latest release with tag
id: latestrelease id: latestrelease
run: | run: |
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" 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 - name: Confirm release tag
run: | run: |
echo ${{ steps.latestrelease.outputs.releasetag }} echo ${{ steps.latestrelease.outputs.releasetag }}
- name: Checkout tag - name: Checkout tag
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
ref: ${{ steps.latestrelease.outputs.releasetag }} ref: ${{ steps.latestrelease.outputs.releasetag }}
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true bundler-cache: true
- name: Audit - name: Audit
@ -131,53 +138,55 @@ jobs:
deploy: deploy:
name: Deploy name: Deploy
concurrency: 'production' concurrency: "production"
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: 'production' environment: "production"
needs: [lint, test, audit] needs: [lint, test, audit]
steps: steps:
- name: Get latest release with tag - name: Get latest release with tag
id: latestrelease id: latestrelease
run: | run: |
echo "::set-output name=releasetag::$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" 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: | - name: Confirm release tag
echo ${{ steps.latestrelease.outputs.releasetag }} run: |
- name: Checkout tag echo ${{ steps.latestrelease.outputs.releasetag }}
uses: actions/checkout@v2
with: - name: Checkout tag
ref: ${{ steps.latestrelease.outputs.releasetag }} uses: actions/checkout@v3
with:
- name: Install Cloud Foundry CLI ref: ${{ steps.latestrelease.outputs.releasetag }}
run: |
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - - name: Install Cloud Foundry CLI
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list run: |
sudo apt-get update wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
sudo apt-get install cf8-cli echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
- name: Deploy sudo apt-get update
env: sudo apt-get install cf8-cli
CF_USERNAME: ${{ secrets.CF_USERNAME }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD }} - name: Deploy
CF_API_ENDPOINT: ${{ secrets.CF_API_ENDPOINT }} env:
CF_SPACE: ${{ secrets.CF_SPACE }} CF_USERNAME: ${{ secrets.CF_USERNAME }}
CF_ORG: ${{ secrets.CF_ORG }} CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
APP_NAME: dluhc-core-production CF_API_ENDPOINT: ${{ secrets.CF_API_ENDPOINT }}
GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }} CF_SPACE: ${{ secrets.CF_SPACE }}
APP_HOST: ${{ secrets.APP_HOST }} CF_ORG: ${{ secrets.CF_ORG }}
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} APP_NAME: dluhc-core-production
IMPORT_PAAS_INSTANCE: ${{ secrets.IMPORT_PAAS_INSTANCE }} GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }}
EXPORT_PAAS_INSTANCE: ${{ secrets.EXPORT_PAAS_INSTANCE }} APP_HOST: ${{ secrets.APP_HOST }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }} RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
run: | IMPORT_PAAS_INSTANCE: ${{ secrets.IMPORT_PAAS_INSTANCE }}
cf api $CF_API_ENDPOINT EXPORT_PAAS_INSTANCE: ${{ secrets.EXPORT_PAAS_INSTANCE }}
cf auth SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
cf target -o $CF_ORG -s $CF_SPACE run: |
cf set-env $APP_NAME GOVUK_NOTIFY_API_KEY $GOVUK_NOTIFY_API_KEY cf api $CF_API_ENDPOINT
cf set-env $APP_NAME APP_HOST $APP_HOST cf auth
cf set-env $APP_NAME RAILS_MASTER_KEY $RAILS_MASTER_KEY cf target -o $CF_ORG -s $CF_SPACE
cf set-env $APP_NAME IMPORT_PAAS_INSTANCE $IMPORT_PAAS_INSTANCE cf set-env $APP_NAME GOVUK_NOTIFY_API_KEY $GOVUK_NOTIFY_API_KEY
cf set-env $APP_NAME EXPORT_PAAS_INSTANCE $EXPORT_PAAS_INSTANCE cf set-env $APP_NAME APP_HOST $APP_HOST
cf set-env $APP_NAME SENTRY_DSN $SENTRY_DSN cf set-env $APP_NAME RAILS_MASTER_KEY $RAILS_MASTER_KEY
cf push $APP_NAME --strategy rolling 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 SENTRY_DSN $SENTRY_DSN
cf push $APP_NAME --strategy rolling

114
.github/workflows/staging_pipeline.yml

@ -1,9 +1,9 @@
name: 'Staging CI/CD Pipeline' name: Staging CI/CD Pipeline
on: on:
push: push:
branches: branches:
- main - main
pull_request: pull_request:
workflow_dispatch: workflow_dispatch:
@ -25,14 +25,15 @@ jobs:
POSTGRES_DB: data_collector POSTGRES_DB: data_collector
ports: ports:
- 5432:5432 - 5432:5432
# needed because the postgres container does not provide a healthcheck # Needed because the Postgres container does not provide a health check
# tmpfs makes DB faster by using RAM # tmpfs makes database faster by using RAM
options: >- options: >-
--mount type=tmpfs,destination=/var/lib/postgresql/data --mount type=tmpfs,destination=/var/lib/postgresql/data
--health-cmd pg_isready --health-cmd pg_isready
--health-interval 10s --health-interval 10s
--health-timeout 5s --health-timeout 5s
--health-retries 5 --health-retries 5
env: env:
RAILS_ENV: test RAILS_ENV: test
GEMFILE_RUBY_VERSION: 3.1.1 GEMFILE_RUBY_VERSION: 3.1.1
@ -43,23 +44,24 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true bundler-cache: true
- name: Set up node
uses: actions/setup-node@v2 - name: Set up Node.js
uses: actions/setup-node@v3
with: with:
node-version: '16' cache: yarn
node-version: 16
- name: Create DB - name: Create database
run: | run: |
bundle exec rake db:prepare bundle exec rake db:prepare
- name: Compile Assets - name: Compile assets
run: | run: |
bundle exec rake assets:precompile bundle exec rake assets:precompile
@ -70,14 +72,14 @@ jobs:
lint: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true bundler-cache: true
- name: Rubocop - name: Rubocop
@ -87,14 +89,14 @@ jobs:
audit: audit:
name: Audit dependencies name: Audit dependencies
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Set up Ruby - name: Set up Ruby
uses: ruby/setup-ruby@v1 uses: ruby/setup-ruby@v1
with: with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true bundler-cache: true
- name: Audit - name: Audit
@ -103,49 +105,49 @@ jobs:
deploy: deploy:
name: Deploy name: Deploy
concurrency: 'staging' concurrency: staging
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: 'staging' environment: staging
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
needs: [lint, test, audit] needs: [lint, test, audit]
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Install Cloud Foundry CLI - name: Install Cloud Foundry CLI
run: | run: |
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list 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 update
sudo apt-get install cf8-cli sudo apt-get install cf8-cli
- name: Deploy
env: - name: Deploy
CF_USERNAME: ${{ secrets.CF_USERNAME }} env:
CF_PASSWORD: ${{ secrets.CF_PASSWORD }} CF_USERNAME: ${{ secrets.CF_USERNAME }}
CF_API_ENDPOINT: ${{ secrets.CF_API_ENDPOINT }} CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
CF_SPACE: ${{ secrets.CF_SPACE }} CF_API_ENDPOINT: ${{ secrets.CF_API_ENDPOINT }}
CF_ORG: ${{ secrets.CF_ORG }} CF_SPACE: ${{ secrets.CF_SPACE }}
API_USER: ${{ secrets.API_USER }} CF_ORG: ${{ secrets.CF_ORG }}
API_KEY: ${{ secrets.API_KEY }} API_USER: ${{ secrets.API_USER }}
APP_NAME: dluhc-core-staging API_KEY: ${{ secrets.API_KEY }}
GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }} APP_NAME: dluhc-core-staging
APP_HOST: ${{ secrets.APP_HOST }} GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }}
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} APP_HOST: ${{ secrets.APP_HOST }}
IMPORT_PAAS_INSTANCE: ${{ secrets.IMPORT_PAAS_INSTANCE }} RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
EXPORT_PAAS_INSTANCE: ${{ secrets.EXPORT_PAAS_INSTANCE }} IMPORT_PAAS_INSTANCE: ${{ secrets.IMPORT_PAAS_INSTANCE }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }} EXPORT_PAAS_INSTANCE: ${{ secrets.EXPORT_PAAS_INSTANCE }}
run: | SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
cf api $CF_API_ENDPOINT run: |
cf auth cf api $CF_API_ENDPOINT
cf target -o $CF_ORG -s $CF_SPACE cf auth
cf set-env $APP_NAME API_USER $API_USER cf target -o $CF_ORG -s $CF_SPACE
cf set-env $APP_NAME API_KEY $API_KEY cf set-env $APP_NAME API_USER $API_USER
cf set-env $APP_NAME GOVUK_NOTIFY_API_KEY $GOVUK_NOTIFY_API_KEY cf set-env $APP_NAME API_KEY $API_KEY
cf set-env $APP_NAME APP_HOST $APP_HOST cf set-env $APP_NAME GOVUK_NOTIFY_API_KEY $GOVUK_NOTIFY_API_KEY
cf set-env $APP_NAME RAILS_MASTER_KEY $RAILS_MASTER_KEY cf set-env $APP_NAME APP_HOST $APP_HOST
cf set-env $APP_NAME IMPORT_PAAS_INSTANCE $IMPORT_PAAS_INSTANCE cf set-env $APP_NAME RAILS_MASTER_KEY $RAILS_MASTER_KEY
cf set-env $APP_NAME EXPORT_PAAS_INSTANCE $EXPORT_PAAS_INSTANCE cf set-env $APP_NAME IMPORT_PAAS_INSTANCE $IMPORT_PAAS_INSTANCE
cf set-env $APP_NAME SENTRY_DSN $SENTRY_DSN cf set-env $APP_NAME EXPORT_PAAS_INSTANCE $EXPORT_PAAS_INSTANCE
cf push $APP_NAME --strategy rolling cf set-env $APP_NAME SENTRY_DSN $SENTRY_DSN
cf push $APP_NAME --strategy rolling

Loading…
Cancel
Save