Skip to content

Commit a7e322a

Browse files
committed
add experimental buildx workflow
1 parent 34f8447 commit a7e322a

File tree

5 files changed

+182
-13
lines changed

5 files changed

+182
-13
lines changed

.github/workflows/buildx.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: buildx-qemu-experimental-build
2+
3+
# This workflow is a QEMU-BUILDX based.
4+
# - Not for the platform='linux/amd64' see --> `main.yml' !
5+
# - Not for the `*-master``building. Emulation takes a lot of times!
6+
#
7+
# Expecting: upstream "postgres" docker images for OS/ARCH=platforms
8+
# [ check https://hub.docker.com/_/postgres/tags ]
9+
#
10+
# Comments: 2022-09-07 ( with QEMU 7.00 )
11+
# 'linux/arm64' Postgres JIT is not working; ( SET JIT=OFF under the alpine test )
12+
# 'linux/arm/v7' - debian: Unable to locate package postgresql-??-postgis-3;
13+
# 'linux/arm/v6' - debian: Unable to locate package postgresql-??-postgis-3;
14+
# 'linux/s390x' [alpine|debian] failed test.
15+
# 'linux/mips64le' [alpine|debian] failed test.
16+
#
17+
18+
on:
19+
push:
20+
pull_request:
21+
schedule:
22+
- cron: '15 6 * * 1'
23+
24+
defaults:
25+
run:
26+
shell: bash
27+
28+
jobs:
29+
30+
make-docker-images:
31+
strategy:
32+
# allowing fails ..
33+
fail-fast: false
34+
matrix:
35+
# succesful tests matrix:
36+
platforms: ['linux/arm64','linux/arm/v7','linux/arm/v6','linux/386','linux/ppc64le']
37+
postgres: [ 15 ]
38+
postgis: ['3.3']
39+
variant: [alpine]
40+
include:
41+
- postgres: 15
42+
postgis: '3.3'
43+
variant: 'default'
44+
platforms: 'linux/arm64'
45+
- postgres: 15
46+
postgis: '3.3'
47+
variant: 'default'
48+
platforms: 'linux/ppc64le'
49+
50+
name: ${{ matrix.platforms }} ${{ matrix.postgres }}-${{ matrix.postgis }} ${{ matrix.variant }}
51+
runs-on: ubuntu-latest
52+
53+
env:
54+
VERSION: ${{ matrix.postgres }}-${{ matrix.postgis }}
55+
VARIANT: ${{ matrix.variant }}
56+
# Not the default (main) workflow!
57+
WORKFLOW: buildx
58+
# Docker image tag postfix
59+
TAG_POSTFIX: '-experimental'
60+
61+
steps:
62+
63+
- name: Checkout
64+
uses: actions/checkout@v3
65+
66+
- name: Set up QEMU
67+
uses: docker/setup-qemu-action@v2
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v2
71+
72+
- name: "debug: docker buildx inspect --bootstrap"
73+
run: docker buildx inspect --bootstrap
74+
75+
- name: "debug: docker buildx ls"
76+
run: docker buildx ls
77+
78+
- name: "Inspect the base alpine image postgres:${{ matrix.postgres }}-alpine3.16"
79+
if: ${{ env.VARIANT == 'alpine' }}
80+
run: docker pull --platform=${{ matrix.platforms }} postgres:${{ matrix.postgres }}-alpine3.16 && docker inspect postgres:${{ matrix.postgres }}-alpine3.16
81+
env:
82+
DOCKER_DEFAULT_PLATFORM: ${{ matrix.platforms }}
83+
PLATFORM: ${{ matrix.platforms }}
84+
85+
- name: "Build/Test: ${{ env.VERSION }} ${{ env.VARIANT }}${{env.TAG_POSTFIX}} ${{ env.DOCKER_DEFAULT_PLATFORM }}"
86+
run: make test
87+
env:
88+
DOCKER_DEFAULT_PLATFORM: ${{ matrix.platforms }}
89+
PLATFORM: ${{ matrix.platforms }}
90+
# Buildx/qemu test need more time
91+
POSTGRES_TEST_TRIES: 42
92+
POSTGRES_TEST_SLEEP: 2
93+
94+
- name: "debug: docker images"
95+
run: docker images
96+
97+
- name: "debug: docker inspect postgis/postgis:${{ env.VERSION }}${{ env.TAG_POSTFIX }}"
98+
if: ${{ env.VARIANT == 'default' }}
99+
run: docker inspect postgis/postgis:${{ env.VERSION }}${{ env.TAG_POSTFIX }}
100+
101+
- name: "debug: docker inspect postgis/postgis:${{ env.VERSION }}-${{ env.VARIANT }}${{ env.TAG_POSTFIX }}"
102+
if: ${{ env.VARIANT == 'alpine' }}
103+
run: docker inspect postgis/postgis:${{ env.VERSION }}-${{ env.VARIANT }}${{ env.TAG_POSTFIX }}
104+
105+
- name: Login to dockerhub
106+
uses: docker/login-action@v1
107+
if: ${{ (github.ref == 'refs/heads/master') && (github.event_name != 'pull_request') }}
108+
with:
109+
username: ${{ secrets.DOCKERHUB_USERNAME }}
110+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
111+
112+
- name: Push docker image to dockerhub - ${{ matrix.platforms }}
113+
if: ${{ (github.ref == 'refs/heads/master') && (github.event_name != 'pull_request') }}
114+
env:
115+
# platform is important!
116+
DOCKER_DEFAULT_PLATFORM: ${{ matrix.platforms }}
117+
PLATFORM: ${{ matrix.platforms }}
118+
#
119+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
120+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
121+
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
122+
run: make push

Dockerfile.alpine.template

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,31 @@ RUN set -eux \
9090
&& make -j$(nproc) \
9191
&& make install \
9292
\
93+
# buildx platform check for debug.
94+
&& uname -a \
95+
&& uname -m \
96+
&& cat /proc/cpuinfo \
97+
\
9398
# regress check
9499
&& mkdir /tempdb \
95100
&& chown -R postgres:postgres /tempdb \
96101
&& su postgres -c 'pg_ctl -D /tempdb init' \
97-
&& su postgres -c 'pg_ctl -D /tempdb start' \
102+
\
103+
&& if [ "%%PG_MAJOR%%" == "10" ]; then \
104+
set -eux \
105+
# pg ==10 : testing with huge_pages=off ---> for the buildx/qemu workflow
106+
&& su postgres -c 'pg_ctl -o "--huge_pages=off" -D /tempdb start' \
107+
&& su postgres -c 'psql -c "SHOW HUGE_PAGES;"' \
108+
; \
109+
else \
110+
set -eux \
111+
# pg >=11 : testing with jit=off , huge_pages=off ---> for the buildx/qemu workflow
112+
&& su postgres -c 'pg_ctl -o "--huge_pages=off" -o "--jit=off" -D /tempdb start' \
113+
&& su postgres -c 'psql -c "SHOW HUGE_PAGES;"' \
114+
&& su postgres -c 'psql -c "SHOW JIT;"' \
115+
; \
116+
fi \
117+
\
98118
&& cd regress \
99119
&& make -j$(nproc) check RUNTESTFLAGS=--extension PGUSER=postgres \
100120
#&& make -j$(nproc) check RUNTESTFLAGS=--dumprestore PGUSER=postgres \

Dockerfile.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ ENV POSTGIS_MAJOR %%POSTGIS_MAJOR%%
66
ENV POSTGIS_VERSION %%POSTGIS_VERSION%%
77

88
RUN apt-get update \
9+
\
10+
# buildx debug info
11+
&& uname -a \
12+
&& uname -m \
13+
&& lscpu \
14+
\
915
&& apt-cache showpkg postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \
1016
&& apt-get install -y --no-install-recommends \
1117
# ca-certificates: for accessing remote raster files;

Makefile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ LATEST_VERSION=14-3.3
1111
do_default=true
1212
do_alpine=true
1313

14+
# There are multiple workflows in the .github/workflows/*
15+
# The default WORKFLOW is the main.yml ( amd64 ) but can be overriden via environment variables.
16+
17+
WORKFLOW ?= main
18+
TAG_POSTFIX=
19+
20+
# IF this is not the 'main' workflow THEN We add special image tag postfix. ( -experimental )
21+
ifneq ($(WORKFLOW),main)
22+
TAG_POSTFIX=-experimental
23+
endif
24+
1425
# The following logic evaluates VERSION and VARIANT variables that may have
1526
# been previously specified, and modifies the "do" flags depending on the values.
1627
# The VERSIONS variable is also set to contain the version(s) to be processed.
@@ -76,11 +87,11 @@ update:
7687
define build-version
7788
build-$1:
7889
ifeq ($(do_default),true)
79-
$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1) $1
90+
$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)$(TAG_POSTFIX) $1
8091
endif
8192
ifeq ($(do_alpine),true)
8293
ifneq ("$(wildcard $1/alpine)","")
83-
$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)-alpine $1/alpine
94+
$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)-alpine$(TAG_POSTFIX) $1/alpine
8495
endif
8596
endif
8697
endef
@@ -99,11 +110,11 @@ test: $(foreach version,$(VERSIONS),test-$(version))
99110
define test-version
100111
test-$1: test-prepare build-$1
101112
ifeq ($(do_default),true)
102-
$(OFFIMG_LOCAL_CLONE)/test/run.sh -c $(OFFIMG_LOCAL_CLONE)/test/config.sh -c test/postgis-config.sh $(REPO_NAME)/$(IMAGE_NAME):$(version)
113+
$(OFFIMG_LOCAL_CLONE)/test/run.sh -c $(OFFIMG_LOCAL_CLONE)/test/config.sh -c test/postgis-config.sh $(REPO_NAME)/$(IMAGE_NAME):$(version)$(TAG_POSTFIX)
103114
endif
104115
ifeq ($(do_alpine),true)
105116
ifneq ("$(wildcard $1/alpine)","")
106-
$(OFFIMG_LOCAL_CLONE)/test/run.sh -c $(OFFIMG_LOCAL_CLONE)/test/config.sh -c test/postgis-config.sh $(REPO_NAME)/$(IMAGE_NAME):$(version)-alpine
117+
$(OFFIMG_LOCAL_CLONE)/test/run.sh -c $(OFFIMG_LOCAL_CLONE)/test/config.sh -c test/postgis-config.sh $(REPO_NAME)/$(IMAGE_NAME):$(version)-alpine$(TAG_POSTFIX)
107118
endif
108119
endif
109120
endef
@@ -113,7 +124,7 @@ $(foreach version,$(VERSIONS),$(eval $(call test-version,$(version))))
113124
### RULES FOR TAGGING ###
114125

115126
tag-latest: $(BUILD_LATEST_DEP)
116-
$(DOCKER) image tag $(REPO_NAME)/$(IMAGE_NAME):$(LATEST_VERSION) $(REPO_NAME)/$(IMAGE_NAME):latest
127+
$(DOCKER) image tag $(REPO_NAME)/$(IMAGE_NAME):$(LATEST_VERSION) $(REPO_NAME)/$(IMAGE_NAME):latest$(TAG_POSTFIX)
117128

118129

119130
### RULES FOR PUSHING ###
@@ -123,24 +134,26 @@ push: $(foreach version,$(VERSIONS),push-$(version)) $(PUSH_DEP)
123134
define push-version
124135
push-$1: test-$1
125136
ifeq ($(do_default),true)
126-
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):$(version)
137+
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):$(version)$(TAG_POSTFIX)
127138
endif
128139
ifeq ($(do_alpine),true)
129140
ifneq ("$(wildcard $1/alpine)","")
130-
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):$(version)-alpine
141+
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):$(version)-alpine$(TAG_POSTFIX)
131142
endif
132143
endif
133144
endef
134145
$(foreach version,$(VERSIONS),$(eval $(call push-version,$(version))))
135146

136147
push-latest: tag-latest $(PUSH_LATEST_DEP)
137-
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):latest
138-
@$(DOCKER) run -v "$(PWD)":/workspace \
148+
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):latest$(TAG_POSTFIX)
149+
150+
ifeq ($(WORKFLOW),main)
151+
@$(DOCKER) run -v "$(PWD)":/workspace \
139152
-e DOCKERHUB_USERNAME='$(DOCKERHUB_USERNAME)' \
140153
-e DOCKERHUB_PASSWORD='$(DOCKERHUB_ACCESS_TOKEN)' \
141154
-e DOCKERHUB_REPOSITORY='$(REPO_NAME)/$(IMAGE_NAME)' \
142155
-e README_FILEPATH='/workspace/README.md' $(DOCKERHUB_DESC_IMG)
143-
156+
endif
144157

145158
.PHONY: build all update test-prepare test tag-latest push push-latest \
146159
$(foreach version,$(VERSIONS),build-$(version)) \

test/tests/postgis-basics/run.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ set -e
33

44
image="$1"
55

6+
# buildx debug:
7+
uname -a
8+
uname -m
9+
cat /proc/cpuinfo
10+
611
export POSTGRES_USER='my cool postgres user'
712
export POSTGRES_PASSWORD='my cool postgres password'
813
export POSTGRES_DB='my cool postgres database'
@@ -24,15 +29,18 @@ psql() {
2429
"$@"
2530
}
2631

27-
tries=10
32+
: ${POSTGRES_TEST_TRIES:=10}
33+
: ${POSTGRES_TEST_SLEEP:=2}
34+
35+
tries="$POSTGRES_TEST_TRIES"
2836
while ! echo 'SELECT 1' | psql &> /dev/null; do
2937
(( tries-- ))
3038
if [ $tries -le 0 ]; then
3139
echo >&2 'postgres failed to accept connections in a reasonable amount of time!'
3240
echo 'SELECT 1' | psql # to hopefully get a useful error message
3341
false
3442
fi
35-
sleep 2
43+
sleep "$POSTGRES_TEST_SLEEP"
3644
done
3745

3846
echo 'SELECT PostGIS_Version()' | psql

0 commit comments

Comments
 (0)