Manage OLM files (PR #45)

Implementation of issue https://github.com/eclipse/che/issues/13780

* complete cluster role
* update operator.yaml
* Add OLM files for openshift in beta-5 state
* Add RC 2 release CSV
* Reordered beta 5 csv in alphabetic order
* Add first bits of OLM files management
* lowercase `RC` and remove readiness probe
* pre-release (with `rc-2.0`) and nightly channels
* Add the kubernetes version of the OLM package
* Adding operator sources
* `OperatorSource`s should be in distinct namespaces
* Change proposed by @l0rd
* scripts to update nightly CSVs
* script to release OLM files
* Add the script to push OLM files as Quay apps
* Add script to prepare `community-operators` PRs
* script to release the operator Go code
* Rename `*-test-*` to `*-preview-*` and rename the `pre-releases` channel to `stable`
* `9.9.9` as semver-compliant prefix for nightlies

Signed-off-by: David Festal <dfestal@redhat.com>
pull/47/head
David Festal 2019-07-15 15:39:47 +02:00 committed by GitHub
parent 30f81e1b32
commit 4bf6621df1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 2628 additions and 22 deletions

View File

@ -22,6 +22,8 @@ rules:
- get
- delete
- list
- patch
- update
- watch
- apiGroups:
- config.openshift.io

View File

@ -32,14 +32,17 @@ spec:
command:
- che-operator
imagePullPolicy: IfNotPresent
readinessProbe:
exec:
command:
- stat
- /tmp/operator-sdk-ready
initialDelaySeconds: 4
periodSeconds: 10
failureThreshold: 1
# TODO: to be uncommented when issue
# https://github.com/operator-framework/operator-sdk/issues/1234
# is fixed
# readinessProbe:
# exec:
# command:
# - stat
# - /tmp/operator-sdk-ready
# initialDelaySeconds: 4
# periodSeconds: 10
# failureThreshold: 1
env:
- name: WATCH_NAMESPACE
valueFrom:

View File

@ -16,30 +16,32 @@ spec:
replicas: 1
selector:
matchLabels:
name: che-operator
app: che-operator
template:
metadata:
labels:
name: che-operator
app: che-operator
spec:
serviceAccountName: che-operator
containers:
- name: che-operator
image: quay.io/eclipse-che/che-operator:7.0.0-beta-5.0
image: quay.io/eclipse-che/che-operator:nightly
ports:
- containerPort: 60000
name: metrics
command:
- che-operator
imagePullPolicy: IfNotPresent
readinessProbe:
exec:
command:
- stat
- /tmp/operator-sdk-ready
initialDelaySeconds: 4
periodSeconds: 10
failureThreshold: 1
- /usr/local/bin/che-operator
imagePullPolicy: Always
# TODO: to be uncommented when issue
# https://github.com/operator-framework/operator-sdk/issues/1234
# is fixed
# readinessProbe:
# exec:
# command:
# - stat
# - /tmp/operator-sdk-ready
# initialDelaySeconds: 4
# periodSeconds: 10
# failureThreshold: 1
env:
- name: WATCH_NAMESPACE
valueFrom:
@ -51,3 +53,6 @@ spec:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "che-operator"
restartPolicy: Always
serviceAccountName: che-operator
terminationGracePeriodSeconds: 5

View File

@ -0,0 +1 @@
generated/

View File

@ -0,0 +1,27 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
rm -Rf "${BASE_DIR}/generated/roles"
mkdir -p "${BASE_DIR}/generated/roles"
roleYaml="${BASE_DIR}/../../deploy/role.yaml"
index=0
while [ $index -le 20 ]
do
if yq -r -e ".rules[${index}] | select(.apiGroups[0] == \"route.openshift.io\") | \"\"" "${roleYaml}"
then
yq -y "del(.rules[${index}])" "${roleYaml}" > "${BASE_DIR}/generated/roles/role.yaml"
exit $?
fi
((index++))
done
exit 1

View File

@ -0,0 +1,3 @@
role-path: generated/current-role.yaml
operator-path: ../../deploy/operator.yaml
crd-cr-paths: ["../../deploy/crds/org_v1_che_crd.yaml"]

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,7 @@
packageName: eclipse-che-preview-kubernetes
channels:
- name: stable
currentCSV: eclipse-che-preview-kubernetes.v7.0.0-rc-2.0
- name: nightly
currentCSV: eclipse-che-preview-kubernetes.v9.9.9-nightly.1562083645
defaultChannel: stable

View File

@ -0,0 +1,10 @@
apiVersion: operators.coreos.com/v1
kind: OperatorSource
metadata:
name: eclipse-che-preview-kubernetes
namespace: marketplace
spec:
authorizationToken: {}
endpoint: 'https://quay.io/cnr'
registryNamespace: eclipse-che-operator-kubernetes
type: appregistry

View File

@ -0,0 +1 @@
generated/

View File

@ -0,0 +1,17 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
rm -Rf "${BASE_DIR}/generated/roles"
mkdir -p "${BASE_DIR}/generated/roles"
cp "${BASE_DIR}/../../deploy/role.yaml" "${BASE_DIR}/generated/roles/role.yaml"
cp "${BASE_DIR}/../../deploy/cluster_role.yaml" "${BASE_DIR}/generated/roles/cluster_role.yaml"

View File

@ -0,0 +1,3 @@
operator-path: ../../deploy/operator.yaml
role-path: generated/current-role.yaml
crd-cr-paths: ["../../deploy/crds/org_v1_che_crd.yaml"]

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,15 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: checlusters.org.eclipse.che
spec:
group: org.eclipse.che
names:
kind: CheCluster
listKind: CheClusterList
plural: checlusters
singular: checluster
scope: Namespaced
version: v1
subresources:
status: {}

View File

@ -0,0 +1,7 @@
packageName: eclipse-che-preview-openshift
channels:
- name: stable
currentCSV: eclipse-che-preview-openshift.v7.0.0-rc-2.0
- name: nightly
currentCSV: eclipse-che-preview-openshift.v9.9.9-nightly.1561994908
defaultChannel: stable

View File

@ -0,0 +1,10 @@
apiVersion: operators.coreos.com/v1
kind: OperatorSource
metadata:
name: eclipse-che-preview-openshift
namespace: openshift-marketplace
spec:
authorizationToken: {}
endpoint: 'https://quay.io/cnr'
registryNamespace: eclipse-che-operator-openshift
type: appregistry

View File

@ -0,0 +1,85 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
set -e
CURRENT_DIR=$(pwd)
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
for platform in 'kubernetes' 'openshift'
do
packageName="eclipse-che-preview-${platform}"
echo
echo "## Preparing the OperatorHub package to push to the 'community-operators' repository for platform '${platform}' from local package '${packageName}'"
packageBaseFolderPath="${BASE_DIR}/${packageName}"
cd "${packageBaseFolderPath}"
packageFolderPath="${packageBaseFolderPath}/deploy/olm-catalog/${packageName}"
communityOperatorsLocalGitFolder="${packageBaseFolderPath}/generated/community-operators"
echo " - Cloning the 'community-operators' GitHub repository to temporary folder: ${communityOperatorsLocalGitFolder}"
rm -Rf "${communityOperatorsLocalGitFolder}"
mkdir -p "${communityOperatorsLocalGitFolder}"
git clone https://github.com/operator-framework/community-operators.git "${communityOperatorsLocalGitFolder}" 2>&1 | sed -e 's/^/ /'
branch="update-eclipse-che"
if [ "${platform}" == "kubernetes" ]
then
branch="${branch}-upstream"
fi
branch="${branch}-operator-$(date +%s)"
echo " - Creating branch '${branch}' in the local 'community-operators' repository: ${communityOperatorsLocalGitFolder}"
cd "${communityOperatorsLocalGitFolder}"
git checkout -b "${branch}" 2>&1 | sed -e 's/^/ /'
cd "${packageBaseFolderPath}"
platformSubFolder="community-operators"
if [ "${platform}" == "kubernetes" ]
then
platformSubFolder="upstream-${platformSubFolder}"
fi
folderToUpdate="${communityOperatorsLocalGitFolder}/${platformSubFolder}/eclipse-che"
sourcePackageFilePath="${packageFolderPath}/${packageName}.package.yaml"
destinationPackageFilePath="${folderToUpdate}/eclipse-che.package.yaml"
lastPackagePreReleaseVersion=$(yq -r '.channels[] | select(.name == "stable") | .currentCSV' "${sourcePackageFilePath}" | sed -e "s/${packageName}.v//")
lastPublishedPackageVersion=$(yq -r '.channels[] | select(.name == "final") | .currentCSV' "${destinationPackageFilePath}" | sed -e "s/eclipse-che.v//")
echo " - Last package pre-release version of local package: ${lastPackagePreReleaseVersion}"
echo " - Last package release version of cloned 'community-operators' repository: ${lastPackagePreReleaseVersion}"
if [ "${lastPackagePreReleaseVersion}" == "${lastPublishedPackageVersion}" ]
then
echo "#### ERROR ####"
echo "Release ${lastPackagePreReleaseVersion} already exists in the '${platformSubFolder}/eclipse-che' package !"
exit 1
fi
echo " => will create release '${lastPackagePreReleaseVersion}' in the following package folder :'${folderToUpdate}'"
sed \
-e "/^ replaces: ${packageName}.v.*/d" \
-e "/^ version: ${lastPackagePreReleaseVersion}/i\ \ replaces: eclipse-che.v${lastPublishedPackageVersion}" \
-e "s/${packageName}/eclipse-che/" \
"${packageFolderPath}/${lastPackagePreReleaseVersion}/${packageName}.v${lastPackagePreReleaseVersion}.clusterserviceversion.yaml" \
> "${folderToUpdate}/eclipse-che.v${lastPackagePreReleaseVersion}.clusterserviceversion.yaml"
echo " - Copying the CRD file"
cp "${packageFolderPath}/${lastPackagePreReleaseVersion}/${packageName}.crd.yaml" \
"${folderToUpdate}/eclipse-che.crd.yaml"
echo " - Updating the 'final' channel with new release in the package descriptor: ${destinationPackageFilePath}"
sed -e "s/${lastPublishedPackageVersion}/${lastPackagePreReleaseVersion}/" "${destinationPackageFilePath}" > "${destinationPackageFilePath}.new"
mv "${destinationPackageFilePath}.new" "${destinationPackageFilePath}"
done
cd "${CURRENT_DIR}"

72
olm/push-olm-files-to-quay.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
set -e
CURRENT_DIR=$(pwd)
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
for platform in 'kubernetes' 'openshift'
do
packageName="eclipse-che-preview-${platform}"
quayNamespace="eclipse-che-operator-${platform}"
echo
echo "## Pushing the OperatorHub package '${packageName}' for platform '${platform}' to the Quay.io '${quayNamespace}' organization"
packageBaseFolderPath="${BASE_DIR}/${packageName}"
cd "${packageBaseFolderPath}"
packageFolderPath="${packageBaseFolderPath}/deploy/olm-catalog/${packageName}"
flattenFolderPath="${packageBaseFolderPath}/generated/flatten"
echo " - Flatten package to temporary folder: ${flattenFolderPath}"
rm -Rf "${flattenFolderPath}"
mkdir -p "${flattenFolderPath}"
operator-courier flatten "${packageFolderPath}" generated/flatten
lastGitCommit=$(git log -n 1 --format="%h" -- .)
applicationVersion="9.9.$(date +%s)+${lastGitCommit}"
echo " - Push flattened files to Quay.io namespace '${quayNamespace}' as version ${applicationVersion}"
case ${platform} in
"kubernetes")
QUAY_USERNAME_PLATFORM_VAR="QUAY_USERNAME_K8S"
QUAY_PASSWORD_PLATFORM_VAR="QUAY_PASSWORD_K8S"
QUAY_USERNAME=${QUAY_USERNAME_K8S:-$QUAY_USERNAME}
QUAY_PASSWORD=${QUAY_PASSWORD_K8S:-$QUAY_PASSWORD}
;;
"openshift")
QUAY_USERNAME_PLATFORM_VAR="QUAY_USERNAME_OS"
QUAY_PASSWORD_PLATFORM_VAR="QUAY_PASSWORD_OS"
QUAY_USERNAME=${QUAY_USERNAME_OS:-$QUAY_USERNAME}
QUAY_PASSWORD=${QUAY_PASSWORD_OS:-$QUAY_PASSWORD}
;;
esac
if [ -z "${QUAY_USERNAME}" ] || [ -z "${QUAY_PASSWORD}" ]
then
echo "#### ERROR: "
echo "You should have set ${QUAY_USERNAME_PLATFORM_VAR} and ${QUAY_PASSWORD_PLATFORM_VAR} environment variables"
echo "with a user that has write access to the following Quay.io namespace: ${quayNamespace}"
echo "or QUAY_USERNAME and QUAY_PASSWORD if the same user can access both namespaces 'eclipse-che-operator-kubernetes' and 'eclipse-che-operator-openshift'"
exit 1
fi
AUTH_TOKEN=$(curl -sH "Content-Type: application/json" -XPOST https://quay.io/cnr/api/v1/users/login -d '
{
"user": {
"username": "'"${QUAY_USERNAME}"'",
"password": "'"${QUAY_PASSWORD}"'"
}
}' | jq -r '.token')
operator-courier push generated/flatten "${quayNamespace}" "${packageName}" "${applicationVersion}" "${AUTH_TOKEN}"
done
cd "${CURRENT_DIR}"

73
olm/release-olm-files.sh Executable file
View File

@ -0,0 +1,73 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
set -e
REGEX="^([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\-[0-9a-z-]+(\\.[0-9a-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
CURRENT_DIR=$(pwd)
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
if [[ "$1" =~ $REGEX ]]
then
RELEASE="$1"
else
echo "You should provide the new release as the first parameter"
echo "and it should be semver-compatible with optional *lower-case* pre-release part"
exit 1
fi
for platform in 'kubernetes' 'openshift'
do
packageName="eclipse-che-preview-${platform}"
echo
echo "## Creating release '${RELEASE}' of the OperatorHub package '${packageName}' for platform '${platform}'"
packageBaseFolderPath="${BASE_DIR}/${packageName}"
cd "${packageBaseFolderPath}"
packageFolderPath="${packageBaseFolderPath}/deploy/olm-catalog/${packageName}"
packageFilePath="${packageFolderPath}/${packageName}.package.yaml"
lastPackageNightlyVersion=$(yq -r '.channels[] | select(.name == "nightly") | .currentCSV' "${packageFilePath}" | sed -e "s/${packageName}.v//")
lastPackagePreReleaseVersion=$(yq -r '.channels[] | select(.name == "stable") | .currentCSV' "${packageFilePath}" | sed -e "s/${packageName}.v//")
echo " - Last package nightly version: ${lastPackageNightlyVersion}"
echo " - Last package pre-release version: ${lastPackagePreReleaseVersion}"
if [ "${lastPackagePreReleaseVersion}" == "${RELEASE}" ]
then
echo "Release ${RELEASE} already exists in the package !"
echo "You should first remove it"
exit 1
fi
echo " => will create release '${RELEASE}' from nightly version '${lastPackageNightlyVersion}' that will replace previous release '${lastPackagePreReleaseVersion}'"
mkdir -p "${packageFolderPath}/${RELEASE}"
sed \
-e 's/imagePullPolicy: *Always/imagePullPolicy: IfNotPresent/' \
-e 's/"cheImageTag": *"nightly"/"cheImageTag": ""/' \
-e 's|"identityProviderImage": *"eclipse/che-keycloak:nightly"|"identityProviderImage": ""|' \
-e "/^ replaces: ${packageName}.v.*/d" \
-e "s/^ version: ${lastPackageNightlyVersion}/ version: ${RELEASE}/" \
-e "/^ version: ${RELEASE}/i\ \ replaces: ${packageName}.v${lastPackagePreReleaseVersion}" \
-e "s/:nightly/:${RELEASE}/" \
-e "s/${lastPackageNightlyVersion}/${RELEASE}/" \
-e "s/createdAt:.*$/createdAt: \"$(date -u +%FT%TZ)\"/" \
"${packageFolderPath}/${lastPackageNightlyVersion}/${packageName}.v${lastPackageNightlyVersion}.clusterserviceversion.yaml" \
> "${packageFolderPath}/${RELEASE}/${packageName}.v${RELEASE}.clusterserviceversion.yaml"
echo " - Copying the CRD file"
cp "${packageFolderPath}/${lastPackageNightlyVersion}/${packageName}.crd.yaml" \
"${packageFolderPath}/${RELEASE}/${packageName}.crd.yaml"
echo " - Updating the 'stable' channel with new release in the package descriptor: ${packageFilePath}"
sed -e "s/${lastPackagePreReleaseVersion}/${RELEASE}/" "${packageFilePath}" > "${packageFilePath}.new"
mv "${packageFilePath}.new" "${packageFilePath}"
done
cd "${CURRENT_DIR}"

45
olm/update-nightly-olm-files.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
set -e
CURRENT_DIR=$(pwd)
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
for platform in 'kubernetes' 'openshift'
do
packageName=eclipse-che-preview-${platform}
echo
echo "## Updating OperatorHub package '${packageName}' for platform '${platform}'"
packageBaseFolderPath=${BASE_DIR}/${packageName}
cd "${packageBaseFolderPath}"
packageFolderPath="${packageBaseFolderPath}/deploy/olm-catalog/${packageName}"
packageFilePath="${packageFolderPath}/${packageName}.package.yaml"
lastPackageVersion=$(yq -r '.channels[] | select(.name == "nightly") | .currentCSV' "${packageFilePath}" | sed -e "s/${packageName}.v//")
echo " - Last package version: ${lastPackageVersion}"
newNightlyPackageVersion="9.9.9-nightly.$(date +%s)"
echo " => will create a new version: ${newNightlyPackageVersion}"
./build-roles.sh
for role in "$(pwd)"/generated/roles/*.yaml
do
echo " - Updating new package version with roles defined in: ${role}"
cp "$role" generated/current-role.yaml
operator-sdk olm-catalog gen-csv --csv-version "${newNightlyPackageVersion}" --from-version="${lastPackageVersion}" 2>&1 | sed -e 's/^/ /'
done
echo " - Copying the CRD file"
cp "${packageFolderPath}/${lastPackageVersion}/eclipse-che-preview-${platform}.crd.yaml" "${packageFolderPath}/${newNightlyPackageVersion}/eclipse-che-preview-${platform}.crd.yaml"
echo " - Updating the 'nightly' channel with new version in the package descriptor: ${packageFilePath}"
echo " (the previous one is saved with the .old suffix)"
sed -e "s/${lastPackageVersion}/${newNightlyPackageVersion}/" "${packageFilePath}" > "${packageFilePath}.new"
mv "${packageFilePath}" "${packageFilePath}.old"
mv "${packageFilePath}.new" "${packageFilePath}"
done
cd "${CURRENT_DIR}"

76
release-operator-code.sh Executable file
View File

@ -0,0 +1,76 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 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
set -e
REGEX="^([0-9]+)\\.([0-9]+)\\.([0-9]+)(\\-[0-9a-z-]+(\\.[0-9a-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
CURRENT_DIR=$(pwd)
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
if [[ "$1" =~ $REGEX ]]
then
RELEASE="$1"
else
echo "You should provide the new release as the first parameter"
echo "and it should be semver-compatible with optional *lower-case* pre-release part"
exit 1
fi
cd "${BASE_DIR}"
echo
echo "## Creating release '${RELEASE}' of the Che operator docker image"
lastDefaultCheVersion=$(grep 'DefaultCheServerImageTag' "pkg/deploy/defaults.go" | sed -e 's/.*DefaultCheServerImageTag *= *"\([^"]*\)"/\1/')
lastDefaultKeycloakVersion=$(grep 'DefaultKeycloakUpstreamImage' "pkg/deploy/defaults.go" | sed -e 's/.*DefaultKeycloakUpstreamImage *= *"[^":]*:\([^"]*\)"/\1/')
if [ "${lastDefaultCheVersion}" != "${lastDefaultKeycloakVersion}" ]
then
echo "#### ERROR ####"
echo "Current default Che version: ${lastDefaultCheVersion}"
echo "Current default Keycloak version: ${lastDefaultKeycloakVersion}"
echo "Current default version for Che and keycloak are not the same in file 'pkg/deploy/defaults.go'."
echo "Please fix that manually first !"
exit 1
fi
lastDefaultVersion="${lastDefaultCheVersion}"
echo " - Current default Che and Keycloak version: ${lastDefaultVersion}"
echo " - New version to apply as default Che and Keycloak version: ${RELEASE}"
if [ "${lastDefaultVersion}" == "${RELEASE}" ]
then
echo "Release ${RELEASE} already exists as the default in the Operator Go code !"
exit 1
fi
echo " => will update default Eclipse Che Keycloak docker image tags from '${lastDefaultVersion}' to '${RELEASE}'"
sed \
-e "s/\(.*DefaultCheServerImageTag *= *\"\)[^\"]*\"/\1${RELEASE}\"/" \
-e "s/\(.*DefaultKeycloakUpstreamImage *= *\"[^\":]*:\)[^\"]*\"/\1${RELEASE}\"/" \
pkg/deploy/defaults.go \
> pkg/deploy/defaults.go.new
mv pkg/deploy/defaults.go.new pkg/deploy/defaults.go
dockerImage="quay.io/eclipse/che-operator:${RELEASE}"
echo " - Building Che Operator docker image for new release ${RELEASE}"
docker build -t "quay.io/eclipse/che-operator:${RELEASE}" .
echo
echo "## Released Che operator docker image: ${dockerImage}"
echo "## Now you will probably want to:"
echo " - Push your '${dockerImage}' docker image"
echo " - Release the Che operator OLM packages with command:"
echo " ./olm/release-olm-files.sh ${RELEASE}"
echo " - Commit your changes"
echo " - Push the the Che operator OLM packages to Quay.io preview applications with command:"
echo " ./olm/push-olm-files-to-quay.sh ${RELEASE}"
cd "${CURRENT_DIR}"