-
Notifications
You must be signed in to change notification settings - Fork 58
/
sync.sh
executable file
·172 lines (152 loc) · 6.15 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
#!/bin/bash
#
# Copyright (c) 2021 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
#
# SPECIAL CASE: convert registry upper-midstream (crw repo, forked from upstream w/ different plugins) to lower-midstream (crw-images repo) using yq, sed
# https://github.com/redhat-developer/codeready-workspaces/tree/crw-2-rhel-8/dependencies to https://github.com/redhat-developer/codeready-workspaces-images
set -e
# defaults
CSV_VERSION=2.y.0 # csv 2.y.0
CRW_VERSION=${CSV_VERSION%.*} # tag 2.y
UPSTM_NAME="che-plugin-registry"
MIDSTM_NAME="pluginregistry"
usage () {
echo "
Usage: $0 -v [CRW CSV_VERSION] [-s /path/to/sources] [-t /path/to/generated] [-b CRW_BRANCH]
Example: $0 -v 2.y.0 -s ${HOME}/codeready-workspaces -t /tmp/codeready-workspaces-images/codeready-workspaces-${MIDSTM_NAME} -b crw-2.y-rhel-8
"
exit
}
if [[ $# -lt 6 ]]; then usage; fi
while [[ "$#" -gt 0 ]]; do
case $1 in
'-b') CRW_BRANCH="$2"; shift 1;;
# for CSV_VERSION = 2.2.0, get CRW_VERSION = 2.2
'-v') CSV_VERSION="$2"; CRW_VERSION="${CSV_VERSION%.*}"; shift 1;;
# paths to use for input and ouput
'-s') SOURCEDIR="$2"; SOURCEDIR=${SOURCEDIR%/}/dependencies/${UPSTM_NAME};
if [[ ! -d ${SOURCEDIR} ]]; then echo "Cannot find ${SOURCEDIR} !"; exit 1; fi;;
'-t') TARGETDIR="$2"; TARGETDIR="${TARGETDIR%/}"; shift 1;;
'--help'|'-h') usage;;
# optional tag overrides
esac
shift 1
done
if [ "${CSV_VERSION}" == "2.y.0" ]; then usage; fi
# try to compute branches from currently checked out branch; else fall back to hard coded value for where to find
# https://github.com/redhat-developer/codeready-workspaces-images/blob/${CRW_BRANCH}/codeready-workspaces-operator-metadata-generated/manifests/codeready-workspaces.csv.yaml
if [[ -z ${CRW_BRANCH} ]]; then
CRW_BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
if [[ $CRW_BRANCH != "crw-2."*"-rhel-8" ]]; then
CRW_BRANCH="crw-2-rhel-8"
fi
fi
# step one - build the builder image
BUILDER=$(command -v podman || true)
if [[ ! -x $BUILDER ]]; then
echo "[WARNING] podman is not installed, trying with docker"
BUILDER=$(command -v docker || true)
if [[ ! -x $BUILDER ]]; then
echo "[ERROR] must install docker or podman. Abort!"; exit 1
fi
fi
# global / generic changes
echo ".github/
.git/
.gitattributes
/build/scripts/sync.sh
/bootstrap.Dockerfile
/cvp.yml
/container.yaml
/content_sets.*
/cvp.yml
/cvp-owners.yml
/sources
/get-source*.sh
/tests/basic-test.yaml
" > /tmp/rsync-excludes
echo "Rsync ${SOURCEDIR} to ${TARGETDIR}"
rsync -azrlt --checksum --exclude-from /tmp/rsync-excludes --delete "${SOURCEDIR}"/ "${TARGETDIR}"/
rm -f /tmp/rsync-excludes
# special case, copy job-config.json into midstream root dir so it's accessible from /build/../job-config.json
rsync -azrlt --checksum "${SOURCEDIR%/*}/job-config.json" "${TARGETDIR}"/
# ensure shell scripts are executable
find "${TARGETDIR}"/ -name "*.sh" -exec chmod +x {} \;
# CRW-1792 transform che-editors.yaml#L5 and che-plugins.yaml#L3 to refer to /latest
pushd "${TARGETDIR}" >/dev/null || exit 1
for d in che-editors.yaml che-plugins.yaml; do
sed -i ${d} -r -e "s|/nightly|/latest|" -e "s|/next|/latest|"
done
popd >/dev/null || exit
# transform Dockerfile
# shellcheck disable=SC1004
sed "${TARGETDIR}/build/dockerfiles/Dockerfile" --regexp-extended \
`# Strip registry from image references` \
-e 's|FROM registry.access.redhat.com/|FROM |' \
-e 's|FROM registry.redhat.io/|FROM |' \
`# CRW-2448 switch from ubi8 to rhel8 for OSBS` \
-e 's|ubi8/httpd-24:([0-9]+)(-[0-9.]+)|rhel8/httpd-24:\1|g' \
-e 's|ubi8/httpd-24$|rhel8/httpd-24|g' \
`# trim off version so we get the latest from internal registry` \
-e 's|ubi8/python-38:([0-9]+)(-[0-9.]+)|ubi8/python-38:\1|g' \
`# Set arg options: disable BOOTSTRAP; update CRW_BRANCH to correct value` \
-e 's|ARG BOOTSTRAP=.*|ARG BOOTSTRAP=false|' \
-e "s|ARG CRW_BRANCH=.*|ARG CRW_BRANCH=${CRW_BRANCH}|" \
`# Enable offline build - copy in built binaries` \
-e 's|# (COPY root-local.tgz)|\1|' \
`# only enable rhel8 here -- don't want centos or epel ` \
-e 's|^ *(COPY .*)/content_set.*repo (.+)|\1/content_sets_rhel8.repo \2|' \
> "${TARGETDIR}/Dockerfile"
cat << EOT >> "${TARGETDIR}/Dockerfile"
ENV SUMMARY="Red Hat CodeReady Workspaces ${MIDSTM_NAME} container" \\
DESCRIPTION="Red Hat CodeReady Workspaces ${MIDSTM_NAME} container" \\
PRODNAME="codeready-workspaces" \\
COMPNAME="${MIDSTM_NAME}-rhel8"
LABEL 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="${CRW_VERSION}" \\
license="EPLv2" \\
maintainer="Eric Williams <ericwill@redhat.com>, Nick Boldt <nboldt@redhat.com>" \\
io.openshift.expose-services="" \\
usage=""
EOT
echo "Converted Dockerfile"
# header to reattach to yaml files after yq transform removes it
COPYRIGHT="#
# Copyright (c) 2021 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
"
replaceField()
{
theFile="$1"
updateName="$2"
updateVal="$3"
echo "[INFO] ${0##*/} :: * ${updateName}: ${updateVal}"
# shellcheck disable=SC2016 disable=SC2086
changed=$(yq -Y --arg updateName "${updateName}" --arg updateVal "${updateVal}" ${updateName}' = $updateVal' "${theFile}")
echo "${COPYRIGHT}${changed}" > "${theFile}"
}
pushd "${TARGETDIR}" >/dev/null || exit 1
# TODO transform che-theia references to CRW theia references, including:
# description, icon, attributes.version, attributes.title, attributes.repository
popd >/dev/null || exit