Skip to content

Commit f908ed6

Browse files
committed
Add ARM64
1 parent fbffb62 commit f908ed6

3 files changed

Lines changed: 41 additions & 24 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ jobs:
2525
- uses: pre-commit/action@v1.0.1
2626

2727
build-test-push:
28+
if: github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
2829
runs-on: ubuntu-latest
2930
needs: pre-commit
31+
permissions:
32+
contents: read
33+
packages: write
3034
strategy:
3135
fail-fast: false
3236
matrix:
@@ -42,43 +46,49 @@ jobs:
4246
- "10"
4347
- "9.6"
4448
env:
49+
DOCKER_PLATFORM: linux/amd64,linux/arm64
4550
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4651
LATEST_RELEASE: "18-alpine"
47-
DOCKER_REPO: tecnativa/postgres-autoconf
48-
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
52+
DOCKER_REPO: "" # Set in the next step
53+
BASE_TAG: ${{ matrix.pg_version }}-alpine
54+
DOCKER_TAG: ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
4955
GIT_SHA1: ${{ github.sha }}
50-
IS_PR: ${{ github.event_name == 'pull_request' }}
56+
PG_VERSION: ${{ matrix.pg_version }}
57+
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
58+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
59+
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }}
5160
steps:
61+
# Image repo names have to be lowercase.
62+
- name: Set image repository name
63+
run: |
64+
if [ "$GITHUB_REPOSITORY" = "Tecnativa/docker-postgres-autoconf" ]; then
65+
echo "DOCKER_REPO=tecnativa/postgres-autoconf" >> "$GITHUB_ENV"
66+
else
67+
echo "DOCKER_REPO=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
68+
fi
5269
- uses: actions/checkout@v4
5370
- uses: actions/setup-python@v6
5471
- run: pip install -r tests/ci-requirements.txt
5572

73+
- name: Set up QEMU
74+
uses: docker/setup-qemu-action@v4
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v4
5677
# Build images
5778
- run: ./hooks/build
5879
# Test
5980
- run: python -m unittest tests.test -v
60-
- name: Set Docker Tag
61-
run: |
62-
if [ "${{ env.IS_PR }}" = "true" ]; then
63-
echo "DOCKER_TAG=${{ matrix.pg_version }}-test-pr${{ github.event.number }}" >> $GITHUB_ENV
64-
else
65-
echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV
66-
fi
67-
- name: Tag Docker Image for PR
68-
if: env.IS_PR
69-
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
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.DOCKERHUB_TOKEN && env.DOCKERHUB_LOGIN
7384
env:
7485
REGISTRY_HOST: docker.io
75-
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
76-
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
86+
REGISTRY_TOKEN: ${{ env.DOCKERHUB_TOKEN }}
87+
REGISTRY_USERNAME: ${{ env.DOCKERHUB_LOGIN }}
7788
run: ./hooks/push
7889
- 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))
8090
env:
8191
REGISTRY_HOST: ghcr.io
82-
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}
83-
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN }}
92+
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
93+
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN || github.repository_owner }}
8494
run: ./hooks/push

hooks/build

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@ from plumbum import FG, local
33
from plumbum.cmd import date, docker
44

55
# Check environment variables are present
6+
DOCKER_PLATFORM = local.env.get("DOCKER_PLATFORM", "linux/amd64,linux/arm64")
67
DOCKER_TAG = local.env["DOCKER_TAG"]
8+
BASE_TAG = local.env.get("BASE_TAG", DOCKER_TAG)
9+
REPO = local.env["DOCKER_REPO"]
710
COMMIT = local.env.get("GIT_SHA1")
811
DATE = date("--rfc-3339", "ns")
912

1013
# Build image
1114
(
1215
docker[
13-
"image",
16+
"buildx",
1417
"build",
18+
"--platform",
19+
local.env["DOCKER_PLATFORM"],
1520
"--build-arg",
1621
"VCS_REF={}".format(COMMIT),
1722
"--build-arg",
1823
"BUILD_DATE={}".format(DATE),
1924
"--build-arg",
20-
"BASE_TAG={}".format(DOCKER_TAG),
25+
"BASE_TAG={}".format(BASE_TAG),
2126
"--tag",
22-
"tecnativa/postgres-autoconf:{}".format(DOCKER_TAG),
27+
"{}:{}".format(REPO, DOCKER_TAG),
2328
".",
2429
]
2530
& 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)