-
-
Notifications
You must be signed in to change notification settings - Fork 54
148 lines (137 loc) · 6.27 KB
/
release.yml
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
name: release
on:
push:
branches:
- 'master'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
fetch-depth: '0'
- name: Set env variables
run: |
echo "GITHUB_DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
echo "GITHUB_SHA=${{ github.sha }}" >> $GITHUB_ENV
- name: Get latest Webapp release version
run: |
WEBAPP_RELEASE=$(curl -sX GET "https://api.github.com/repos/netbootxyz/webapp/releases/latest" | jq -r '. | .tag_name')
echo "WEBAPP_RELEASE=${WEBAPP_RELEASE}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to the Docker Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Determine version numbers
id: version_check
continue-on-error: true
run: |
IMAGE=netbootxyz/netbootxyz
TOKEN=$(curl -sX GET \
"https://ghcr.io/token?scope=repository%3Anetbootxyz%2Fnetbootxyz%3Apull" \
| jq -r '.token')
TAG=$(curl -s --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/tags/list?n=1000" \
| jq -r '.tags[-1]')
echo LATEST_TAG: $TAG
MULTIDIGEST=$(curl -s \
--header "Accept: application/vnd.oci.image.index.v1+json" \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/manifests/${TAG}" \
| jq -r 'first(.manifests[].digest)')
DIGEST=$(curl -s \
--header "Accept: application/vnd.oci.image.manifest.v1+json" \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/manifests/${MULTIDIGEST}" \
| jq -r '.config.digest')
IMAGE_INFO=$(curl -sL \
--header "Authorization: Bearer ${TOKEN}" \
"https://ghcr.io/v2/${IMAGE}/blobs/${DIGEST}" \
| jq -r '.config')
IMAGE_RELEASE=$(echo ${IMAGE_INFO} | jq -r '.Labels.build_version' | awk '{print $3}')
IMAGE_VERSION=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $1}')
NB_RELEASE_NUMBER=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $2}')
TAG_SHA=$(git rev-list -n 1 ${IMAGE_RELEASE})
if [ -z "${MULTIDIGEST}" ] || [ "${MULTIDIGEST}" == "null" ]; then
echo "**** No existing container build found, assuming first build ****"
VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
elif [ "${WEBAPP_RELEASE}" == "${IMAGE_VERSION}" ]; then
echo "**** Version ${WEBAPP_RELEASE} unchanged, checking if there is anything to build..."
if [ "${TAG_SHA}" == "${GITHUB_SHA}" ]; then
echo "**** Nothing to do, exiting build... **** "
exit 1
else
echo "**** Changes found... incrementing build number version... ****"
NB_RELEASE_NUMBER=$((NB_RELEASE_NUMBER + 1))
VERSION_TAG=${IMAGE_VERSION}-nbxyz${NB_RELEASE_NUMBER}
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
fi
else
echo "**** New version ${WEBAPP_RELEASE} found; old version was ${IMAGE_VERSION}. Generating new webapp release... ****"
VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
fi
- name: Docker meta
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
id: meta
uses: docker/metadata-action@v5
with:
images: netbootxyz/netbootxyz
labels: |
maintainer=antonym
org.opencontainers.image.created=${{ env.GITHUB_DATE }}
org.opencontainers.image.authors=netboot.xyz
org.opencontainers.image.url=https://github.com/netbootxyz/docker-netbootxyz/packages
org.opencontainers.image.documentation=https://netboot.xyz
org.opencontainers.image.source=https://github.com/netbootxyz/docker-netbootxyz
org.opencontainers.image.version=${{ env.VERSION_TAG }}
org.opencontainers.image.revision=${{ env.GITHUB_SHA }}
org.opencontainers.image.vendor=netboot.xyz
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.ref.name=${{ env.GITHUB_SHA }}
org.opencontainers.image.title=netbootxyz
org.opencontainers.image.description=netboot.xyz official docker container - Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE.
- name: Build and push image
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
uses: docker/build-push-action@v5
with:
push: true
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
build-args: |
WEBAPP_VERSION=${{ env.WEBAPP_RELEASE }}
VERSION=${{ env.VERSION_TAG }}
BUILD_DATE=${{ env.GITHUB_DATE }}
tags: |
netbootxyz/netbootxyz:latest
netbootxyz/netbootxyz:${{ github.sha }}
netbootxyz/netbootxyz:${{ env.VERSION_TAG }}
ghcr.io/netbootxyz/netbootxyz:latest
ghcr.io/netbootxyz/netbootxyz:${{ github.sha }}
ghcr.io/netbootxyz/netbootxyz:${{ env.VERSION_TAG }}
labels: ${{ steps.meta.outputs.labels }}
- name: Bump version and push tag
if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
id: tag_version
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CUSTOM_TAG: ${{ env.VERSION_TAG }}
WITH_V: true
RELEASE_BRANCHES: master