Merge pull request #1832 from GluuFederation/admin-ui-issue-1747 #1358
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish Releases to Hub | |
on: | |
schedule: | |
- cron: "0 23 * * *" | |
push: | |
tags: | |
- "*" | |
branches: | |
- main | |
paths: | |
- "docker-**/**" | |
- "!**.md" | |
workflow_dispatch: | |
inputs: | |
services: | |
description: 'One or set of the docker images. Format as following: "docker-admin-ui docker-flex-monolith docker-flex-all-in-one"' | |
required: true | |
default: 'docker-admin-ui docker-flex-monolith docker-flex-all-in-one' | |
gluu_version: | |
description: 'The war version to build the image off' | |
required: false | |
default: '' | |
image_tag: | |
description: 'The manual image tag to post' | |
required: false | |
default: '' | |
tags: | |
description: 'Tags' | |
required: false | |
permissions: | |
contents: read | |
jobs: | |
docker: | |
permissions: | |
packages: write | |
runs-on: ubuntu-latest | |
strategy: | |
max-parallel: 8 | |
matrix: | |
docker-images: ["admin-ui", "flex-monolith", "flex-all-in-one"] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
sparse-checkout: | | |
automation | |
docker-admin-ui | |
docker-flex-monolith | |
docker-flex-all-in-one | |
- name: Check docker directories that changed | |
id: build_docker_image | |
run: | | |
BUILD=true | |
DEFAULT_ALL=${{ github.event.inputs.services }} | |
if [ -z "$DEFAULT_ALL" ] | |
then | |
DEFAULT_ALL="docker-admin-ui docker-flex-monolith docker-flex-all-in-one" | |
else | |
echo "$DEFAULT_ALL" | |
fi | |
# Detect actual docker folders that changed if error arises default to all images | |
DIRECTORIES_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | cut -d/ -f1 | sort -u | grep "docker" || echo "$DEFAULT_ALL") | |
if [[ "$DIRECTORIES_CHANGED" =~ "${{ matrix.docker-images }}" ]]; then | |
echo "A change in this images directory has occured" | |
echo ::set-output name=build::${BUILD} | |
fi | |
- name: Install dependencies | |
if: steps.build_docker_image.outputs.build || github.event_name == 'tags' | |
run: | | |
sudo apt-get update | |
sudo python3 -m pip install --upgrade pip | |
sudo pip3 install setuptools --upgrade | |
sudo pip3 install -r ./automation/requirements.txt | |
sudo apt-get update | |
- name: Prepare | |
if: steps.build_docker_image.outputs.build || github.event_name == 'tags' | |
id: prep | |
run: | | |
REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | |
MAIN_VERSION=$(python3 -c "from dockerfile_parse import DockerfileParser ; dfparser = DockerfileParser('./docker-${{ matrix.docker-images }}') ; print(dfparser.labels['org.opencontainers.image.version'])") | |
DOCKER_IMAGE=ghcr.io/$REPOSITORY/${{ matrix.docker-images }} | |
VERSION=${MAIN_VERSION}_dev | |
if [[ ${{ matrix.docker-images }} == "flex-monolith" ]]; then | |
VERSION=5.1.6_dev | |
DOCKER_IMAGE=ghcr.io/$REPOSITORY/monolith | |
fi | |
BUILD=true | |
if [[ $GITHUB_REF == refs/tags/docker-${{ matrix.docker-images }}-* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/docker-${{ matrix.docker-images }}-v} | |
elif [[ $GITHUB_REF == refs/tags/* ]]; then | |
echo "A tag not matching the image triggered the build. I will not continue." | |
BUILD="" | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION}" | |
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\_[a-b]{1}[0-9]{1,3}$ ]]; then | |
TAGS="$TAGS,${DOCKER_IMAGE}:${MAIN_VERSION}_dev" | |
fi | |
# If the user passed a manual image tag to build a custom manual image | |
MANUAL_IMAGE_TAG=${{ github.event.inputs.image_tag }} | |
if [ ! -z "$MANUAL_IMAGE_TAG" ] | |
then | |
TAGS="$TAGS,${DOCKER_IMAGE}:${MANUAL_IMAGE_TAG}" | |
VERSION=$MANUAL_IMAGE_TAG | |
echo "Manual image tag has been inputted by the user" | |
else | |
echo "$TAGS" | |
fi | |
# If the user passed a war version to build off ,change this war version. | |
GLUU_VERSION=${{ github.event.inputs.gluu_version }} | |
if [ ! -z "$GLUU_VERSION" ] | |
then | |
python3 -c "from dockerfile_parse import DockerfileParser ; dfparser = DockerfileParser('./docker-${{ matrix.docker-images }}') ; dfparser.envs['CN_VERSION'] = '${{ github.event.inputs.gluu_version }}'" | |
echo "War version has been modified." | |
else | |
echo "$GLUU_VERSION" | |
fi | |
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
echo "build=${BUILD}" >> $GITHUB_OUTPUT | |
# wait for all images in DEFAULT_ALL to be built before building the all-in-one image as it depends on all other images | |
if [[ "flex-all-in-one" =~ "${{ matrix.docker-images }}" ]]; then | |
if [[ ${{ github.event_name != 'pull_request' }} ]]; then | |
TEMP_IMG="admin-ui" | |
for i in $TEMP_IMG; do | |
TEMP_TOKEN=$(curl https://ghcr.io/token\?scope\="repository:gluufederation/flex/$i:pull" | jq -r '.token') | |
while [[ $(curl -s -H "Authorization: Bearer ${TEMP_TOKEN}" https://ghcr.io/v2/gluufederation/flex/$i/tags/list | jq -r '.tags' | grep "$VERSION" | tr -d '[:space:]"') != "$VERSION" ]]; do | |
echo "Waiting for $i to be built" | |
sleep 30 | |
done | |
done | |
fi | |
fi | |
# UPDATE BUILD DATES INSIDE THE DOCKERFILE BEFORE BUILDING THE DEV IMAGES TRIGGERED BY JENKINS | |
- name: Setup Python 3.7 | |
if: github.event_name == 'workflow_dispatch' | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.7 | |
- name: Install Python dependencies | |
if: github.event_name == 'workflow_dispatch' | |
run: | | |
sudo apt-get update | |
sudo python3 -m pip install --upgrade pip | |
sudo pip3 install setuptools --upgrade | |
sudo pip3 install -r ./automation/requirements.txt | |
sudo apt-get update | |
sudo apt-get install jq | |
- name: Update Build date in Dockerfile | |
if: github.event_name == 'workflow_dispatch' | |
id: update_build_date_in_dockerfile | |
run: | | |
sudo python3 ./automation/auto_update_image_pr.py | |
#END UPDATE BUILD DATES INSIDE THE DOCKERFILE BEFORE BUILDING THE DEV IMAGES TRIGGERED BY JENKINS | |
- name: Set up QEMU | |
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build | |
uses: docker/setup-qemu-action@master | |
with: | |
image: tonistiigi/binfmt:master | |
platforms: all | |
- name: Set up Docker Buildx | |
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to ghcr | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: ./docker-${{ matrix.docker-images }} | |
file: ./docker-${{ matrix.docker-images }}/Dockerfile | |
#target: prod | |
# add to platforms comma seperated linux/ppc64leL Issue: py3-grpcio | |
# add to platforms comma seperated linux/386 : Issue: openjdk11-jre-headless alpine package not | |
# add to platforms comma seperated ,linux/arm/v6 : Issue: openjdk11-jre-headless alpine package not found | |
# add to platforms comma seperated ,linux/arm/v7 : Issue: openjdk11-jre-headless alpine package not found | |
# add to platforms comma seperated ,linux/s390x: All images with openjdk hav an issue with linux/s390x Problematic frame: J 6 c1 java.lang.String.hashCode()I [email protected] (49 bytes) : Issue: openjdk11-jre-headles | |
# add to platforms comma seperated ,linux/arm64: : PyDev issue only | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.prep.outputs.tags }} | |
- name: Image digest | |
if: steps.build_docker_image.outputs.build && steps.prep.outputs.build | |
run: echo ${{ steps.docker_build.outputs.digest }} |