Skip to content

Commit a9f3926

Browse files
committed
Adapt CI to arm64
1 parent fbffb62 commit a9f3926

2 files changed

Lines changed: 72 additions & 31 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 30 additions & 23 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:
@@ -33,24 +33,29 @@ jobs:
3333
pg_version:
3434
- "18"
3535
- "17"
36-
- "16"
37-
- "15"
38-
- "14"
39-
- "13"
40-
- "12"
41-
- "11"
42-
- "10"
43-
- "9.6"
36+
# - "16"
37+
# - "15"
38+
# - "14"
39+
# - "13"
40+
# - "12"
41+
# - "11"
42+
# - "10"
43+
# - "9.6"
4444
env:
45-
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
45+
# Indicates what's the equivalent to pyxiris/postgres-autoconf:latest image
4646
LATEST_RELEASE: "18-alpine"
47-
DOCKER_REPO: tecnativa/postgres-autoconf
47+
DOCKER_REPO: pyxiris/postgres-autoconf
4848
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
4949
GIT_SHA1: ${{ github.sha }}
5050
IS_PR: ${{ github.event_name == 'pull_request' }}
51+
PG_VERSION: ${{ matrix.pg_version }}
5152
steps:
5253
- uses: actions/checkout@v4
5354
- uses: actions/setup-python@v6
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v3
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3
5459
- run: pip install -r tests/ci-requirements.txt
5560

5661
# Build images
@@ -68,17 +73,19 @@ jobs:
6873
if: env.IS_PR
6974
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
7075
# 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
76+
# - name: Push Docker Image to Docker Hub
77+
# 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))
78+
# env:
79+
# REGISTRY_HOST: docker.io
80+
# REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
81+
# REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
82+
# DOCKER_PLATFORM: linux/amd64,linux/arm64
83+
# run: ./hooks/push
7884
- 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))
85+
if: github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
8086
env:
8187
REGISTRY_HOST: ghcr.io
82-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
83-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
88+
REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
REGISTRY_USERNAME: ${{ github.repository_owner }}
90+
DOCKER_PLATFORM: linux/amd64,linux/arm64
8491
run: ./hooks/push

hooks/push

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
import datetime
23
from plumbum import FG, local
34
from plumbum.cmd import docker
45

@@ -7,6 +8,11 @@ REPO = local.env["DOCKER_REPO"]
78
SUFFIX = local.env.get("DOCKER_REPO_SUFFIX", "")
89
VERSION = local.env["DOCKER_TAG"]
910

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

@@ -20,13 +26,41 @@ docker(
2026
REGISTRY,
2127
)
2228

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

0 commit comments

Comments
 (0)