-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathsync.sh
executable file
·243 lines (220 loc) · 10.1 KB
/
sync.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
#
# Copyright (c) 2021-23 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#
# convert upstream che repo to midstream devspaces-images repo using yq, sed
set -e
# defaults
CSV_VERSION=3.y.0 # csv 3.y.0
DS_VERSION=${CSV_VERSION%.*} # tag 3.y
UPSTM_NAME="operator"
MIDSTM_NAME="operator-bundle"
CSV_VERSION_PREV=""
usage () {
echo "
Usage: $0 -v [DS CSV_VERSION] [-s /path/to/${UPSTM_NAME}] [-t /path/to/generated] [-p DS CSV_VERSION_PREV]
Example: $0 -v 3.y.0 -s ${HOME}/projects/${UPSTM_NAME} -t /tmp/ds-${MIDSTM_NAME} -p 3.y-1.0"
exit
}
if [[ $# -lt 6 ]]; then usage; fi
while [[ "$#" -gt 0 ]]; do
case $1 in
'-v') CSV_VERSION="$2"; DS_VERSION="${CSV_VERSION%.*}"; shift 1;;
# paths to use for input and output
'-s') SOURCEDIR="$2"; SOURCEDIR="${SOURCEDIR%/}"; shift 1;;
'-t') TARGETDIR="$2"; TARGETDIR="${TARGETDIR%/}"; shift 1;;
'-p') CSV_VERSION_PREV="$2"; shift 1;;
'--help'|'-h') usage;;
esac
shift 1
done
if [[ ! -d "${SOURCEDIR}" ]]; then usage; fi
if [[ ! -d "${TARGETDIR}" ]]; then usage; fi
if [[ "${CSV_VERSION}" == "3.y.0" ]]; then usage; fi
# if not set via commandline, compute CSV_VERSION_PREV
# from https://raw.githubusercontent.com/redhat-developer/devspaces/devspaces-3-rhel-8/dependencies/job-config.json
# shellcheck disable=SC2086
if [[ -z "${CSV_VERSION_PREV}" ]]; then
MIDSTM_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "devspaces-3-rhel-8")
if [[ ${MIDSTM_BRANCH} != "devspaces-"*"-rhel-"* ]]; then MIDSTM_BRANCH="devspaces-3-rhel-8"; fi
# load the latest job-config.json, not the branched version; this ensures we get CVE updates (CRW-4324)
configjson="$(curl -sSLo- "https://raw.githubusercontent.com/redhat-developer/devspaces/devspaces-3-rhel-8/dependencies/job-config.json")"
if [[ $configjson == *"404"* ]] || [[ $configjson == *"Not Found"* ]]; then
echo "[ERROR] Could not load https://raw.githubusercontent.com/redhat-developer/devspaces/devspaces-3-rhel-8/dependencies/job-config.json"
echo "[ERROR] Please use -p flag to set CSV_VERSION_PREV"
exit 1
fi
if [[ $MIDSTM_BRANCH == "devspaces-3-rhel-8" ]]; then
DS_VERSION="$(echo "$configjson" | jq -r '.Version')"
else
DS_VERSION=${MIDSTM_BRANCH/devspaces-/}; DS_VERSION=${DS_VERSION//-rhel-8}
fi
if [[ -z "${CSV_VERSION_PREV}" ]]; then
#get from json
CSV_VERSION_PREV="$(echo "$configjson" | jq -r '.CSVs["'${MIDSTM_NAME}'"]."'${DS_VERSION}'".CSV_VERSION_PREV')"
DS_VERSION_PREV="${CSV_VERSION_PREV%-*}"; DS_VERSION_PREV="${DS_VERSION_PREV%.*}"
echo "[INFO] config.json#.CSVs[${MIDSTM_NAME}][$DS_VERSION][CSV_VERSION_PREV] = ${CSV_VERSION_PREV} (DS_VERSION_PREV = ${DS_VERSION_PREV})"
# check if image exists for that tag (doesn't work with CVE respins, only manual releases)
# CRW-2725 also check quay, so we can check update path from 3.y.0.RC -> 3.y+1.0.CI (need to resolve against pre-GA content, not just RHEC GA)
if [[ ! $(skopeo inspect docker://registry.redhat.io/devspaces/devspaces-${MIDSTM_NAME}:${DS_VERSION_PREV} --raw 2>/dev/null) ]] && \
[[ ! $(skopeo inspect docker://quay.io/devspaces/devspaces-${MIDSTM_NAME}:${DS_VERSION_PREV} --raw 2>/dev/null) ]]; then
# else get from latest released image
curl -sSL https://raw.githubusercontent.com/redhat-developer/devspaces/${MIDSTM_BRANCH}/product/containerExtract.sh --output /tmp/containerExtract.sh
if [[ $(cat /tmp/containerExtract.sh) == *"404"* ]] || [[ $(cat /tmp/containerExtract.sh) == *"Not Found"* ]]; then
echo "[ERROR] Could not load https://raw.githubusercontent.com/redhat-developer/devspaces/${MIDSTM_BRANCH}/product/containerExtract.sh"
exit 1
fi
chmod +x /tmp/containerExtract.sh
# NOTE: for CVE respins, container tag != CSV version, so we have to extract the container to get the CSV version, then replace + with -
rm -fr /tmp/registry.redhat.io-devspaces-devspaces-${MIDSTM_NAME}-latest-*
/tmp/containerExtract.sh --delete-before --delete-after registry.redhat.io/devspaces/devspaces-${MIDSTM_NAME}:latest
CSV_VERSION_PREV="$(yq -r '.spec.version' /tmp/registry.redhat.io-devspaces-devspaces-${MIDSTM_NAME}-latest-*/manifests/devspaces.csv.yaml | tr "+" "-")"
echo "[INFO] registry.redhat.io/devspaces/devspaces-${MIDSTM_NAME}:latest#.spec.version = ${CSV_VERSION_PREV}"
rm -fr /tmp/registry.redhat.io-devspaces-devspaces-${MIDSTM_NAME}-latest-*
rm -fr /tmp/containerExtract.sh
if [[ ${CSV_VERSION_PREV} == "null" ]]; then CSV_VERSION_PREV="main"; fi
fi
fi
fi
if [[ -n ${MIDSTM_BRANCH} ]]; then
echo "[INFO] For DS VERSION = ${DS_VERSION} / MIDSTM_BRANCH = ${MIDSTM_BRANCH}:"
else
echo "[INFO] For DS VERSION = ${DS_VERSION}:"
fi
echo "[INFO] CSV_VERSION_PREV = ${CSV_VERSION_PREV}"
# ignore changes in these files
echo ".ci/
.dockerignore
.git/
.github/
.gitignore
.vscode/
/container.yaml
/content_sets.*
/cvp.yml
/cvp-owners.yml
api/
build/
config/
controllers/
Dependencies.md
devfile.yaml
devfiles.yaml
Dockerfile
get-source*.sh
go.mod
go.sum
hack/
main.go
make-release.sh
Makefile
manifests
metadata
mocks/
pkg/
PROJECT
README.md
RELEASE.md
REQUIREMENTS
sources
helmcharts/
tests/basic-test.yaml
tools.go
vendor/
version/
" > /tmp/rsync-excludes
# echo "manifests
# metadata
# bundle
# " > /tmp/rsync-includes
echo "Rsync ${SOURCEDIR} to ${TARGETDIR}"
rsync -azrlt --checksum --exclude-from /tmp/rsync-excludes --delete "${SOURCEDIR}"/ "${TARGETDIR}"/ # --include-from /tmp/rsync-includes
rm -f /tmp/rsync-excludes
# ensure shell scripts are executable
find "${TARGETDIR}"/ -name "*.sh" -exec chmod +x {} \;
# create dockerfile
cat << EOT > "${TARGETDIR}"/Dockerfile
# Copyright (c) 2020-$(date +%Y) Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#
# metadata images built in brew must be from scratch
# https://docs.engineering.redhat.com/display/CFC/Migration
FROM scratch
COPY manifests /manifests/
COPY metadata /metadata/
# append Brew metadata here
ENV SUMMARY="Red Hat OpenShift Dev Spaces ${MIDSTM_NAME} container" \\
DESCRIPTION="Red Hat OpenShift Dev Spaces ${MIDSTM_NAME} container" \\
PRODNAME="devspaces" \\
COMPNAME="${MIDSTM_NAME}"
# https://access.redhat.com/support/policy/updates/openshift#dates
# support for 4.12 ends on January 17, 2025
# support for 4.11 ends on February 10, 2024
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 \\
operators.operatorframework.io.bundle.manifests.v1=manifests/ \\
operators.operatorframework.io.bundle.metadata.v1=metadata/ \\
operators.operatorframework.io.bundle.package.v1=devspaces \\
operators.operatorframework.io.bundle.channels.v1=stable \\
operators.operatorframework.io.bundle.channel.default.v1=stable \\
com.redhat.delivery.operator.bundle="true" \\
com.redhat.openshift.versions="v4.11" \\
com.redhat.delivery.backport=false \\
summary="\$SUMMARY" \\
description="\$DESCRIPTION" \\
io.k8s.description="\$DESCRIPTION" \\
io.k8s.display-name="\$DESCRIPTION" \\
io.openshift.tags="\$PRODNAME,\$COMPNAME" \\
com.redhat.component="\$PRODNAME-\$COMPNAME-container" \\
name="\$PRODNAME/\$COMPNAME" \\
version="${DS_VERSION}" \\
license="EPLv2" \\
maintainer="Anatolii Bazko <[email protected]>, Dmytro Nochevnov <[email protected]>, Samantha Dawley <[email protected]>, Nick Boldt <[email protected]>" \\
io.openshift.expose-services="" \\
usage=""
EOT
echo "Generated Dockerfile"
curl -sSL https://raw.githubusercontent.com/redhat-developer/devspaces/${MIDSTM_BRANCH}/product/getLatestImageTags.sh --output /tmp/getLatestImageTags.sh
if [[ $(cat /tmp/getLatestImageTags.sh) == *"404"* ]] || [[ $(cat /tmp/getLatestImageTags.sh) == *"Not Found"* ]]; then
echo "[ERROR] Could not load https://raw.githubusercontent.com/redhat-developer/devspaces/${MIDSTM_BRANCH}/product/getLatestImageTags.sh"
exit 1
fi
chmod +x /tmp/getLatestImageTags.sh
UBI_TAG=$(/tmp/getLatestImageTags.sh -c ubi8/ubi-minimal --tag "8."); UBI_TAG=${UBI_TAG##*:}
"${TARGETDIR}"/build/scripts/sync-che-operator.sh -v "${CSV_VERSION}" -s "${SOURCEDIR}/" -t "${TARGETDIR}/" --ubi-tag "${UBI_TAG}"
"${TARGETDIR}"/build/scripts/sync-che-olm.sh -v "${CSV_VERSION}" -p "${CSV_VERSION_PREV}" -s "${SOURCEDIR}/" -t "${TARGETDIR}/" --ubi-tag "${UBI_TAG}"
pushd "${TARGETDIR}"/ >/dev/null || exit
rm -fr api/ bundle/ config/ controllers/ hack/ mocks/ pkg/ vendor/ version/ go.* *.go
CSVFILE="${TARGETDIR}"/manifests/devspaces.csv.yaml
# transform into Brew-friendly version of CSV
# OPTION 1: only for images changed in this respin (required for subsequent GAs of 3.y.z)
# sed -r -i "${CSVFILE}" \
# -e "[email protected]/devspaces/[email protected]/rh-osbs/devspaces-operator@g"
# ...
# OPTION 2: use images from reg-proxy, which could be older than the RHEC Freshmaker updates (required for initial GA of 3.y.0)
# CRW-4077 : DO NOT change image references if they have a @sha256: reference, only :3.y
sed -i "${CSVFILE}" -r \
-e "s%(registry.redhat.io|quay.io)/devspaces/(.+:${DS_VERSION})%registry-proxy.engineering.redhat.com/rh-osbs/devspaces-\2%g" \
-e "s@devspaces-rhel8-operator@operator@g" \
-e "s@:latest@:${DS_VERSION}@g"
# date in CSV will be updated only if there were any changes in CSV
pushd ${CSVFILE%/*} >/dev/null || exit # targetdir/manifests/
# git diff ${CSVFILE##*/}
if [[ ! $(git diff ${CSVFILE##*/} | grep -v createdAt | egrep "^(-|\\+) " || true) ]]; then
git checkout ${CSVFILE##*/} || true
fi
popd >/dev/null || exit