Repository navigation
Expand file tree
/
Copy pathpubli.sh
More file actions
executable file
·132 lines (107 loc) · 4.55 KB
/
Copy pathpubli.sh
File metadata and controls
executable file
·132 lines (107 loc) · 4.55 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
# Copyright 2022 Nokia
# Licensed under the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
# publish container image to ghcr.io registry and tag with full tag, short tag, major version tag and latest tag
# the version information is read from the ./version file
# usage: `bash publi.sh`
# if latest tag shouldn't be added, use: `SRL_LATEST=no bash publi.sh 21.11.1-105`
# if major version tag shouldn't be added, use: `SRL_MAJOR=no bash publi.sh 21.11.1-105`
# to just create container images out of the tar.xz archive without pushing them to the registry:
# use `NO_PUSH=true bash publi.sh 21.11.1-105`
# the expectation is that srlinux-arm64:<long-version> and amd64 image is already available locally
# this is done by the `pull.sh` script.
#!/bin/bash
set -e
# source version file to get the version variables
source version
# REL is the original release version-build, i.e. 21.11.1-105
REL=$SRLREL-$SRLBUILD
# short version is one without the build tag - 21.11.1
SHORT_REL=$(echo ${REL} | cut -d "-" -f 1)
# major version is one without the minor fix version - 21.11
MAJOR_REL=$(echo ${REL} | cut -d "." -f 1,2)
ORIG_SRL_AMD64_IMAGE="srlinux-amd64:${REL}"
ORIG_SRL_ARM64_IMAGE="srlinux-arm64:${REL}"
# verify that image's CMD and ENTRYPOINT haven't changed
CMD=$(docker inspect $ORIG_SRL_AMD64_IMAGE -f '{{.Config.Cmd}}')
ENTRYPOINT=$(docker inspect $ORIG_SRL_AMD64_IMAGE -f '{{.Config.Entrypoint}}')
if [[ $ENTRYPOINT != "[/tini -- /usr/local/bin/fixuid -q /entrypoint.sh]" ]]; then
echo "entrypoint changed: $ENTRYPOINT"
exit 1
fi
if [[ $CMD != "[/bin/bash]" ]]; then
echo "cmd changed: $CMD"
exit 1
fi
GHCR_PREFIX="ghcr.io/nokia/srlinux"
AMD_IMAGE=$ORIG_SRL_AMD64_IMAGE
AMD_GHCR_IMAGE="${GHCR_PREFIX}:${REL}-amd64"
ARM_IMAGE=$ORIG_SRL_ARM64_IMAGE
ARM_GHCR_IMAGE="${GHCR_PREFIX}:${REL}-arm64"
# tag
echo "tagging image"
echo " amd64: $AMD_IMAGE -> $AMD_GHCR_IMAGE"
echo " arm64: $ARM_IMAGE -> $ARM_GHCR_IMAGE"
# tagging the original per-platform image to the ghcr per platform
sudo -E docker tag $AMD_IMAGE $AMD_GHCR_IMAGE # amd
sudo -E docker tag $ARM_IMAGE $ARM_GHCR_IMAGE # arm
# skipping pushing images if NO_PUSH env var is set
if [[ "${NO_PUSH}" != "" ]]; then
echo "skipping push of the images and manifests"
exit 0
fi
# push
echo "pushing images to ghcr.io"
# pushing individual images
docker push ${ARM_GHCR_IMAGE}
docker push ${AMD_GHCR_IMAGE}
# cleanup old manifests if they exist
sudo -E docker manifest rm ${GHCR_PREFIX}:${REL} || true
sudo -E docker manifest rm ${GHCR_PREFIX}:${SHORT_REL} || true
sudo -E docker manifest rm ${GHCR_PREFIX}:${MAJOR_REL} || true
sudo -E docker manifest rm ${GHCR_PREFIX}:latest || true
# creating versioned manifest
# full version
sudo -E docker manifest create ${GHCR_PREFIX}:${REL} \
${AMD_GHCR_IMAGE} \
${ARM_GHCR_IMAGE}
sudo -E docker manifest push ${GHCR_PREFIX}:${REL}
# short version
sudo -E docker manifest create ${GHCR_PREFIX}:${SHORT_REL} \
${AMD_GHCR_IMAGE} \
${ARM_GHCR_IMAGE}
sudo -E docker manifest push ${GHCR_PREFIX}:${SHORT_REL}
# creating the latest manifest only if env var SRL_LATEST is not set to `no`
# this is to skip tagging non most recent releases as latest
# e.g. when 24.10.5 is released, but most recent version is 25.3 already
if [[ "${SRL_LATEST}" != "no" ]]; then
sudo -E docker manifest create ${GHCR_PREFIX}:latest \
${AMD_GHCR_IMAGE} \
${ARM_GHCR_IMAGE}
sudo -E docker manifest push ${GHCR_PREFIX}:latest
fi
# create the major version manifest only if env var SRL_MAJOR is not set to `no`
# this skips tagging the major version if say, we push an older minor version
# that is not necessarily the latest minor version.
# e.g. 24.10.2 pushed again while 24.10.4 is already released
if [[ "${SRL_MAJOR}" != "no" ]]; then
sudo -E docker manifest create ${GHCR_PREFIX}:${MAJOR_REL} \
${AMD_GHCR_IMAGE} \
${ARM_GHCR_IMAGE}
sudo -E docker manifest push ${GHCR_PREFIX}:${MAJOR_REL}
fi
# print
echo "Nokia SR Linux $SHORT_REL can be pulled using the following commands:"
echo "docker pull ghcr.io/nokia/srlinux:$REL"
echo "docker pull ghcr.io/nokia/srlinux:$SHORT_REL"
if [[ "${SRL_MAJOR}" != "no" ]]; then
echo "docker pull ghcr.io/nokia/srlinux:$MAJOR_REL"
fi
if [[ "${SRL_LATEST}" != "no" ]]; then
echo "docker pull ghcr.io/nokia/srlinux:latest"
fi
# remove local manifests so they don't mess up with subsequent runs of this script
sudo -E docker manifest rm ${GHCR_PREFIX}:${REL}
sudo -E docker manifest rm ${GHCR_PREFIX}:${SHORT_REL}
sudo -E docker manifest rm ${GHCR_PREFIX}:${MAJOR_REL}
sudo -E docker manifest rm ${GHCR_PREFIX}:latest