Skip to content

Commit 76945c3

Browse files
committed
Add ARM64
1 parent fbffb62 commit 76945c3

4 files changed

Lines changed: 77 additions & 21 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
build-test-push:
2828
runs-on: ubuntu-latest
2929
needs: pre-commit
30+
permissions:
31+
contents: read
32+
packages: write
3033
strategy:
3134
fail-fast: false
3235
matrix:
@@ -44,11 +47,23 @@ jobs:
4447
env:
4548
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4649
LATEST_RELEASE: "18-alpine"
47-
DOCKER_REPO: tecnativa/postgres-autoconf
4850
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
4951
GIT_SHA1: ${{ github.sha }}
52+
PG_VERSION: ${{ matrix.pg_version }}
5053
IS_PR: ${{ github.event_name == 'pull_request' }}
54+
PUBLISH: ${{ github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
55+
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
56+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
57+
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }}
5158
steps:
59+
# Image repo names have to be lowercase.
60+
- name: Set image repository name
61+
run: |
62+
if [ "$GITHUB_REPOSITORY" = "Tecnativa/docker-postgres-autoconf" ]; then
63+
echo "DOCKER_REPO=tecnativa/postgres-autoconf" >> "$GITHUB_ENV"
64+
else
65+
echo "DOCKER_REPO=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
66+
fi
5267
- uses: actions/checkout@v4
5368
- uses: actions/setup-python@v6
5469
- run: pip install -r tests/ci-requirements.txt
@@ -67,18 +82,26 @@ jobs:
6782
- name: Tag Docker Image for PR
6883
if: env.IS_PR
6984
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
85+
- name: Set up QEMU
86+
if: env.PUBLISH
87+
uses: docker/setup-qemu-action@v4
88+
- name: Set up Docker Buildx
89+
if: env.PUBLISH
90+
uses: docker/setup-buildx-action@v4
7091
# Push
7192
- 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))
93+
if: env.PUBLISH && env.DOCKERHUB_TOKEN && env.DOCKERHUB_LOGIN
7394
env:
7495
REGISTRY_HOST: docker.io
75-
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
76-
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
96+
REGISTRY_TOKEN: ${{ env.DOCKERHUB_TOKEN }}
97+
REGISTRY_USERNAME: ${{ env.DOCKERHUB_LOGIN }}
98+
DOCKER_PLATFORM: linux/amd64,linux/arm64
7799
run: ./hooks/push
78100
- 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))
101+
if: env.PUBLISH
80102
env:
81103
REGISTRY_HOST: ghcr.io
82-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
83-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
104+
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
105+
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN || github.repository_owner }}
106+
DOCKER_PLATFORM: linux/amd64,linux/arm64
84107
run: ./hooks/push

hooks/build

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

55
# Check environment variables are present
66
DOCKER_TAG = local.env["DOCKER_TAG"]
7+
REPO = local.env["DOCKER_REPO"]
78
COMMIT = local.env.get("GIT_SHA1")
89
DATE = date("--rfc-3339", "ns")
910

@@ -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(REPO, DOCKER_TAG),
2324
".",
2425
]
2526
& FG

hooks/push

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/usr/bin/env python3
22
from plumbum import FG, local
3-
from plumbum.cmd import docker
3+
from plumbum.cmd import date, docker
44

55
REGISTRY = local.env.get("REGISTRY_HOST", "docker.io")
66
REPO = local.env["DOCKER_REPO"]
77
SUFFIX = local.env.get("DOCKER_REPO_SUFFIX", "")
88
VERSION = local.env["DOCKER_TAG"]
99

10+
PLATFORMS = local.env.get("DOCKER_PLATFORM")
11+
PG_VERSION = local.env.get("PG_VERSION", VERSION.split("-")[0])
12+
GIT_SHA1 = local.env.get("GIT_SHA1", "")
13+
1014
# Log all locally available images; will help to pin images
1115
docker["image", "ls", "--digests", REPO] & FG
1216

@@ -20,13 +24,39 @@ docker(
2024
REGISTRY,
2125
)
2226

23-
# Push built images
24-
local_image = "%s:%s" % (REPO, VERSION)
25-
public_image = "%s/%s%s:%s" % (REGISTRY, REPO, SUFFIX, VERSION)
26-
docker["image", "tag", local_image, public_image] & FG
27-
docker["image", "push", public_image] & FG
28-
if VERSION == local.env.get("LATEST_RELEASE"):
29-
latest_version = "alpine" if VERSION.endswith("-alpine") else "latest"
30-
public_image = "%s/%s%s:%s" % (REGISTRY, REPO, SUFFIX, latest_version)
31-
docker["image", "tag", local_image, public_image] & FG
32-
docker["image", "push", public_image] & FG
27+
28+
def public_image(tag):
29+
return "%s/%s%s:%s" % (REGISTRY, REPO, SUFFIX, tag)
30+
31+
32+
def tags_to_push():
33+
tags = [VERSION]
34+
if VERSION == local.env.get("LATEST_RELEASE"):
35+
latest_version = "alpine" if VERSION.endswith("-alpine") else "latest"
36+
tags.append(latest_version)
37+
return tags
38+
39+
40+
if PLATFORMS:
41+
BUILD_DATE = date("--rfc-3339", "ns")
42+
cmd = docker[
43+
"buildx",
44+
"build",
45+
"--platform",
46+
PLATFORMS,
47+
"--build-arg",
48+
"BASE_TAG={}-alpine".format(PG_VERSION),
49+
"--build-arg",
50+
"VCS_REF={}".format(GIT_SHA1),
51+
"--build-arg",
52+
"BUILD_DATE={}".format(BUILD_DATE),
53+
]
54+
for tag in tags_to_push():
55+
cmd = cmd["--tag", public_image(tag)]
56+
(cmd["--push", "."] & FG)
57+
else:
58+
local_image = "%s:%s" % (REPO, VERSION)
59+
for tag in tags_to_push():
60+
image = public_image(tag)
61+
docker["image", "tag", local_image, image] & FG
62+
docker["image", "push", image] & FG

tests/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class PostgresAutoconfCase(unittest.TestCase):
2424

2525
@classmethod
2626
def setUpClass(cls):
27-
with local.cwd(local.cwd / ".."):
27+
base_tag = local.env.get("BASE_TAG", local.env["DOCKER_TAG"])
28+
with local.cwd(local.cwd / ".."), local.env(BASE_TAG=base_tag):
2829
print("Building image")
2930
local["./hooks/build"] & FG
30-
cls.image = f"tecnativa/postgres-autoconf:{local.env['DOCKER_TAG']}"
31+
repo = local.env.get("DOCKER_REPO", "tecnativa/postgres-autoconf")
32+
cls.image = f"{repo}:{local.env['DOCKER_TAG']}"
3133
cls.cert_files = ("client.ca.cert.pem", "server.cert.pem", "server.key.pem")
3234
return super().setUpClass()
3335

0 commit comments

Comments
 (0)