Skip to content

Add support to perform an initial backup on startup #88

Add support to perform an initial backup on startup

Add support to perform an initial backup on startup #88

Workflow file for this run

name: CI
on:
push:
branches:
- 'main'
paths-ignore:
- '**.md'
- '.gitignore'
- '.github/workflows/pushrm.yml'
pull_request:
paths-ignore:
- '**.md'
- '.github/**'
jobs:
test-script:
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:14
env:
POSTGRES_DB: "database"
POSTGRES_USER: "user"
POSTGRES_PASSWORD: "test"
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options:
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Test backup script for pg_dump
env:
POSTGRES_DB: "database"
POSTGRES_USER: "user"
POSTGRES_PASSWORD: "test"
POSTGRES_HOST: "127.0.0.1"
POSTGRES_PORT: 5432
POSTGRES_EXTRA_OPTS: "-Z0"
BACKUP_DIR: "/tmp/backups"
# Defaults
POSTGRES_DB_FILE: "**None**"
POSTGRES_USER_FILE: "**None**"
POSTGRES_PASSWORD_FILE: "**None**"
POSTGRES_PASSFILE_STORE: "**None**"
POSTGRES_CLUSTER: "FALSE"
BACKUP_SUFFIX: ".sql.gz"
BACKUP_LATEST_TYPE: "symlink"
BACKUP_KEEP_DAYS: 7
BACKUP_KEEP_WEEKS: 4
BACKUP_KEEP_MONTHS: 6
BACKUP_KEEP_MINS: 1440
WEBHOOK_URL: "**None**"
WEBHOOK_EXTRA_ARGS: ""
run: |
echo "Test backup script for pg_dump..."
rm -fR "$BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
bash -x backup.sh
echo "Generated backup files:"
ls -laR "$BACKUP_DIR"
- name: Test backup script for pg_dump with directories
env:
POSTGRES_DB: "database"
POSTGRES_USER: "user"
POSTGRES_PASSWORD: "test"
POSTGRES_HOST: "127.0.0.1"
POSTGRES_PORT: 5432
POSTGRES_EXTRA_OPTS: "-Z0 -Fd"
BACKUP_SUFFIX: ""
BACKUP_LATEST_TYPE: "symlink"
BACKUP_DIR: "/tmp/backups"
# Defaults
POSTGRES_DB_FILE: "**None**"
POSTGRES_USER_FILE: "**None**"
POSTGRES_PASSWORD_FILE: "**None**"
POSTGRES_PASSFILE_STORE: "**None**"
POSTGRES_CLUSTER: "FALSE"
BACKUP_KEEP_DAYS: 7
BACKUP_KEEP_WEEKS: 4
BACKUP_KEEP_MONTHS: 6
BACKUP_KEEP_MINS: 1440
WEBHOOK_URL: "**None**"
WEBHOOK_EXTRA_ARGS: ""
run: |
echo "Test backup script for pg_dump with directories..."
rm -fR "$BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
bash -x backup.sh
echo "Generated backup files:"
ls -laR "$BACKUP_DIR"
- name: Test backup script for pg_dumpall
env:
POSTGRES_CLUSTER: "TRUE"
POSTGRES_DB: "database"
POSTGRES_USER: "user"
POSTGRES_PASSWORD: "test"
POSTGRES_HOST: "127.0.0.1"
POSTGRES_PORT: 5432
POSTGRES_EXTRA_OPTS: ""
BACKUP_DIR: "/tmp/backups"
# Defaults
POSTGRES_DB_FILE: "**None**"
POSTGRES_USER_FILE: "**None**"
POSTGRES_PASSWORD_FILE: "**None**"
POSTGRES_PASSFILE_STORE: "**None**"
BACKUP_SUFFIX: ".sql.gz"
BACKUP_LATEST_TYPE: "symlink"
BACKUP_KEEP_DAYS: 7
BACKUP_KEEP_WEEKS: 4
BACKUP_KEEP_MONTHS: 6
BACKUP_KEEP_MINS: 1440
WEBHOOK_URL: "**None**"
WEBHOOK_EXTRA_ARGS: ""
run: |
echo "Test backup script for pg_dumpall..."
rm -fR "$BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
bash -x backup.sh
echo "Generated backup files:"
ls -laR "$BACKUP_DIR"
- name: Test docker-bake.hcl contents
run: |
echo "Test if docker-bake.hcl have been generated by generate-docker-bake.sh..."
./generate-docker-bake.sh docker-bake-generated.hcl
cmp docker-bake.hcl docker-bake-generated.hcl
test-docker:
if: ${{ github.event_name == 'pull_request' || github.ref != 'refs/heads/main' }}
needs: [ test-script ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Test docker images build
run: docker buildx bake --pull
publish:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
needs: [ test-script ]
runs-on: ubuntu-22.04
environment: docker.io
steps:
# Increase available disk space by removing unnecessary tool chains:
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173
- name: Increase available disk space
run: sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost "$AGENT_TOOLSDIRECTORY"
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Configure build revision
id: vars
run: echo "::set-output name=sha_short::${GITHUB_SHA:0:7}"
- name: Build images
env:
REGISTRY_PREFIX: ${{ secrets.DOCKERHUB_USERNAME }}/
BUILD_REVISION: ${{ steps.vars.outputs.sha_short }}
run: docker buildx bake --pull
- name: Push images
env:
REGISTRY_PREFIX: ${{ secrets.DOCKERHUB_USERNAME }}/
BUILD_REVISION: ${{ steps.vars.outputs.sha_short }}
run: docker buildx bake --push
## Example of publish using GitHub Container Registry instead
# publish:
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# needs: [ test-script ]
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Build images
# env:
# REGISTRY_PREFIX: ghcr.io/${{ github.repository_owner }}/
# run: docker buildx bake --pull
#
# - name: Push images
# env:
# REGISTRY_PREFIX: ghcr.io/${{ github.repository_owner }}/
# run: docker buildx bake --push