Skip to content

Commit 767fa1e

Browse files
initial commit
0 parents  commit 767fa1e

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

.github/workflows/docker-publish.yaml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
# Publish semver tags as releases.
12+
tags: [ 'v*.*.*' ]
13+
pull_request:
14+
branches: [ "main" ]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: ${{ github.repository }}
21+
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
28+
packages: write
29+
# This is used to complete the identity challenge
30+
# with sigstore/fulcio when running outside of PRs.
31+
id-token: write
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v3
36+
37+
# Set up BuildKit Docker container builder to be able to build
38+
# multi-platform images and export cache
39+
# https://github.com/docker/setup-buildx-action
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
42+
43+
# Login against a Docker registry except on PR
44+
# https://github.com/docker/login-action
45+
- name: Log into registry ${{ env.REGISTRY }}
46+
if: github.event_name != 'pull_request'
47+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
# Extract metadata (tags, labels) for Docker
54+
# https://github.com/docker/metadata-action
55+
- name: Extract Docker metadata
56+
id: meta
57+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
58+
with:
59+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60+
61+
# Build and push Docker image with Buildx (don't push on PR)
62+
# https://github.com/docker/build-push-action
63+
- name: Build and push Docker image
64+
id: build-and-push
65+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
66+
with:
67+
context: .
68+
push: ${{ github.event_name != 'pull_request' }}
69+
tags: ${{ steps.meta.outputs.tags }}
70+
labels: ${{ steps.meta.outputs.labels }}
71+
cache-from: type=gha
72+
cache-to: type=gha,mode=max
73+

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM postgres:16
2+
RUN apt update && apt install curl -y
3+
RUN curl https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/bin/mc && chmod +x /usr/bin/mc
4+
COPY backup.sh /usr/bin/backup.sh
5+
RUN chmod +x /usr/bin/backup.sh

backup.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
echo "Starting PostgreSQL backup to S3..."
3+
echo "Setup minio client..."
4+
mc alias set s3 ${S3_ENDPOINT} ${S3_ACCESSKEY} ${S3_SECRETKEY}
5+
echo "Backup database..."
6+
PGPASSWORD=${PSQL_PASS} pg_dump -h ${PSQL_HOST} -U ${PSQL_USER} -C ${PSQL_NAME} > /backups/backup.sql
7+
echo "Compress backup..."
8+
gzip /backups/backup.sql
9+
echo "Copy to S3..."
10+
mc cp /backups/backup.sql.gz s3/${S3_BUCKET}/db-${PSQL_NAME}-$(date "+%Y-%m-%dT%H-%M-%S").sql.gz
11+
echo "Notify HC..."
12+
curl ${HC_UR}
13+
echo "done."

0 commit comments

Comments
 (0)