Skip to content

Build and push database image for next #57

Build and push database image for next

Build and push database image for next #57

name: Build and push database image
run-name: Build and push database image for ${{ github.ref_name }}
on:
workflow_dispatch:
push:
branches: [next]
workflow_call:
inputs:
github_ref:
description: The git commit sha to build the image from.
type: string
permissions:
id-token: write
contents: read
jobs:
build-and-push-database-image:
name: Build and push database image
runs-on: ubuntu-latest
env:
RAILS_ENV: development
DATABASE_HOST: localhost
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
BUNDLE_WITHOUT: test
RAILS_MASTER_KEY: intentionally-insecure-dev-key00
SKIP_TEST_DATABASE: true
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ inputs.github_ref || github.ref_name == 'next' && 'next' || github.ref_name }}
repository: nhsdigital/manage-vaccinations-in-schools
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .tool-versions
cache: yarn
- name: Create Dockerfile
run: >-
echo -e \
"FROM postgis/postgis:17-master\nENV PGDATA=\"/var/lib/postgresql/mydata\"" \
> database.Dockerfile
- name: Build image
run: docker build -t database:latest -f database.Dockerfile .
- name: Start container
run: |
docker run -d \
--name database \
-e "POSTGRES_HOST_AUTH_METHOD=trust" \
-p 5432:5432 \
database:latest
- name: Wait for database to be ready
run: |
docker exec database bash -c '
until pg_isready -U postgres; do
echo "Waiting for postgres..."
sleep 2
done'
- uses: ruby/setup-ruby@0cb964fd540e0a24c900370abf38a33466142735 # v1.305.0
with:
bundler-cache: true
- name: Set up database for testing
run: |
bin/rails db:setup
bin/rails feature_flags:enable_for_development
bin/mavis gias import --input-file=spec/fixtures/dfe-schools.zip
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0
with:
role-to-assume: arn:aws:iam::393416225559:role/GitHubAssuranceTestRole
aws-region: eu-west-2
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@376925c9d111252e87ae59691e5a442dd100ef6a # v2.1.3
# yamllint disable rule:line-length
- name: Get image tag
id: get-image-tag
run: |
git_ref=$(git rev-parse ${{ inputs.github_ref || github.ref_name == 'next' && 'origin/next' || github.ref_name }})
echo "value=$git_ref" >> "$GITHUB_OUTPUT"
- name: Commit image
run: >-
docker commit database "${{ steps.login-ecr.outputs.registry
}}/mavis/development/postgres_db:${{ steps.get-image-tag.outputs.value }}"
- name: Push image
run: >-
docker push "${{ steps.login-ecr.outputs.registry }}/mavis/development/postgres_db:${{
steps.get-image-tag.outputs.value }}"
# yamllint enable rule:line-length