forked from DiouxX/docker-glpi
-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (137 loc) · 5.41 KB
/
docker.yml
File metadata and controls
162 lines (137 loc) · 5.41 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Sync Last 10 GLPI Images
on:
schedule:
- cron: "0 3 * * *" # Run daily at 3 AM UTC
workflow_dispatch:
push:
branches: [master]
jobs:
fetch-tags:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.get_tags.outputs.tags }}
steps:
- name: Fetch last 10 GLPI releases (stable + prerelease)
id: get_tags
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
API_URL="https://api.github.com/repos/glpi-project/glpi/releases?per_page=20"
HEADERS=(-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN")
RELEASES=$(curl -sL "${HEADERS[@]}" "$API_URL")
# Take the latest 10 tags (includes prereleases)
TAGS=$(echo "$RELEASES" | jq -r '.[0:10] | .[].tag_name')
if [ -z "$TAGS" ]; then
echo "tags=[]" >> $GITHUB_OUTPUT
else
echo "Found GLPI releases (last 10):"
echo "$TAGS"
TAGS_JSON=$(echo "$TAGS" | jq -R . | jq -s . | jq -c .) # compact JSON array
echo "tags=$TAGS_JSON" >> $GITHUB_OUTPUT
fi
build:
needs: fetch-tags
if: needs.fetch-tags.outputs.tags != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
tag: ${{ fromJson(needs.fetch-tags.outputs.tags) }}
env:
DOCKER_HUB_USERNAME_SET: ${{ secrets.DOCKER_HUB_USERNAME != '' }}
DOCKER_HUB_ACCESS_TOKEN_SET: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN != '' }}
GHCR_PAT_IS_SET: ${{ secrets.GHCR_PAT != '' }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Release Info
id: release_info
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
API_URL="https://api.github.com/repos/glpi-project/glpi/releases/tags/${{ matrix.tag }}"
HEADERS=(-H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN")
DATA=$(curl -sL "${HEADERS[@]}" "$API_URL")
NOTES=$(echo "$DATA" | jq -r .body)
IS_PRERELEASE=$(echo "$DATA" | jq -r .prerelease)
IMAGE_TAG_VERSION="$(echo "${{ matrix.tag }}" | sed 's/^v//')" # drop leading v
MAJOR_TAG="$(echo "$IMAGE_TAG_VERSION" | cut -d. -f1)"
echo "IMAGE_TAG_VERSION=$IMAGE_TAG_VERSION" >> $GITHUB_ENV
echo "MAJOR_TAG=$MAJOR_TAG" >> $GITHUB_ENV
echo "IS_PRERELEASE=$IS_PRERELEASE" >> $GITHUB_ENV
echo "$NOTES" > release_notes.md
- name: Check if release already exists in this repo
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "${{ matrix.tag }}" >/dev/null 2>&1; then
echo "Release ${{ matrix.tag }} already exists, skipping build."
echo "skip_build=true" >> $GITHUB_ENV
else
echo "skip_build=false" >> $GITHUB_ENV
fi
- name: Create GitHub Release
if: env.skip_build == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ env.IS_PRERELEASE }}" = "true" ]; then
gh release create "${{ matrix.tag }}" \
--title "GLPI ${{ matrix.tag }}" \
--notes-file release_notes.md \
--prerelease
else
gh release create "${{ matrix.tag }}" \
--title "GLPI ${{ matrix.tag }}" \
--notes-file release_notes.md
fi
- name: Set up Docker Buildx
if: env.skip_build == 'false'
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: env.skip_build == 'false' && env.DOCKER_HUB_USERNAME_SET == 'true' && env.DOCKER_HUB_ACCESS_TOKEN_SET == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Log in to GitHub Container Registry
if: env.skip_build == 'false' && env.GHCR_PAT_IS_SET == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- name: Prepare Docker Tags
if: env.skip_build == 'false'
id: prep_tags
run: |
TAG=${{ env.IMAGE_TAG_VERSION }}
MAJOR=${{ env.MAJOR_TAG }}
IMAGE_DH=geniusdynamics/glpi
IMAGE_GH=ghcr.io/${{ github.repository_owner }}/glpi
TAGS=""
if [[ "$TAG" == *"rc"* ]]; then
# Pre-release RC tagging
TAGS="$TAGS,$IMAGE_DH:$TAG,$IMAGE_DH:${MAJOR}-rc,$IMAGE_DH:rc"
TAGS="$TAGS,$IMAGE_GH:$TAG,$IMAGE_GH:${MAJOR}-rc,$IMAGE_GH:rc"
else
# Stable release tagging
TAGS="$TAGS,$IMAGE_DH:$TAG,$IMAGE_DH:$MAJOR,$IMAGE_DH:latest"
TAGS="$TAGS,$IMAGE_GH:$TAG,$IMAGE_GH:$MAJOR,$IMAGE_GH:latest"
fi
TAGS=$(echo "$TAGS" | sed 's/^,//')
echo "FINAL_TAGS=$TAGS" >> $GITHUB_ENV
- name: Build and Push Image
if: env.skip_build == 'false' && env.FINAL_TAGS != ''
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.FINAL_TAGS }}
platforms: linux/amd64
- name: Build Summary
if: env.skip_build == 'false'
run: |
echo "✔️ Built GLPI ${{ matrix.tag }}"
echo "Tags: ${{ env.FINAL_TAGS }}"