Skip to content

Commit 6898122

Browse files
committed
ci: parametrize build and push for fork portability
Hardcoded references to tecnativa/postgres-autoconf and the upstream repo prevented forks from building and publishing their own images. Replace with dynamic values: - hooks/build reads DOCKER_REPO from environment (with fallback) - CI uses github.repository_owner for repo and GITHUB_TOKEN for GHCR - Drop Docker Hub push (requires manual secrets setup) - Only push on master branch to ghcr.io This enables any fork to build, test, and publish images to GHCR without additional secret configuration.
1 parent fbffb62 commit 6898122

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
env:
4545
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4646
LATEST_RELEASE: "18-alpine"
47-
DOCKER_REPO: tecnativa/postgres-autoconf
47+
DOCKER_REPO: ${{ github.repository_owner }}/postgres-autoconf
4848
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
4949
GIT_SHA1: ${{ github.sha }}
5050
IS_PR: ${{ github.event_name == 'pull_request' }}
@@ -67,18 +67,11 @@ jobs:
6767
- name: Tag Docker Image for PR
6868
if: env.IS_PR
6969
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
70-
# Push
71-
- name: Push Docker Image to Docker Hub
72-
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && (github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
73-
env:
74-
REGISTRY_HOST: docker.io
75-
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
76-
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
77-
run: ./hooks/push
78-
- name: Push Docker Image to GitHub Registry
79-
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && (github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
70+
# Push to GitHub Container Registry
71+
- name: Push Docker Image to GitHub Container Registry
72+
if: github.ref == 'refs/heads/master'
8073
env:
8174
REGISTRY_HOST: ghcr.io
82-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
83-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
75+
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
REGISTRY_USERNAME: ${{ github.actor }}
8477
run: ./hooks/push

hooks/build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from plumbum import FG, local
33
from plumbum.cmd import date, docker
44

55
# Check environment variables are present
6+
DOCKER_REPO = local.env.get("DOCKER_REPO", "tecnativa/postgres-autoconf")
67
DOCKER_TAG = local.env["DOCKER_TAG"]
78
COMMIT = local.env.get("GIT_SHA1")
89
DATE = date("--rfc-3339", "ns")
@@ -19,7 +20,7 @@ DATE = date("--rfc-3339", "ns")
1920
"--build-arg",
2021
"BASE_TAG={}".format(DOCKER_TAG),
2122
"--tag",
22-
"tecnativa/postgres-autoconf:{}".format(DOCKER_TAG),
23+
"{}:{}".format(DOCKER_REPO, DOCKER_TAG),
2324
".",
2425
]
2526
& FG

0 commit comments

Comments
 (0)