diff --git a/.docker/01-marina.cnf b/.docker/01-marina.cnf new file mode 100644 index 00000000..743d013f --- /dev/null +++ b/.docker/01-marina.cnf @@ -0,0 +1,4 @@ +# Marina specific cli settings +[mysql] +# Increase verbosity of CLI tool +verbose diff --git a/.docker/Dockerfile.seed b/.docker/Dockerfile.seed index 381d99f3..10f7a1ac 100644 --- a/.docker/Dockerfile.seed +++ b/.docker/Dockerfile.seed @@ -1,11 +1,16 @@ FROM ghcr.io/dpc-sdp/bay/mariadb:6.x ARG DATA_DIR=/tmp/data +ARG DB_FILE=db.sql COPY $DATA_DIR /var/lib/mysql +COPY $DB_FILE /var/tmp/db.sql +COPY 01-marina.cnf /etc/mysql/conf.d/ USER root +RUN fix-permissions /etc/mysql/conf.d/ + RUN chown -R mysql /var/lib/mysql \ && chgrp -R mysql /var/lib/mysql \ && /bin/fix-permissions /var/lib/mysql diff --git a/.github/workflows/run_db_trigger.yml b/.github/workflows/run_db_trigger.yml index c6086b4f..a8aba9ce 100644 --- a/.github/workflows/run_db_trigger.yml +++ b/.github/workflows/run_db_trigger.yml @@ -23,6 +23,21 @@ on: type: string required: false default: ubuntu-latest + aws-region: + description: 'AWS region' + required: false + type: string + default: ap-southeast-4 + ecr-registry: + description: 'ECR registry' + required: false + type: string + default: 734101502693.dkr.ecr.ap-southeast-4.amazonaws.com + ecr-push-role-arn: + description: 'ECR push role ARN' + required: false + type: string + default: arn:aws:iam::734101502693:role/GithubEcrPushRole secrets: AWS_ACCESS_KEY_ID: @@ -49,7 +64,6 @@ jobs: packages: write id-token: write env: - REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }}/mariadb TMP_DATA_DIR: data DB_FILE: db.sql @@ -107,40 +121,68 @@ jobs: fi - name: Download the DB image dockerfile - run: curl -o Dockerfile.seed https://raw.githubusercontent.com/dpc-sdp/github-actions/main/.docker/Dockerfile.seed + run: curl -o Dockerfile.seed https://raw.githubusercontent.com/dpc-sdp/github-actions/refs/heads/feat/PENG-1779--push-to-ecr/.docker/Dockerfile.seed + + - name: Download Marina config file + run: curl -o 01-marina.cnf https://raw.githubusercontent.com/dpc-sdp/github-actions/refs/heads/feat/PENG-1779--push-to-ecr/.docker/01-marina.cnf # 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 }} + registry: ghcr.io username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_TOKEN }} + - name: Configure AWS credentials for registry push + uses: aws-actions/configure-aws-credentials@v6 + with: + role-to-assume: ${{ inputs.ecr-push-role-arn }} + aws-region: ${{ inputs.aws-region }} + + - name: Login to Amazon ECR + uses: aws-actions/amazon-ecr-login@v2 + # 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 - + images: | + ghcr.io/${{ env.IMAGE_NAME }} + ${{ inputs.ecr-registry }}/marina-platform/databases/${{ github.event.repository.name }}/mariadb + flavor: | + latest=true - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Validate DB file is present in build context + run: | + if [ ! -s "${{ env.DB_FILE }}" ]; then + echo "Expected database file '${{ env.DB_FILE }}' is missing or empty in build context." + echo "Current directory: $(pwd)" + echo "Directory contents:" + ls -la + exit 1 + fi + + echo "Found '${{ env.DB_FILE }}' in build context." + ls -lh "${{ env.DB_FILE }}" + - 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 }} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + build-args: | + DATA_DIR=${{ env.TMP_DATA_DIR }} + DB_FILE=${{ env.DB_FILE }} + tags: ${{ steps.meta.outputs.tags }} platforms: linux/amd64,linux/arm64 labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }}