From 5f24a2746e20bda7cfe77ccae498d18a3ef813f5 Mon Sep 17 00:00:00 2001 From: Mohammed Irfan Date: Fri, 28 Jun 2024 10:45:30 +0100 Subject: [PATCH] replace dockerhub hooks with github actions --- .github/workflows/build.yml | 112 ++++++++++++++++++++++++++++++++++++ hooks/build | 57 ------------------ hooks/push | 23 -------- hooks/test | 11 ---- 4 files changed, 112 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 hooks/build delete mode 100644 hooks/push delete mode 100755 hooks/test diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..343a49f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,112 @@ +name: Docker Image CI + +on: + push: + branches: [ "main", '[0-9]+\.[0-9]+\.[0-9]+', '[0-9]+\.[0-9]+\.[x]' ] + +env: + DOCKER_REPO: ${{ vars.DOCKER_REPO }} + +jobs: + build_image: + runs-on: ubuntu-latest + steps: + - name: Validate build conditions + env: + NIGHTLY_MASTER_VERSION: ${{ vars.NIGHTLY_MASTER_VERSION }} + NIGHTLY_STABLE_VERSION: ${{ vars.NIGHTLY_STABLE_VERSION }} + NIGHTLY_MAINT_VERSION: ${{ vars.NIGHTLY_MAINT_VERSION }} + STABLE_VERSION: ${{ vars.STABLE_VERSION }} + MAINT_VERSION: ${{ vars.MAINT_VERSION }} + run: | + buildable_status=1 + versions=("$NIGHTLY_MASTER_VERSION" "$NIGHTLY_STABLE_VERSION" "$NIGHTLY_MAINT_VERSION" "$STABLE_VERSION" "$MAINT_VERSION") + # We will proceed with the build only if the branch name is valid and supported by our repo-level vars. + for version in "${versions[@]}"; do + for single_version in $version; do + if [[ "$GITHUB_REF_NAME" == "$single_version" ]]; then + # Valid version + buildable_status=0 + break; + fi + done + done + exit $buildable_status + + - name: Initialise the cache for the plugin dependencies + id: plugincache + uses: actions/cache@v4 + with: + path: ./resources/geoserver-plugins/ + key: ${{ runner.os }}-build-${{ github.ref_name }} + + - name: Download the dependencies (plugins) + if: steps.plugincache.outputs.cache-hit != 'true' + env: + PLUG_IN_LIST: "monitor control-flow libjpeg-turbo" + run: | + for version in $NIGHTLY_MASTER_VERSION; do + if [[ "$GITHUB_REF_NAME" == $version ]]; then + PLUG_IN_VERSION="2.$(expr $MIDDLE_STABLE + 1)-SNAPSHOT" + break + fi + done + if [ -z $PLUG_IN_VERSION ]; then + for version in $NIGHTLY_STABLE_VERSION; do + if [[ "$GITHUB_REF_NAME" == $version ]]; then + PLUG_IN_VERSION="2.$MIDDLE_STABLE-SNAPSHOT" + break + fi + done + fi + if [ -z $PLUG_IN_VERSION ]; then + for version in $NIGHTLY_MAINT_VERSION; do + if [[ "$GITHUB_REF_NAME" == $version ]]; then + PLUG_IN_VERSION="2.$(expr $MIDDLE_STABLE - 1)-SNAPSHOT" + break + fi + done + fi + + if [ -z $PLUG_IN_VERSION ]; then + for version in $STABLE_VERSION $MAINT_VERSION; do + if [[ "$GITHUB_REF_NAME" == $version ]]; then + PLUG_IN_VERSION="$version" + break + fi + done + fi + + mkdir -p ./resources/geoserver-plugins + for PLUG_IN_NAME in $PLUG_IN_LIST; do + URL="https://build.geoserver.org/geoserver/$GITHUB_REF_NAME/ext-latest/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip" + curl -C - -k -o ./resources/geoserver-plugins/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip $URL + done + + - uses: actions/checkout@v4 + - name: Build the geoserver image + run: | + WAR_FILE="https://build.geoserver.org/geoserver/$GITHUB_REF_NAME/geoserver-$GITHUB_REF_NAME-latest-war.zip" + docker build \ + --build-arg GEOSERVER_WEBAPP_SRC="$WAR_FILE" \ + --build-arg PLUG_IN_PATHS="./resources/geoserver-plugins" \ + -f "$DOCKERFILE_PATH" \ + -t "${DOCKER_REPO}:$GITHUB_REF_NAME" . + rm -rf ./resources/geoserver-plugins/* + + - name: Login to docker hub + uses: docker/login-action@v3.2.0 + with: + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Push docker image + run: docker push "${DOCKER_REPO}:$GITHUB_REF_NAME" + + test: + runs-on: ubuntu-latest + needs: build_image + timeout-minutes: 10 + steps: + - name: Run the tests + run: docker run --rm -i "${DOCKER_REPO}:$GITHUB_REF_NAME" /docker/tests/run_tests.sh \ No newline at end of file diff --git a/hooks/build b/hooks/build deleted file mode 100644 index d61ca09..0000000 --- a/hooks/build +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -x - -PLUG_IN_LIST="monitor control-flow libjpeg-turbo" -NIGHTLY_MASTER_PLUG_IN_VERSION="2.$(expr $MIDDLE_STABLE + 1)-SNAPSHOT" -NIGHTLY_STABLE_PLUG_IN_VERSION="2.$MIDDLE_STABLE-SNAPSHOT" -NIGHTLY_MAINT_PLUG_IN_VERSION="2.$(expr $MIDDLE_STABLE - 1)-SNAPSHOT" -echo $NIGHTLY_MASTER_PLUG_IN_VERSION -echo $NIGHTLY_STABLE_PLUG_IN_VERSION -echo $NIGHTLY_MAINT_PLUG_IN_VERSION -for NIGHTLY_VERSION in $NIGHTLY_MASTER_VERSION $NIGHTLY_STABLE_VERSION $NIGHTLY_MAINT_VERSION; do - NIGHTLY_URL="https://build.geoserver.org/geoserver/$NIGHTLY_VERSION/geoserver-$NIGHTLY_VERSION-latest-war.zip" - [[ "$NIGHTLY_MASTER_VERSION" == *"$NIGHTLY_VERSION"* ]] && PLUG_IN_VERSION="$NIGHTLY_MASTER_PLUG_IN_VERSION" - [[ "$NIGHTLY_STABLE_VERSION" == *"$NIGHTLY_VERSION"* ]] && PLUG_IN_VERSION="$NIGHTLY_STABLE_PLUG_IN_VERSION" - [[ "$NIGHTLY_MAINT_VERSION" == *"$NIGHTLY_VERSION"* ]] && PLUG_IN_VERSION="$NIGHTLY_MAINT_PLUG_IN_VERSION" - echo $PLUG_IN_VERSION - #PLUG_IN_URLS=() - mkdir -p ./resources/geoserver-plugins - for PLUG_IN_NAME in $PLUG_IN_LIST; do - echo $PLUG_IN_NAME - echo $PLUG_IN_VERSION - URL="https://build.geoserver.org/geoserver/$NIGHTLY_VERSION/ext-latest/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip" - #wget $URL -O ./resources/geoserver-plugins/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip - curl -k -o ./resources/geoserver-plugins/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip $URL - #echo "Plugin $PLUG_IN_NAME URL for version $PLUG_IN_VERSION: $URL" - #PLUG_IN_URLS+=($URL) - done - var=$(IFS=$' '; echo "${PLUG_IN_URLS[*]}" ) - docker build \ - --build-arg GEOSERVER_WEBAPP_SRC="$NIGHTLY_URL" \ - --build-arg PLUG_IN_PATHS="./resources/geoserver-plugins" \ - -f "$DOCKERFILE_PATH" \ - -t "${DOCKER_REPO}:$NIGHTLY_VERSION" . - rm -rf ./resources/geoserver-plugins/* -done - -for VERSION in $STABLE_VERSION $MAINT_VERSION; do - GEOSERVER_URL="https://sourceforge.net/projects/geoserver/files/GeoServer/$VERSION/geoserver-$VERSION-war.zip/download" - #PLUG_IN_URLS=() - mkdir -p ./resources/geoserver-plugins - for PLUG_IN_NAME in $PLUG_IN_LIST; do - echo $PLUG_IN_NAME - echo $VERSION - mkdir -p ./resources/geoserver-plugins - URL="https://sourceforge.net/projects/geoserver/files/GeoServer/$VERSION/extensions/geoserver-$VERSION-$PLUG_IN_NAME-plugin.zip/download" - #wget $URL -O ./resources/geoserver-plugins/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip - curl -k -o ./resources/geoserver-plugins/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip $URL - #echo "Plugin $PLUG_IN_NAME URL for version $PLUG_IN_VERSION: $URL" - #PLUG_IN_URLS+=($URL) - done - var=$(IFS=$'\ '; echo "${PLUG_IN_URLS[*]}" ) - docker build \ - --build-arg GEOSERVER_WEBAPP_SRC="$GEOSERVER_URL" \ - --build-arg PLUG_IN_PATHS="./resources/geoserver-plugins" \ - -f "$DOCKERFILE_PATH" \ - -t "${DOCKER_REPO}:$VERSION" . - rm -rf ./resources/geoserver-plugins/* -done diff --git a/hooks/push b/hooks/push deleted file mode 100644 index 0472d39..0000000 --- a/hooks/push +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -touch /tmp/failed_versions - -for NIGHTLY_VERSION in $NIGHTLY_MASTER_VERSION $NIGHTLY_STABLE_VERSION $NIGHTLY_MAINT_VERSION; do - if [ "$(grep $NIGHTLY_VERSION /tmp/failed_versions)" == "" ]; then - docker push "${DOCKER_REPO}:$NIGHTLY_VERSION" - fi -done - -for VERSION in $STABLE_VERSION $MAINT_VERSION; do - if [ "$(grep $VERSION /tmp/failed_versions)" == "" ]; then - docker push "${DOCKER_REPO}:$VERSION" - fi -done - -if [ "$(grep $NEWEST_VERSION /tmp/failed_versions)" == "" ]; then - docker pull "${DOCKER_REPO}:$NEWEST_VERSION" || exit 1 - docker tag "${DOCKER_REPO}:$NEWEST_VERSION" ${DOCKER_REPO}:latest - docker push "${DOCKER_REPO}:latest" -fi - -echo "List of versions with problems not uploaded: \n $(cat /tmp/failed_versions)" diff --git a/hooks/test b/hooks/test deleted file mode 100755 index 60add2f..0000000 --- a/hooks/test +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -for NIGHTLY_VERSION in $NIGHTLY_MASTER_VERSION $NIGHTLY_STABLE_VERSION $NIGHTLY_MAINT_VERSION; do - export VERSION=$NIGHTLY_VERSION - timeout 10m docker-compose -f docker-compose.test.yml run --rm sut || ( echo "test for docker image geoserver:$VERSION failed" && echo $VERSION >> /tmp/failed_versions ) -done - -for VERSION in $STABLE_VERSION $MAINT_VERSION; do - #export VERSION=$VERSION - timeout 10m docker-compose -f docker-compose.test.yml run --rm sut || ( echo "test for docker image geoserver:$VERSION failed" && echo $VERSION >> /tmp/failed_versions ) -done