Skip to content

Push Docker Images on New Release #1377

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

Closed
71 changes: 71 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish Docker image

on:
release:
types: [published]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it means that we will push Docker images when release is created on GitHub. That's not required from an Apache standpoint, but good enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's exactly the trigger ?

Continuing this comment as well, you got it correct. I've put the trigger on the GitHub release - this is due to my inexperience with the Apache release process. Is there a better trigger for this potentially?


jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should checkout on the release tag here, not on main.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the official documentation for actions/checkout, this step will check out the exact SHA that triggered the event. So it will be the release tag.

ref: https://github.com/actions/checkout?tab=readme-ov-file#usage


- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a #v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker Image build
run: |
./gradlew \
:polaris-quarkus-server:assemble \
:polaris-quarkus-server:quarkusAppPartsBuild --rerun \
:polaris-quarkus-admin:assemble \
:polaris-quarkus-admin:quarkusAppPartsBuild --rerun \
-Dquarkus.container-image.build=true \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: it's possible to push directly in this step using quarkus.container-image.push=true.

-PeclipseLinkDeps=org.postgresql:postgresql:42.7.4

- name: List all Docker images
run: docker images

- name: Push Docker image to Docker Hub
run: |
docker push apache/polaris
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should push with the image tag (in addition of latest). Basically:

docker push apache/polaris:{version}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub metadata that generates the version is a bit wonky and requires some parsing. But I know that when we build the Docker images using ./gradlew, it creates tags for both the version and latest. Do you think it is okay to push them all using the docker push apache/polaris --all-tags?

ref: https://github.com/adnanhemani/polaris/actions/runs/14486887998/job/40634198664#step:7:20