Skip to content

Commit 0fff03b

Browse files
committed
Add ARM64
1 parent fbffb62 commit 0fff03b

4 files changed

Lines changed: 65 additions & 19 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 18 additions & 5 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,10 +47,12 @@ 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
50+
DOCKER_REPO: ${{ github.repository == 'Tecnativa/docker-postgres-autoconf' && 'tecnativa/postgres-autoconf' || github.repository }}
4851
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
4952
GIT_SHA1: ${{ github.sha }}
53+
PG_VERSION: ${{ matrix.pg_version }}
5054
IS_PR: ${{ github.event_name == 'pull_request' }}
55+
PUBLISH: ${{ github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
5156
steps:
5257
- uses: actions/checkout@v4
5358
- uses: actions/setup-python@v6
@@ -67,18 +72,26 @@ jobs:
6772
- name: Tag Docker Image for PR
6873
if: env.IS_PR
6974
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
75+
- name: Set up QEMU
76+
if: env.PUBLISH
77+
uses: docker/setup-qemu-action@v4
78+
- name: Set up Docker Buildx
79+
if: env.PUBLISH
80+
uses: docker/setup-buildx-action@v4
7081
# Push
7182
- 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))
83+
if: env.PUBLISH && secrets.DOCKERHUB_TOKEN != ''
7384
env:
7485
REGISTRY_HOST: docker.io
7586
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
7687
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
88+
DOCKER_PLATFORM: linux/amd64,linux/arm64
7789
run: ./hooks/push
7890
- 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))
91+
if: env.PUBLISH
8092
env:
8193
REGISTRY_HOST: ghcr.io
82-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
83-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
94+
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN != '' && secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
95+
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN != '' && secrets.BOT_LOGIN || github.repository_owner }}
96+
DOCKER_PLATFORM: linux/amd64,linux/arm64
8497
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)