File tree Expand file tree Collapse file tree 5 files changed +112
-0
lines changed Expand file tree Collapse file tree 5 files changed +112
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Delete Old Docker Image
2+
3+ on :
4+ workflow_dispatch :
5+
6+ jobs :
7+
8+ cleanup-pg :
9+ runs-on : ubuntu-latest
10+ steps :
11+
12+ - name : Cleanup Docker images from GHCR
13+ uses : dataaxiom/ghcr-cleanup-action@v1
14+ with :
15+ token : ${{ secrets.GITHUB_TOKEN }}
16+ owner : ${{ github.repository_owner }}
17+ repository : multi-repo/Postgres
18+ keep-n-tagged : 1
19+ package : multi-repo/Postgres/pg
20+ dry-run : false
Original file line number Diff line number Diff line change 1+ name : Build Docker Images
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ release :
8+ types : [created, published, released]
9+
10+
11+ jobs :
12+
13+ ghcr-build-pg :
14+ runs-on : ubuntu-latest
15+ container :
16+ image : gcr.io/kaniko-project/executor:v1.23.0-debug
17+ options : --entrypoint /bin/sh
18+ permissions :
19+ packages : write
20+
21+
22+ steps :
23+
24+
25+ - name : Set branch name as environment variable
26+ run : echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
27+
28+ - name : Set up Docker config for Kaniko
29+ run : |
30+ cat <<EOF > /kaniko/.docker/config.json
31+ {
32+ "auths": {
33+ "ghcr.io": {
34+ "auth": "$(echo -n "$GIT_USERNAME:$GIT_PASSWORD" | base64 -w0)"
35+ }
36+ }
37+ }
38+ EOF
39+ env :
40+ GIT_USERNAME : ${{ github.actor }}
41+ GIT_PASSWORD : ${{ secrets.GITHUB_TOKEN }}
42+
43+
44+ - name : Build and push pg
45+ run : |
46+ /kaniko/executor --dockerfile="Dockerfile" \
47+ --context="${{ github.repositoryUrl }}#${{ github.ref_name }}#${{ github.sha }}" \
48+ --destination="$GH_REGISTRY/$IMAGE_NAME:${GITHUB_REF_NAME}" \
49+
50+ env :
51+ GH_REGISTRY : " ghcr.io"
52+ IMAGE_NAME : " ${{ github.repository }}/pg"
53+
54+
55+
56+ delete-old-images :
57+ runs-on : ubuntu-latest
58+
59+ steps :
60+ - name : Trigger Delete Old Image Workflow
61+ run : |
62+ curl -X POST \
63+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
64+ -H "Accept: application/vnd.github.v3+json" \
65+ https://api.github.com/repos/${{ github.repository }}/actions/workflows/delete-old-image.yml/dispatches \
66+ -d '{"ref": "main"}'
67+
68+
69+ deploy :
70+ needs : [delete-old-images, ghcr-build-pg]
71+ runs-on : ubuntu-latest
72+ steps :
73+ - name : Deploy to environment
74+ run : |
75+ echo "Deploying application"
Original file line number Diff line number Diff line change 1+ FROM postgres:16.6
2+
3+ COPY create-db.sh /docker-entrypoint-initdb.d/create-db.sh
4+ RUN chmod +x /docker-entrypoint-initdb.d/create-db.sh
5+
6+ CMD ["postgres" ]
Original file line number Diff line number Diff line change 1+ ### postgres image
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ until pg_isready -U " $POSTGRES_USER " ; do
4+ echo " Waiting for PostgreSQL to start..."
5+ sleep 1
6+ done
7+
8+ psql -v ON_ERROR_STOP=1 --username " $POSTGRES_USER " --no-password << -EOSQL
9+ CREATE DATABASE "$DATABASE_NAME ";
10+ EOSQL
You can’t perform that action at this time.
0 commit comments