Skip to content

Commit 7ba55bf

Browse files
committed
feat: refactor to build docker images from major versions
skip if no Dockerfile exists
1 parent c37f69b commit 7ba55bf

File tree

6 files changed

+175
-126
lines changed

6 files changed

+175
-126
lines changed

.github/workflows/dockerhub-release-15-6.yml

Lines changed: 0 additions & 104 deletions
This file was deleted.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: Release all major versions on Dockerhub
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- release/*
8+
- sam/docker-oriole17
9+
paths:
10+
- ".github/workflows/dockerhub-release-matrix.yml"
11+
- "anisble/vars.yml"
12+
workflow_dispatch:
13+
14+
jobs:
15+
prepare:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
matrix_config: ${{ steps.set-matrix.outputs.matrix_config }}
19+
steps:
20+
- name: Checkout Repo
21+
uses: actions/checkout@v3
22+
23+
- uses: DeterminateSystems/nix-installer-action@main
24+
25+
- name: Generate build matrix
26+
id: set-matrix
27+
run: |
28+
# Get all postgres versions from vars.yml
29+
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml)
30+
31+
# Check which versions have corresponding Dockerfiles and create matrix config
32+
MATRIX_CONFIG="{"
33+
MATRIX_CONFIG+="\"include\":["
34+
FIRST=true
35+
36+
while IFS= read -r version; do
37+
# Remove quotes from version
38+
version=$(echo "$version" | tr -d '"')
39+
40+
# Determine dockerfile name based on version
41+
if [[ "$version" == "orioledb-"* ]]; then
42+
dockerfile="Dockerfile-${version#orioledb-}-orioledb"
43+
else
44+
dockerfile="Dockerfile-${version}"
45+
fi
46+
47+
# Check if Dockerfile exists
48+
if [ -f "$dockerfile" ]; then
49+
if [ "$FIRST" = true ]; then
50+
FIRST=false
51+
else
52+
MATRIX_CONFIG+=","
53+
fi
54+
MATRIX_CONFIG+="{\"version\":\"$version\",\"dockerfile\":\"$dockerfile\"}"
55+
fi
56+
done <<< "$VERSIONS"
57+
58+
MATRIX_CONFIG+="]}"
59+
60+
# Output the matrix configuration
61+
echo "matrix_config=$MATRIX_CONFIG" >> $GITHUB_OUTPUT
62+
63+
build:
64+
needs: prepare
65+
strategy:
66+
matrix: ${{ fromJson(needs.prepare.outputs.matrix_config) }}
67+
runs-on: ubuntu-latest
68+
outputs:
69+
image_tag: supabase/postgres:${{ steps.settings.outputs.postgres-version }}
70+
build_args: ${{ steps.args.outputs.result }}
71+
steps:
72+
- uses: actions/checkout@v3
73+
- id: settings
74+
run: sed -r 's/(\s|\")+//g' common-nix.vars.pkr.hcl >> $GITHUB_OUTPUT
75+
- id: args
76+
uses: mikefarah/yq@master
77+
with:
78+
cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'
79+
80+
build_release_image:
81+
needs: [build]
82+
strategy:
83+
matrix:
84+
include:
85+
- runner: [self-hosted, X64]
86+
arch: amd64
87+
- runner: arm-runner
88+
arch: arm64
89+
runs-on: ${{ matrix.runner }}
90+
timeout-minutes: 180
91+
outputs:
92+
image_digest: ${{ steps.build.outputs.digest }}
93+
steps:
94+
- run: docker context create builders
95+
- uses: docker/setup-buildx-action@v3
96+
with:
97+
endpoint: builders
98+
- uses: docker/login-action@v2
99+
with:
100+
username: ${{ secrets.DOCKER_USERNAME }}
101+
password: ${{ secrets.DOCKER_PASSWORD }}
102+
- id: build
103+
uses: docker/build-push-action@v5
104+
with:
105+
push: true
106+
build-args: |
107+
${{ needs.build.outputs.build_args }}
108+
target: production
109+
tags: ${{ needs.build.outputs.image_tag }}_${{ matrix.arch }}
110+
platforms: linux/${{ matrix.arch }}
111+
cache-from: type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
112+
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
113+
file: ${{ matrix.dockerfile }}
114+
- name: Slack Notification
115+
if: ${{ failure() }}
116+
uses: rtCamp/action-slack-notify@v2
117+
env:
118+
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
119+
SLACK_USERNAME: "gha-failures-notifier"
120+
SLACK_COLOR: "danger"
121+
SLACK_MESSAGE: "Building Postgres ${{ matrix.arch }} image failed for version ${{ matrix.version }}"
122+
SLACK_FOOTER: ""
123+
124+
merge_manifest:
125+
needs: [build, build_release_image]
126+
runs-on: ubuntu-latest
127+
steps:
128+
- uses: docker/setup-buildx-action@v3
129+
- uses: docker/login-action@v2
130+
with:
131+
username: ${{ secrets.DOCKER_USERNAME }}
132+
password: ${{ secrets.DOCKER_PASSWORD }}
133+
- name: Merge multi-arch manifests
134+
run: |
135+
docker buildx imagetools create -t ${{ needs.build.outputs.image_tag }} \
136+
${{ needs.build.outputs.image_tag }}_amd64 \
137+
${{ needs.build.outputs.image_tag }}_arm64
138+
- name: Slack Notification
139+
if: ${{ failure() }}
140+
uses: rtCamp/action-slack-notify@v2
141+
env:
142+
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
143+
SLACK_USERNAME: "gha-failures-notifier"
144+
SLACK_COLOR: "danger"
145+
SLACK_MESSAGE: "Building Postgres image failed for version ${{ matrix.version }}"
146+
SLACK_FOOTER: ""
147+
148+
publish:
149+
needs: [build, merge_manifest]
150+
uses: ./.github/workflows/mirror.yml
151+
with:
152+
version: ${{ needs.build.outputs.docker_version }}
153+
secrets: inherit

Dockerfile-15

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,14 @@ ARG wal_g_release=2.0.1
4141

4242
FROM ubuntu:focal as base
4343

44-
45-
ENV DEBIAN_FRONTEND=noninteractive \
46-
DEBCONF_NONINTERACTIVE_SEEN=true \
47-
TZ=Etc/UTC
48-
49-
# Pre-configure tzdata before any installations
50-
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
51-
echo $TZ > /etc/timezone && \
52-
apt-get update && \
53-
apt-get install -y --no-install-recommends tzdata && \
54-
apt-get install -y \
44+
RUN apt update -y && apt install -y \
5545
curl \
5646
gnupg \
5747
lsb-release \
5848
software-properties-common \
5949
wget \
6050
sudo \
61-
git \
62-
&& apt clean && \
63-
rm -rf /var/lib/apt/lists/*
51+
&& apt clean
6452

6553

6654
RUN adduser --system --home /var/lib/postgresql --no-create-home --shell /bin/bash --group --gecos "PostgreSQL administrator" postgres
@@ -114,6 +102,12 @@ RUN chown -R postgres:postgres /usr/lib/postgresql
114102
RUN ln -sf /usr/lib/postgresql/share/postgresql/timezonesets /usr/share/postgresql/timezonesets
115103

116104

105+
RUN apt-get update && \
106+
apt-get install -y --no-install-recommends tzdata
107+
108+
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
109+
dpkg-reconfigure --frontend noninteractive tzdata
110+
117111
RUN apt-get update && \
118112
apt-get install -y --no-install-recommends \
119113
build-essential \
File renamed without changes.

Dockerfile-156 renamed to deprecated-Dockerfile-15-prev

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,26 @@ ARG wal_g_release=2.0.1
4141

4242
FROM ubuntu:focal as base
4343

44-
RUN apt update -y && apt install -y \
44+
45+
ENV DEBIAN_FRONTEND=noninteractive \
46+
DEBCONF_NONINTERACTIVE_SEEN=true \
47+
TZ=Etc/UTC
48+
49+
# Pre-configure tzdata before any installations
50+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
51+
echo $TZ > /etc/timezone && \
52+
apt-get update && \
53+
apt-get install -y --no-install-recommends tzdata && \
54+
apt-get install -y \
4555
curl \
4656
gnupg \
4757
lsb-release \
4858
software-properties-common \
4959
wget \
5060
sudo \
51-
&& apt clean
61+
git \
62+
&& apt clean && \
63+
rm -rf /var/lib/apt/lists/*
5264

5365

5466
RUN adduser --system --home /var/lib/postgresql --no-create-home --shell /bin/bash --group --gecos "PostgreSQL administrator" postgres
@@ -102,12 +114,6 @@ RUN chown -R postgres:postgres /usr/lib/postgresql
102114
RUN ln -sf /usr/lib/postgresql/share/postgresql/timezonesets /usr/share/postgresql/timezonesets
103115

104116

105-
RUN apt-get update && \
106-
apt-get install -y --no-install-recommends tzdata
107-
108-
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
109-
dpkg-reconfigure --frontend noninteractive tzdata
110-
111117
RUN apt-get update && \
112118
apt-get install -y --no-install-recommends \
113119
build-essential \
File renamed without changes.

0 commit comments

Comments
 (0)