Skip to content
Open
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
65 changes: 65 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Docker Build and Push

on:
push:
branches: [ main ]
tags: [ 'v*', 'latest' ]
pull_request:
branches: [ main ]
workflow_dispatch: # Allows manual triggering of the workflow

jobs:
build-and-push:
name: Build and Push PostgreSQL Backup Images
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
postgres-version: ['10', '11', '12', '13', '14', '15', '16', '17']

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
flavor: |
latest=auto
suffix=-pg${{ matrix.postgres-version }},onlatest=true

- name: Prepare build context
run: |
mkdir -p build/${{ matrix.postgres-version }}
cp template/* build/${{ matrix.postgres-version }}/
sed "s/%VERSION%/${{ matrix.postgres-version }}/g" template/Dockerfile > build/${{ matrix.postgres-version }}/Dockerfile

- name: Build and push
uses: docker/build-push-action@v6
with:
context: build/${{ matrix.postgres-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
88 changes: 88 additions & 0 deletions .github/workflows/smoketest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Smoke-test on pg16

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: # Allows manual triggering of the workflow

jobs:
test-backup:
name: Test PostgreSQL Backup
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_PASSWORD: test
POSTGRES_USER: test
POSTGRES_DB: testdb
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Create backup directory
run: mkdir -p ./backup-output

- name: Prepare build context
run: |
mkdir -p build/16
cp template/* build/16/
sed "s/%VERSION%/16/g" template/Dockerfile > build/16/Dockerfile

- name: Build test image
uses: docker/build-push-action@v6
with:
context: build/16
push: false
tags: postgresql-backup:test-16
load: true

- name: Run backup
run: |
docker run --rm \
--network=${{ job.container.network }} \
-e DB_HOST=postgres \
-e DB_PORT=5432 \
-e DB_PASS=test \
-e DB_USER=test \
-e DB_NAME=testdb \
-v ${{ github.workspace }}/backup-output:/data/backups \
--entrypoint "/backup/run.sh" \
postgresql-backup:test-16

- name: Check backup was created
run: |
echo "Checking for backup files..."
ls -la ${{ github.workspace }}/backup-output

# Count backup files
BACKUP_COUNT=$(find ${{ github.workspace }}/backup-output -type f | wc -l)

if [ "$BACKUP_COUNT" -eq 0 ]; then
echo "Error: No backup files were created!"
exit 1
else
echo "Success: Found $BACKUP_COUNT backup file(s)"
fi

# Verify backup file format
BACKUP_FILE=$(find ${{ github.workspace }}/backup-output -type f | head -n 1)
echo "Backup file: $BACKUP_FILE"

# Check if the backup file is a valid PostgreSQL dump
if file "$BACKUP_FILE" | grep -q "PostgreSQL"; then
echo "Success: Backup file is a valid PostgreSQL dump"
else
echo "Warning: Backup file format could not be verified"
file "$BACKUP_FILE"
fi
Loading