Skip to content

Commit 06d6346

Browse files
authored
Merge pull request #411 from mitzkia/axosyslog_image_rebuild
Rebuild axosyslog image with auto patch version increment
2 parents 74fb889 + 3220ae0 commit 06d6346

File tree

2 files changed

+66
-24
lines changed

2 files changed

+66
-24
lines changed

.github/workflows/axosyslog-docker.yml

+47-5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ jobs:
125125
merge-and-push:
126126
runs-on: ubuntu-latest
127127
needs: [prepare, image-build]
128+
outputs:
129+
tags: ${{ steps.docker-metadata-tags.outputs.tags }}
128130
steps:
129131
- name: Download digests
130132
uses: actions/download-artifact@v4
@@ -136,13 +138,53 @@ jobs:
136138
- name: Set up Docker Buildx
137139
uses: docker/setup-buildx-action@v3
138140

141+
- name: "Query previous container image version"
142+
uses: actions/github-script@v7
143+
with:
144+
script: |
145+
const versionPattern = /^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$/;
146+
const package_name = "axosyslog", org = "axoflow";
147+
const allPackageVersions = await github.paginate(
148+
github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg,
149+
{ package_type: "container", package_name, org }
150+
);
151+
152+
const latest = allPackageVersions.find(p =>
153+
p.metadata.container?.tags.includes("latest")
154+
);
155+
const { data: { metadata: { container: { tags } } } } =
156+
await github.rest.packages.getPackageVersionForOrganization({
157+
package_type: "container", package_name, org, package_version_id: latest.id
158+
});
159+
160+
previousDockerTag = tags.find(t => versionPattern.test(t));
161+
core.exportVariable('previous_docker_tag', previousDockerTag);
162+
139163
- name: Extract metadata (AxoSyslog version) for Docker
140164
id: docker-metadata-tags
141-
uses: docker/metadata-action@v5
142-
with:
143-
images: ${{ needs.prepare.outputs.image-name }}
144-
tags: type=match,pattern=axosyslog-([0-9].*),group=1
145-
sep-tags: ','
165+
run: |
166+
previous_docker_tag_short=$(echo $previous_docker_tag | cut -d"-" -f1)
167+
previous_docker_tag_rebuild_num=$(echo $previous_docker_tag | cut -d"-" -f2)
168+
current_git_tag=$(echo ${{ github.ref }} | cut -d"-" -f2)
169+
if [[ $current_git_tag =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
170+
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; }
171+
if [ $(version $current_git_tag) -gt $(version $previous_docker_tag_short) ]; then
172+
next_docker_tag_with_patch=$current_git_tag-1
173+
next_docker_tag=$current_git_tag
174+
echo "New AxoSyslog release detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)"
175+
elif [ $(version $current_git_tag) -eq $(version $previous_docker_tag_short) ]; then
176+
next_docker_tag_patch=$((previous_docker_tag_rebuild_num+1))
177+
next_docker_tag_with_patch=$previous_docker_tag_short-$next_docker_tag_patch
178+
next_docker_tag=$previous_docker_tag_short
179+
echo "AxoSyslog image rebuild detected (new version: $next_docker_tag_with_patch, previous docker version: $previous_docker_tag)"
180+
else
181+
echo "Given git tag version is less than previous docker tag version: $current_git_tag < $previous_docker_tag_short"
182+
echo "Rebuilding an older AxoSyslog version is not allowed. Please provide a valid git tag version."
183+
exit 1
184+
fi
185+
TAGS="ghcr.io/axoflow/axosyslog:$next_docker_tag,ghcr.io/axoflow/axosyslog:$next_docker_tag_with_patch,ghcr.io/axoflow/axosyslog:latest"
186+
echo "tags=$TAGS" >> $GITHUB_OUTPUT
187+
fi
146188
147189
- name: Compose Docker image tags
148190
id: tags

requirements.txt

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
boto3<=1.28.33 # <= is used for python3.6 compatibility on centos-7
22
botocore<=1.31.33 # <= is used for python3.6 compatibility on centos-7
3-
cachetools==4.2.4
4-
certifi==2024.7.4
5-
charset-normalizer==2.0.12
6-
google-auth==2.13.0
7-
idna==3.7
8-
kubernetes==25.3.0
9-
oauthlib==3.2.2
10-
pyasn1==0.4.8
11-
pyasn1-modules==0.2.8
12-
python-dateutil==2.8.2
13-
PyYAML==6.0.1
14-
requests==2.32.0
15-
requests-oauthlib==1.3.1
16-
rsa==4.9
17-
six==1.16.0
18-
urllib3==1.26.19
19-
websocket-client==1.3.1
20-
ply==3.11
21-
tornado==6.4.2
3+
cachetools~=4.2
4+
certifi~=2024.7
5+
charset-normalizer~=2.0
6+
google-auth~=2.13
7+
idna~=3.7
8+
kubernetes~=25.3
9+
oauthlib~=3.2
10+
pyasn1~=0.4
11+
pyasn1-modules~=0.2
12+
python-dateutil~=2.8
13+
PyYAML~=6.0
14+
requests~=2.32
15+
requests-oauthlib~=1.3
16+
rsa~=4.9
17+
six~=1.16
18+
urllib3~=1.26
19+
websocket-client~=1.3
20+
ply~=3.11
21+
tornado~=6.4

0 commit comments

Comments
 (0)