Skip to content

Commit 6de140f

Browse files
committed
Adapt CI to arm64
1 parent fbffb62 commit 6de140f

5 files changed

Lines changed: 86 additions & 41 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ on:
55
push:
66
branches:
77
- master
8-
schedule:
9-
# See https://crontab.guru/weekly
10-
- cron: 0 0 * * 0
8+
# schedule:
9+
# # See https://crontab.guru/weekly
10+
# - cron: 0 0 * * 0
1111

1212
jobs:
1313
pre-commit:
@@ -27,30 +27,38 @@ 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:
3336
pg_version:
3437
- "18"
3538
- "17"
36-
- "16"
37-
- "15"
38-
- "14"
39-
- "13"
40-
- "12"
41-
- "11"
42-
- "10"
43-
- "9.6"
39+
# - "16"
40+
# - "15"
41+
# - "14"
42+
# - "13"
43+
# - "12"
44+
# - "11"
45+
# - "10"
46+
# - "9.6"
4447
env:
45-
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
48+
# Indicates what's the equivalent to pyxiris/postgres-autoconf:latest image
4649
LATEST_RELEASE: "18-alpine"
47-
DOCKER_REPO: tecnativa/postgres-autoconf
50+
DOCKER_REPO: pyxiris/postgres-autoconf
4851
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
4952
GIT_SHA1: ${{ github.sha }}
5053
IS_PR: ${{ github.event_name == 'pull_request' }}
54+
PG_VERSION: ${{ matrix.pg_version }}
5155
steps:
5256
- uses: actions/checkout@v4
5357
- uses: actions/setup-python@v6
58+
- name: Set up QEMU
59+
uses: docker/setup-qemu-action@v3
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v3
5462
- run: pip install -r tests/ci-requirements.txt
5563

5664
# Build images
@@ -65,20 +73,22 @@ jobs:
6573
echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV
6674
fi
6775
- name: Tag Docker Image for PR
68-
if: env.IS_PR
76+
if: github.event_name == 'pull_request'
6977
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
7078
# 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
79+
# - name: Push Docker Image to Docker Hub
80+
# 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))
81+
# env:
82+
# REGISTRY_HOST: docker.io
83+
# REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
84+
# REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
85+
# DOCKER_PLATFORM: linux/amd64,linux/arm64
86+
# run: ./hooks/push
7887
- 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))
88+
if: github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
8089
env:
8190
REGISTRY_HOST: ghcr.io
82-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
83-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
91+
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
REGISTRY_USERNAME: ${{ github.repository_owner }}
93+
DOCKER_PLATFORM: linux/amd64,linux/arm64
8494
run: ./hooks/push

Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ RUN apk add --no-cache python3 py3-netifaces \
3535
COPY autoconf-entrypoint /
3636

3737
# Metadata
38-
ARG VCS_REF
39-
ARG BUILD_DATE
40-
LABEL org.label-schema.vendor=Tecnativa \
41-
org.label-schema.license=Apache-2.0 \
42-
org.label-schema.build-date="$BUILD_DATE" \
43-
org.label-schema.vcs-ref="$VCS_REF" \
44-
org.label-schema.vcs-url="https://github.com/Tecnativa/docker-postgres-autoconf"
38+
# ARG VCS_REF
39+
# ARG BUILD_DATE
40+
# LABEL org.label-schema.vendor=Tecnativa \
41+
# org.label-schema.license=Apache-2.0 \
42+
# org.label-schema.build-date="$BUILD_DATE" \
43+
# org.label-schema.vcs-ref="$VCS_REF" \
44+
# org.label-schema.vcs-url="https://github.com/Tecnativa/docker-postgres-autoconf"

hooks/build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DATE = date("--rfc-3339", "ns")
1919
"--build-arg",
2020
"BASE_TAG={}".format(DOCKER_TAG),
2121
"--tag",
22-
"tecnativa/postgres-autoconf:{}".format(DOCKER_TAG),
22+
"pyxiris/postgres-autoconf:{}".format(DOCKER_TAG),
2323
".",
2424
]
2525
& FG

hooks/push

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env python3
2+
import datetime
3+
24
from plumbum import FG, local
35
from plumbum.cmd import docker
46

@@ -7,6 +9,11 @@ REPO = local.env["DOCKER_REPO"]
79
SUFFIX = local.env.get("DOCKER_REPO_SUFFIX", "")
810
VERSION = local.env["DOCKER_TAG"]
911

12+
# Multi-arch configuration
13+
PLATFORMS = local.env.get("DOCKER_PLATFORM")
14+
PG_VERSION = local.env.get("PG_VERSION", VERSION.split("-")[0])
15+
GIT_SHA1 = local.env.get("GIT_SHA1", "")
16+
1017
# Log all locally available images; will help to pin images
1118
docker["image", "ls", "--digests", REPO] & FG
1219

@@ -20,13 +27,41 @@ docker(
2027
REGISTRY,
2128
)
2229

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
30+
31+
def push_image(tag):
32+
public_image = "%s/%s%s:%s" % (REGISTRY, REPO, SUFFIX, tag)
33+
if PLATFORMS:
34+
print(f"Building and pushing multi-arch image: {public_image}")
35+
# Re-build for all platforms and push directly
36+
# We use VERSION as the BASE_TAG for the Dockerfile
37+
(
38+
docker[
39+
"buildx",
40+
"build",
41+
"--platform",
42+
PLATFORMS,
43+
"--build-arg",
44+
f"BASE_TAG={PG_VERSION}-alpine",
45+
"--build-arg",
46+
f"VCS_REF={GIT_SHA1}",
47+
"--build-arg",
48+
f"BUILD_DATE={datetime.datetime.now().isoformat()}",
49+
"--tag",
50+
public_image,
51+
"--push",
52+
".",
53+
]
54+
& FG
55+
)
56+
else:
57+
# Fallback to standard push for single architecture
58+
local_image = "%s:%s" % (REPO, VERSION)
59+
docker["image", "tag", local_image, public_image] & FG
60+
docker["image", "push", public_image] & FG
61+
62+
63+
push_image(VERSION)
64+
2865
if VERSION == local.env.get("LATEST_RELEASE"):
2966
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
67+
push_image(latest_version)

tests/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def setUpClass(cls):
2727
with local.cwd(local.cwd / ".."):
2828
print("Building image")
2929
local["./hooks/build"] & FG
30-
cls.image = f"tecnativa/postgres-autoconf:{local.env['DOCKER_TAG']}"
30+
cls.image = f"{local.env.get('DOCKER_REPO', 'pyxiris/postgres-autoconf')}:{local.env['DOCKER_TAG']}"
3131
cls.cert_files = ("client.ca.cert.pem", "server.cert.pem", "server.key.pem")
3232
return super().setUpClass()
3333

0 commit comments

Comments
 (0)