Skip to content

ci: move the container build process to bake #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions .github/workflows/build-commitfest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ on:
inputs:
patch_id:
description: "ID of the Patch"
required: false
required: true
major_version:
description: "PostgreSQL major version (leave empty for default)"
required: false

# set up environment variables to be used across all the jobs
env:
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"
BRANCH: "master"

defaults:
run:
# default failure handling for shell scripts in 'run' steps
Expand All @@ -28,7 +23,7 @@ jobs:
contents: read
packages: write
outputs:
pg_image: "${{ env.REGISTRY }}:${{ env.TAG }}"
images: ${{ env.IMAGES }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -47,10 +42,9 @@ jobs:
fi

- name: Set commitfest branch and tag
if: github.event.inputs.patch_id != ''
run: |
BRANCH="cf/${{ github.event.inputs.patch_id }}"
TAG="${{ env.PG_MAJOR }}-${BRANCH////-}"
TAG="${BRANCH////-}"
echo "TAG=${TAG}" >> $GITHUB_ENV
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV

Expand All @@ -61,17 +55,36 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
uses: docker/bake-action@v6
id: build
env:
environment: production
registry: ghcr.io/${{ github.repository_owner }}
revision: ${{ github.sha }}
pgMajor: ${{ env.PG_MAJOR }}
with:
context: .
set: |
*.args.PG_REPO=https://github.com/postgresql-cfbot/postgresql.git
*.args.PG_BRANCH=${{ env.BRANCH }}
minimal.tags=${{ env.registry }}/postgresql-trunk:18-minimal-${{ env.TAG }}
standard.tags=${{ env.registry }}/postgresql-trunk:18-standard-${{ env.TAG }}
postgis.tags=${{ env.registry }}/postgresql-trunk:18-postgis-${{ env.TAG }}
push: true
load: false
tags: |
${{ env.REGISTRY }}:${{ env.TAG }}
build-args: |
PG_REPO=https://github.com/postgresql-cfbot/postgresql.git
PG_BRANCH=${{ env.BRANCH }}

# Get a list of the images that were built and pushed.
- name: Generated images
id: images
run: |
IMAGES="$(echo '${{ steps.build.outputs.metadata }}' | jq -r '.[]."image.name"')"
{
echo 'IMAGES<<EOF'
echo "${IMAGES}"
echo EOF
} >> $GITHUB_ENV

generate-summary:
name: Commitfest Image Build summary
Expand All @@ -83,11 +96,15 @@ jobs:
run: |
commitFestPatchID=${{ github.event.inputs.patch_id }}
commitFestURL="https://commitfest.postgresql.org/patch/${commitFestPatchID}"
image="${{ needs.build-pg.outputs.pg_image }}"
imageURL="https://${image}"
images="${{ needs.build-pg.outputs.images }}"
images_list="$(echo $images | tr ' ' '\n' | sed 's/^/https:\/\//')"
standardImage="$(echo $images | tr ' ' '\n' | grep standard)"

echo "# Commitfest Image Build summary" >> $GITHUB_STEP_SUMMARY
echo "**Commitfest Patch URL**: [$commitFestPatchID]($commitFestURL)" >> $GITHUB_STEP_SUMMARY
echo "**Container Image**: [$image]($imageURL)" >> $GITHUB_STEP_SUMMARY
echo "Here's the list of Container Images that have been built:" >> $GITHUB_STEP_SUMMARY
echo "$images_list" >> $GITHUB_STEP_SUMMARY

echo "## CloudNativePG Cluster definition" >> $GITHUB_STEP_SUMMARY
echo "You can create a cluster in CloudNativePG running this image:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
Expand All @@ -97,7 +114,7 @@ jobs:
echo "metadata:" >> $GITHUB_STEP_SUMMARY
echo " name: commitfest-$commitFestPatchID" >> $GITHUB_STEP_SUMMARY
echo "spec:" >> $GITHUB_STEP_SUMMARY
echo " imageName: $image" >> $GITHUB_STEP_SUMMARY
echo " imageName: $standardImage" >> $GITHUB_STEP_SUMMARY
echo " instances: 3" >> $GITHUB_STEP_SUMMARY
echo " storage:" >> $GITHUB_STEP_SUMMARY
echo " size: 1Gi" >> $GITHUB_STEP_SUMMARY
Expand Down
70 changes: 38 additions & 32 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ on:
major_version:
description: "PostgreSQL major version (leave empty for default)"
required: false
extra_tag:
description: "Optional extra tag (make sure it starts with the PG major)"
required: false

# set up environment variables to be used across all the jobs
env:
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"

defaults:
run:
Expand All @@ -35,7 +28,8 @@ jobs:
contents: read
packages: write
outputs:
pg_image: ${{ env.TAG }}
images: ${{ env.IMAGES }}
pg_major: ${{ env.PG_MAJOR }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -53,35 +47,43 @@ jobs:
echo "PG_MAJOR=${{ github.event.inputs.major_version }}" >> $GITHUB_ENV
fi

- name: Set tag and optional extra tag
run: |
TAG="${{ env.REGISTRY }}:${{ env.PG_MAJOR }}-build-${{ github.run_number }}"
EXTRA_TAG=""
if [[ "${{ github.event.inputs.extra_tag }}" != "" ]]; then
EXTRA_TAG="${{ env.REGISTRY }}:${{ github.event.inputs.extra_tag }}"
fi
echo "TAG=${TAG}" >> $GITHUB_ENV
echo "EXTRA_TAG=${EXTRA_TAG}" >> $GITHUB_ENV

- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
uses: docker/bake-action@v6
id: build
env:
environment: production
registry: ghcr.io/${{ github.repository_owner }}
revision: ${{ github.sha }}
pgMajor: ${{ env.PG_MAJOR }}
with:
context: .
set: |
*.args.PG_REPO=${{ github.event.inputs.pg_repo }}
*.args.PG_BRANCH=${{ github.event.inputs.pg_branch }}
minimal.tags=${{ env.registry }}/postgresql-trunk:18-minimal-${{ github.run_number }}
standard.tags=${{ env.registry }}/postgresql-trunk:18-standard-${{ github.run_number }}
postgis.tags=${{ env.registry }}/postgresql-trunk:18-postgis-${{ github.run_number }}
push: true
load: false
tags: |
${{ env.TAG }}
${{ env.EXTRA_TAG }}
build-args: |
PG_REPO=${{ github.event.inputs.pg_repo }}
PG_BRANCH=${{ github.event.inputs.pg_branch }}

# Get a list of the images that were built and pushed.
- name: Generated images
id: images
run: |
IMAGES="$(echo '${{ steps.build.outputs.metadata }}' | jq -r '.[]."image.name"')"
{
echo 'IMAGES<<EOF'
echo "${IMAGES}"
echo EOF
} >> $GITHUB_ENV

generate-summary:
name: PostgreSQL Image Build summary
Expand All @@ -92,11 +94,15 @@ jobs:
- name: Output summary
run: |
pg_major="${{ needs.build-pg.outputs.pg_major }}"
image="${{ needs.build-pg.outputs.pg_image }}"
imageURL="https://${image}"
images="${{ needs.build-pg.outputs.images }}"
images_list="$(echo $images | tr ' ' '\n' | sed 's/^/https:\/\//')"
standardImage="$(echo $images | tr ' ' '\n' | grep standard)"

echo "# PostgreSQL Image Build summary" >> $GITHUB_STEP_SUMMARY
echo "**Container Image**: [$image]($imageURL)" >> $GITHUB_STEP_SUMMARY
echo "## CloudNativePG Cluster definition" >> $GITHUB_STEP_SUMMARY
echo "Here's the list of Container Images that have been built:" >> $GITHUB_STEP_SUMMARY
echo "$images_list" >> $GITHUB_STEP_SUMMARY

echo "## CloudNativePG Cluster definition (example using the standard image)" >> $GITHUB_STEP_SUMMARY
echo "You can create a cluster in CloudNativePG running this image:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`sh" >> $GITHUB_STEP_SUMMARY
echo "(cat <<EOF" >> $GITHUB_STEP_SUMMARY
Expand All @@ -105,7 +111,7 @@ jobs:
echo "metadata:" >> $GITHUB_STEP_SUMMARY
echo " name: pg-$pg_major-build" >> $GITHUB_STEP_SUMMARY
echo "spec:" >> $GITHUB_STEP_SUMMARY
echo " imageName: $image" >> $GITHUB_STEP_SUMMARY
echo " imageName: $standardImage" >> $GITHUB_STEP_SUMMARY
echo " instances: 3" >> $GITHUB_STEP_SUMMARY
echo " storage:" >> $GITHUB_STEP_SUMMARY
echo " size: 1Gi" >> $GITHUB_STEP_SUMMARY
Expand Down
34 changes: 18 additions & 16 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ on:
schedule:
- cron: '0 1 * * *'

# set up environment variables to be used across all the jobs
env:
REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"

defaults:
run:
# default failure handling for shell scripts in 'run' steps
Expand All @@ -31,7 +27,7 @@ jobs:
contents: read
packages: write
outputs:
pg_image: ${{ env.TAG }}
pg_image: ${{ env.PG_IMAGE }}
pg_major: ${{ env.PG_MAJOR }}
cnpg_branch: ${{ env.CNPG_BRANCH }}
test_depth: ${{ env.TEST_DEPTH }}
Expand Down Expand Up @@ -59,26 +55,32 @@ jobs:
echo "FEATURE_TYPE=${{ github.event.inputs.feature_type }}" >> $GITHUB_ENV
fi

- name: Set tag
run: |
postgres_img="${{ env.REGISTRY }}:${{ env.PG_MAJOR }}-devel"
echo "TAG=${postgres_img}" >> $GITHUB_ENV

- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and load
uses: docker/build-push-action@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/bake-action@v6
id: build
env:
environment: production
registry: ghcr.io/${{ github.repository_owner }}
revision: ${{ github.sha }}
pgMajor: ${{ env.PG_MAJOR }}
with:
context: .
push: true
load: false
tags: |
${{ env.TAG }}

# Get a list of the images that were built and pushed. We only care about a single tag for each image.
- name: Generated images
id: images
run: |
echo "PG_IMAGE=$(echo '${{ steps.build.outputs.metadata }}' | jq -r '.["standard"].["image.name"]' | grep -oP '[^,]*\d{12}[^,]*')" >> $GITHUB_ENV

call-reusable-e2e:
if: github.event_name == 'schedule'
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/reusable-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
POSTGRES_VERSION: ${{ inputs.major_version }}
POSTGRES_IMG: ${{ inputs.postgres_img }}
POSTGRES_KIND: "PostgreSQL"
MAJOR_UPGRADE_IMAGE_REGISTRY: "ghcr.io/${{ github.repository_owner }}/postgresql-trunk"

DOCKER_SERVER: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
Expand Down Expand Up @@ -127,6 +128,11 @@ jobs:
docker push $E2E_PRE_ROLLING_UPDATE_IMG
echo "E2E_PRE_ROLLING_UPDATE_IMG=$E2E_PRE_ROLLING_UPDATE_IMG" >> $GITHUB_ENV

- name: Setting up default versions
run: |
# Update pkg/versions/versions.go
sed -i '/DefaultImageName *=/s@".*"@"'"${{ inputs.postgres_img }}"'"@' pkg/versions/versions.go

- name: Run Kind End-to-End tests
run: make e2e-test-kind

Expand Down
Loading
Loading