213 lines
6.2 KiB
YAML
213 lines
6.2 KiB
YAML
# GITHUB ACTIONS - WORKFLOW
|
|
|
|
# Build the database dev docker image with the latest database dump every night
|
|
# so that developers don't have to manually build it themselves.
|
|
|
|
# DB dump becomes available at around 0700 UTC, so schedule is set to 0800 UTC
|
|
# to account for variations.
|
|
|
|
name: Nightly Dev DB Image
|
|
|
|
# Controls when the workflow will run
|
|
on:
|
|
# Run every night
|
|
schedule:
|
|
- cron: '0 8 * * *'
|
|
|
|
# Run on db.Dockerfile changes
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'docker/db.Dockerfile'
|
|
|
|
# Allows you to run this workflow manually from the Actions tab
|
|
workflow_dispatch:
|
|
inputs:
|
|
skipMariaDBBuild:
|
|
description: 'Skip MariaDB Build'
|
|
default: false
|
|
required: true
|
|
type: boolean
|
|
exportDumpAsSQL:
|
|
description: 'Save PostgreSQL Debug Dump'
|
|
default: false
|
|
required: true
|
|
type: boolean
|
|
|
|
jobs:
|
|
build-mariadb:
|
|
name: Build MariaDB Docker Images
|
|
runs-on: ubuntu-latest
|
|
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'schedule' || github.event.inputs.skipMariaDBBuild == 'false') }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- platform: "linux/arm64"
|
|
docker: "arm64"
|
|
- platform: "linux/amd64"
|
|
docker: "x64"
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Docker Build & Push
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: docker/db.Dockerfile
|
|
platforms: ${{ matrix.platform }}
|
|
push: true
|
|
tags: ghcr.io/ietf-tools/datatracker-db:latest-${{ matrix.docker }}
|
|
provenance: false
|
|
|
|
combine-mariadb:
|
|
name: Create MariaDB Docker Manifests
|
|
runs-on: ubuntu-latest
|
|
needs: [build-mariadb]
|
|
permissions:
|
|
packages: write
|
|
steps:
|
|
- name: Get Current Date as Tag
|
|
id: date
|
|
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Create and Push Manifests
|
|
run: |
|
|
echo "Creating the manifests..."
|
|
docker manifest create ghcr.io/ietf-tools/datatracker-db:nightly-${{ steps.date.outputs.date }} ghcr.io/ietf-tools/datatracker-db:latest-x64 ghcr.io/ietf-tools/datatracker-db:latest-arm64
|
|
docker manifest create ghcr.io/ietf-tools/datatracker-db:latest ghcr.io/ietf-tools/datatracker-db:latest-x64 ghcr.io/ietf-tools/datatracker-db:latest-arm64
|
|
echo "Pushing the manifests..."
|
|
docker manifest push -p ghcr.io/ietf-tools/datatracker-db:nightly-${{ steps.date.outputs.date }}
|
|
docker manifest push -p ghcr.io/ietf-tools/datatracker-db:latest
|
|
|
|
migrate:
|
|
name: Migrate MySQL to PostgreSQL DB
|
|
runs-on: ubuntu-latest
|
|
container: ghcr.io/ietf-tools/datatracker-app-base:latest
|
|
if: ${{ always() && !failure() }}
|
|
needs: [combine-mariadb]
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
services:
|
|
db:
|
|
image: ghcr.io/ietf-tools/datatracker-db:latest
|
|
volumes:
|
|
- mariadb-data:/var/lib/mysql
|
|
env:
|
|
MYSQL_ROOT_PASSWORD: ietf
|
|
MYSQL_DATABASE: ietf_utf8
|
|
MYSQL_USER: django
|
|
MYSQL_PASSWORD: RkTkDPFnKpko
|
|
pgdb:
|
|
image: postgres:14.5
|
|
volumes:
|
|
- /pgdata:/var/lib/postgresql/data
|
|
env:
|
|
POSTGRES_PASSWORD: RkTkDPFnKpko
|
|
POSTGRES_USER: django
|
|
POSTGRES_DB: ietf
|
|
POSTGRES_HOST_AUTH_METHOD: trust
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
ref: 'feat/postgres'
|
|
|
|
- name: Migrate
|
|
uses: nick-fields/retry@v2
|
|
with:
|
|
timeout_minutes: 30
|
|
max_attempts: 3
|
|
command: |
|
|
chmod +x ./docker/scripts/db-pg-migrate.sh
|
|
sh ./docker/scripts/db-pg-migrate.sh
|
|
on_retry_command: |
|
|
psql -U django -h pgdb -d ietf -v ON_ERROR_STOP=1 -c '\x' -c 'DROP SCHEMA ietf_utf8 CASCADE;'
|
|
rm -f cast.load
|
|
|
|
- name: Upload DB Dump
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dump
|
|
path: ietf.dump
|
|
|
|
- name: Export as SQL (Debug)
|
|
if: ${{ github.event.inputs.exportDumpAsSQL == 'true' }}
|
|
run: pg_dump -h pgdb -U django ietf > ietf.sql
|
|
|
|
- name: Upload SQL DB Dump (Debug)
|
|
if: ${{ github.event.inputs.exportDumpAsSQL == 'true' }}
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: dumpsql
|
|
path: ietf.sql
|
|
|
|
build:
|
|
name: Build PostgreSQL Docker Images
|
|
runs-on: ubuntu-latest
|
|
if: ${{ always() && !failure() }}
|
|
needs: [migrate]
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
ref: 'feat/postgres'
|
|
|
|
- name: Download DB Dump
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: dump
|
|
|
|
- name: Get Current Date as Tag
|
|
id: date
|
|
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Docker Build & Push
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: docker/db-pg.Dockerfile
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ghcr.io/ietf-tools/datatracker-db-pg:latest,ghcr.io/ietf-tools/datatracker-db-pg:nightly-${{ steps.date.outputs.date }}
|
|
provenance: false
|