diff --git a/.github/workflows/axosyslog-docker.yml b/.github/workflows/axosyslog-docker.yml index 1e8008c7c..9af291d3b 100644 --- a/.github/workflows/axosyslog-docker.yml +++ b/.github/workflows/axosyslog-docker.yml @@ -138,6 +138,8 @@ jobs: merge-and-push: runs-on: ubuntu-latest needs: [prepare, image-build] + outputs: + tags: ${{ steps.docker-metadata-tags.outputs.tags }} steps: - name: Download digests uses: actions/download-artifact@v4 @@ -149,13 +151,53 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: "Query previous container image version" + uses: actions/github-script@v7 + with: + script: | + const versionPattern = /^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$/; + const package_name = "axosyslog", org = "axoflow"; + const allPackageVersions = await github.paginate( + github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg, + { package_type: "container", package_name, org } + ); + + const latest = allPackageVersions.find(p => + p.metadata.container?.tags.includes("latest") + ); + const { data: { metadata: { container: { tags } } } } = + await github.rest.packages.getPackageVersionForOrganization({ + package_type: "container", package_name, org, package_version_id: latest.id + }); + + previousDockerTag = tags.find(t => versionPattern.test(t)); + core.exportVariable('previous_docker_tag', previousDockerTag); + - name: Extract metadata (AxoSyslog version) for Docker id: docker-metadata-tags - uses: docker/metadata-action@v5 - with: - images: ${{ needs.prepare.outputs.image-name }} - tags: type=match,pattern=axosyslog-([0-9].*),group=1 - sep-tags: ',' + run: | + previous_docker_tag_short=$(echo $previous_docker_tag | cut -d"-" -f1) + previous_docker_tag_rebuild_num=$(echo $previous_docker_tag | cut -d"-" -f2) + current_git_tag=$(echo ${{ github.ref }} | cut -d"-" -f2) + if [[ $current_git_tag =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then + function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; } + if [ $(version $current_git_tag) -gt $(version $previous_docker_tag_short) ]; then + next_docker_tag_with_patch=$current_git_tag-1 + next_docker_tag=$current_git_tag + echo "New AxoSyslog release detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)" + elif [ $(version $current_git_tag) -eq $(version $previous_docker_tag_short) ]; then + next_docker_tag_patch=$((previous_docker_tag_rebuild_num+1)) + next_docker_tag_with_patch=$previous_docker_tag_short-$next_docker_tag_patch + next_docker_tag=$previous_docker_tag_short + echo "AxoSyslog image rebuild detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)" + else + echo "Given git tag version is less than previous docker tag version: $current_git_tag < $previous_docker_tag_short" + echo "Rebuilding an older AxoSyslog version is not allowed. Please provide a valid git tag version." + exit 1 + fi + TAGS="ghcr.io/axoflow/axosyslog:$next_docker_tag,ghcr.io/axoflow/axosyslog:$next_docker_tag_with_patch,ghcr.io/axoflow/axosyslog:latest" + echo "tags=$TAGS" >> $GITHUB_OUTPUT + fi - name: Compose Docker image tags id: tags diff --git a/requirements.txt b/requirements.txt index 73a72bcb4..69fd753fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,21 +1,21 @@ boto3<=1.28.33 # <= is used for python3.6 compatibility on centos-7 botocore<=1.31.33 # <= is used for python3.6 compatibility on centos-7 -cachetools==4.2.4 -certifi==2024.7.4 -charset-normalizer==2.0.12 -google-auth==2.13.0 -idna==3.7 -kubernetes==25.3.0 -oauthlib==3.2.2 -pyasn1==0.4.8 -pyasn1-modules==0.2.8 -python-dateutil==2.8.2 -PyYAML==6.0.1 -requests==2.32.0 -requests-oauthlib==1.3.1 -rsa==4.9 -six==1.16.0 -urllib3==1.26.19 -websocket-client==1.3.1 -ply==3.11 -tornado==6.4.2 +cachetools~=4.2 +certifi~=2024.7 +charset-normalizer~=2.0 +google-auth~=2.13 +idna~=3.7 +kubernetes~=25.3 +oauthlib~=3.2 +pyasn1~=0.4 +pyasn1-modules~=0.2 +python-dateutil~=2.8 +PyYAML~=6.0 +requests~=2.32 +requests-oauthlib~=1.3 +rsa~=4.9 +six~=1.16 +urllib3~=1.26 +websocket-client~=1.3 +ply~=3.11 +tornado~=6.4