-
Notifications
You must be signed in to change notification settings - Fork 31
94 lines (77 loc) · 3.17 KB
/
Copy pathdocker.yml
File metadata and controls
94 lines (77 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Build and Publish Docker Image
on:
push:
branches:
- 'main'
release:
types: [published]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/modelbench-private
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest version from registry
id: get_version
run: |
LATEST_VERSION="v0.0.0"
TAGS_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/modelbench-private/versions" 2>/dev/null || echo "[]")
if [ $? -ne 0 ] || [ -z "$TAGS_RESPONSE" ]; then
echo "Error: Failed to fetch package versions from GitHub API"
exit 1
fi
if echo "$TAGS_RESPONSE" | jq -e '.message' >/dev/null 2>&1; then
ERROR_MESSAGE=$(echo "$TAGS_RESPONSE" | jq -r '.message')
echo "Error: GitHub API returned error: $ERROR_MESSAGE"
exit 1
fi
if [ "$TAGS_RESPONSE" != "[]" ] && [ ! -z "$TAGS_RESPONSE" ]; then
SEMVER_TAGS=$(echo "$TAGS_RESPONSE" | jq -r '.[].metadata.container.tags[]?' 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V || echo "")
if [ ! -z "$SEMVER_TAGS" ]; then
LATEST_VERSION=$(echo "$SEMVER_TAGS" | tail -n1)
fi
fi
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
VERSION_NUMBER=${LATEST_VERSION#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION_NUMBER"
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="v$MAJOR.$MINOR.$NEW_PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Latest version found: $LATEST_VERSION"
echo "New version will be: $NEW_VERSION"
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ steps.get_version.outputs.new_version }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Output new version
run: |
echo "Successfully built and pushed:"
echo "- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
echo "- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.new_version }}"