Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .docker/Dockerfile.seed
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ghcr.io/dpc-sdp/bay/mariadb:6.x
ARG BASE_IMAGE=ghcr.io/dpc-sdp/bay/mariadb:6.x
FROM $BASE_IMAGE

ARG DATA_DIR=/tmp/data

Expand All @@ -7,8 +8,7 @@ COPY $DATA_DIR /var/lib/mysql
USER root

RUN chown -R mysql /var/lib/mysql \
&& chgrp -R mysql /var/lib/mysql \
&& /bin/fix-permissions /var/lib/mysql
&& chgrp -R mysql /var/lib/mysql

USER mysql
ENV MARIADB_INIT_WAIT_SECONDS=80
Expand Down
110 changes: 107 additions & 3 deletions .github/workflows/run_db_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,120 @@ jobs:
annotations: ${{ steps.meta.outputs.annotations }}
push: true

export-db-mysql:
runs-on: ${{ inputs.runner }}
permissions:
contents: read
packages: write
id-token: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/mysql
TMP_DATA_DIR: data
DB_FILE: db.sql
steps:
- name: Start the database container
id: container
run: |
CONTAINER_ID=$(docker run -d -e "MYSQL_ROOT_PASSWORD=${{ secrets.DB_IMAGE_MARIADB_ROOT_PASSWORD }}" ghcr.io/dpc-sdp/bay/mysql:6.x)
sleep 30
echo "id=$CONTAINER_ID" >> $GITHUB_OUTPUT

- name: Configure AWS actions
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-2

- name: Download the database
run: aws s3 cp ${{ inputs.s3_uri }} "${{ env.DB_FILE }}"

- name: Import the database into the running container
run: |
echo 'create database if not exists drupal;' | docker exec -i "${{ steps.container.outputs.id }}" /usr/bin/mysql -u root -p${{ secrets.DB_IMAGE_MARIADB_ROOT_PASSWORD }}
cat "${{ env.DB_FILE }}" | docker exec -i "${{ steps.container.outputs.id }}" /usr/bin/mysql -u root -p${{ secrets.DB_IMAGE_MARIADB_ROOT_PASSWORD }} drupal

- name: Verify database is available
run: |
if docker exec -i "${{ steps.container.outputs.id }}" /usr/bin/mysql -u root -p${{ secrets.DB_IMAGE_MARIADB_ROOT_PASSWORD }} -e "show tables;" drupal | grep -q users; then
echo "Database import successfully"
else
echo "Database was not imported successfully"
exit 1
fi

- name: Gracefully shutdown the intermediary container
run: docker exec -i "${{ steps.container.outputs.id }}" mysqladmin -u root -p${{ secrets.DB_IMAGE_MARIADB_ROOT_PASSWORD }} shutdown
continue-on-error: true

- name: Copy database files out of the intermediary container
run: |
mkdir -p "${{ env.TMP_DATA_DIR }}"
docker cp "${{ steps.container.outputs.id }}":/var/lib/mysql/. "${{ env.TMP_DATA_DIR }}/"
ls -la "${{ env.TMP_DATA_DIR }}"

- name: Verify the data directory
run: |
if [ -d "${{ env.TMP_DATA_DIR }}/mysql" ]; then
echo "Files exist on the host"
else
ls -la "${{ env.TMP_DATA_DIR }}"
exit 1
fi

- name: Download the DB image dockerfile
run: curl -o Dockerfile.seed https://raw.githubusercontent.com/dpc-sdp/github-actions/feature/mysql-db-image/.docker/Dockerfile.seed

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ghcr.io
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch


- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push the database image
uses: docker/build-push-action@v5
with:
file: Dockerfile.seed
context: .
build-args: |
DATA_DIR=${{ env.TMP_DATA_DIR }}
BASE_IMAGE=ghcr.io/dpc-sdp/bay/mysql:6.x
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
push: true

notify_slack:
runs-on: ubuntu-latest
needs: [export-db]
needs: [export-db, export-db-mysql]
if: ${{ always() }}
steps:
- name: Send Notification to Slack on Failure
if: ${{ needs.export-db.result == 'failure' }}
if: ${{ needs.export-db.result == 'failure' || needs.export-db-mysql.result == 'failure' }}
uses: 8398a7/action-slack@v3
with:
status: ${{ needs.export-db.result }}
status: failure
text: 'Attention: The db-trigger workflow has FAILED in project "${{ inputs.project }}" for repo "${{ github.repository }}"!'
fields: 'project: ${{ inputs.project }}, repo: ${{ github.repository }}'
mention: 'here'
Expand Down