Browse Source

CLDC-3123 Speed up deployment pipeline (#2355)

* feat: remove unnecessary steps from prod pipeline, check they passed on staging in the prod aws deploy step instead

* feat: test condition

* Revert "feat: test condition"

This reverts commit 4146b2664b.
pull/2383/head v0.4.33
natdeanlewissoftwire 8 months ago committed by GitHub
parent
commit
64001541a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      .github/workflows/aws_deploy.yml
  2. 200
      .github/workflows/production_pipeline.yml

6
.github/workflows/aws_deploy.yml

@ -59,13 +59,17 @@ jobs:
run: | run: |
echo "image-exists=$(if aws ecr list-images --repository-name=$repository --query "imageIds[*].imageTag" | grep -q ${{ github.sha }}; then echo true; else echo false; fi)" >> $GITHUB_ENV echo "image-exists=$(if aws ecr list-images --repository-name=$repository --query "imageIds[*].imageTag" | grep -q ${{ github.sha }}; then echo true; else echo false; fi)" >> $GITHUB_ENV
- name: Build, tag, and push docker image to ECR - name: Build, tag, and push docker image to ECR if there is no image, failing for releases
id: build-image id: build-image
if: ${{ env.image-exists == 'false' }} if: ${{ env.image-exists == 'false' }}
env: env:
registry: ${{ steps.ecr-login.outputs.registry }} registry: ${{ steps.ecr-login.outputs.registry }}
commit_tag: ${{ github.sha }} commit_tag: ${{ github.sha }}
run: | run: |
if [[ ${{ inputs.environment }} == 'production' ]]; then
echo "Error: Deployment to production environment is not allowed as there is no docker image (i.e. the AWS deploy on staging was unsuccessful for this commit)."
exit 1
fi
docker build -t $registry/$repository:$commit_tag . --target=production docker build -t $registry/$repository:$commit_tag . --target=production
docker push $registry/$repository:$commit_tag docker push $registry/$repository:$commit_tag

200
.github/workflows/production_pipeline.yml

@ -5,213 +5,13 @@ on:
types: [released] types: [released]
workflow_dispatch: workflow_dispatch:
env:
REPO_URL: communitiesuk/submit-social-housing-lettings-and-sales-data
defaults: defaults:
run: run:
shell: bash shell: bash
jobs: jobs:
test:
name: Test
runs-on: ubuntu-latest
outputs:
releasetag: ${{ steps.latestrelease.outputs.releasetag }}
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 "releasetag=$(curl -s https://api.github.com/repos/${REPO_URL}/releases/latest | jq '.tag_name' | sed 's/\"//g')" >> $GITHUB_OUTPUT
- 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: 20
- 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: 20
- 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: Set up Node.js
uses: actions/setup-node@v3
with:
cache: yarn
node-version: 20
- name: Install packages and symlink local dependencies
run: |
yarn install --immutable --immutable-cache --check-cache
- name: Lint
run: |
bundle exec rake lint
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
aws_deploy: aws_deploy:
name: AWS Deploy name: AWS Deploy
needs: [lint, test, feature_test, audit]
uses: ./.github/workflows/aws_deploy.yml uses: ./.github/workflows/aws_deploy.yml
with: with:
aws_account_id: 977287343304 aws_account_id: 977287343304

Loading…
Cancel
Save