Skip to content
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

Rebuild axosyslog image with auto patch version increment #411

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
31 changes: 26 additions & 5 deletions .github/workflows/axosyslog-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -151,11 +153,30 @@ jobs:

- 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=$(skopeo inspect docker://ghcr.io/axoflow/axosyslog:latest | jq '.RepoTags' | sed 's/ \|"\|,//g' | grep "^[0-9]*.[0-9]*.[0-9]*$\|^[0-9]*.[0-9]*.[0-9]*-[0-9]*$" | tail -n 1)
Copy link
Member

@MrAnno MrAnno Jan 16, 2025

Choose a reason for hiding this comment

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

jq --raw-output '.RepoTags.[]' produces the desired output, so the sed can be removed.

Copy link
Member

Choose a reason for hiding this comment

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

There is a problem with the skopeo query: it returns all tags, not the corresponding version for latest.
I think I have an idea how to query the exact version.

Copy link
Member

@MrAnno MrAnno Jan 16, 2025

Choose a reason for hiding this comment

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

Very verbose, but it works. Let me know what you think:

      - 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);

After this step, you will get 4.9.0-2 in the $previous_docker_tag variable, and you can use in your script.

previous_docker_tag_short=$(echo $previous_docker_tag | cut -d"-" -f1)
previous_docker_tag_patch=$(echo $previous_docker_tag | cut -d"-" -f2)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: this is the rebuild number, not the patch part.

current_git_tag=$(echo ${{ github.ref }} | cut -d"-" -f2)
Copy link
Member

Choose a reason for hiding this comment

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

We need to make sure everything below this line is skipped when github.ref is not a version tag.
We use this job to produce nightly and snapshot builds as well.

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
echo "Given git tag version is greater than previous docker tag version: $current_git_tag > $previous_docker_tag_short"
Copy link
Member

Choose a reason for hiding this comment

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

Now that we have debugged everything, we could replace this echo with something like this:

New AxoSyslog release detected (new version: , previous docker version: )

next_docker_tag_with_patch=$current_git_tag-1
next_docker_tag=$current_git_tag
echo "Next docker version tag: $next_docker_tag_with_patch"
elif [ $(version $current_git_tag) -eq $(version $previous_docker_tag_short) ]; then
echo "Given git tag version is equals with previous docker tag version: $current_git_tag == $previous_docker_tag_short"
Copy link
Member

Choose a reason for hiding this comment

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

AxoSyslog image rebuild detected (version: )

next_docker_tag_patch=$((previous_docker_tag_patch+1))
next_docker_tag_with_patch=$previous_docker_tag_short-$next_docker_tag_patch
next_docker_tag=$previous_docker_tag_short
echo "Next docker version tag: $next_docker_tag_with_patch"
else
echo "Given git tag version is less than previous docker tag version: $current_git_tag < $previous_docker_tag_short"
echo "This is not allowed. Please provide a valid git tag version."
Copy link
Member

Choose a reason for hiding this comment

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

Rebuilding an older AxoSyslog version is not allowed

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

- name: Compose Docker image tags
id: tags
Expand Down
Loading