-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaser.sh
executable file
·108 lines (86 loc) · 6.39 KB
/
releaser.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
#!/usr/bin/env bash
set +x
# WARNING: this script is used by the GitHub Actions automation and isn't necessarily designed to be consumed directly.
# set defaults that can be overridden
IMAGE_TAG=${TAG_FROM:-latest}
INSPECTION_TAG=${INSPECTION_TAG:-nightly}
BUNDLE_TAG=${BUNDLE_TAG:-nightly-head}
SGO_BUNDLE_RESULT_DIR=${SGO_BUNDLE_RESULT_DIR:-${GITHUB_WORKSPACE}/sgo-bundle}
STO_BUNDLE_RESULT_DIR=${STO_BUNDLE_RESULT_DIR:-${GITHUB_WORKSPACE}/sto-bundle}
SGO_BUNDLE_IMAGE_PATH=quay.io/infrawatch-operators/smart-gateway-operator-bundle
STO_BUNDLE_IMAGE_PATH=quay.io/infrawatch-operators/service-telemetry-operator-bundle
INDEX_IMAGE_PATH=quay.io/infrawatch-operators/infrawatch-catalog
INDEX_IMAGE_TAG=${INDEX_IMAGE_TAG:-nightly}
ARTIFACT_IMAGES=${ARTIFACT_IMAGES:-"sg-core sg-bridge prometheus-webhook-snmp service-telemetry-operator smart-gateway-operator"}
echo "SGO result dir: ${SGO_BUNDLE_RESULT_DIR}"
echo "STO result dir: ${STO_BUNDLE_RESULT_DIR}"
# login to quay.io registry so we can push bundles to infrawatch organization
echo "${QUAY_INFRAWATCH_PASSWORD}" | docker login -u="${QUAY_INFRAWATCH_USERNAME}" --password-stdin quay.io || exit
# tag existing artifacts for nightly reference
for IMAGE in ${ARTIFACT_IMAGES}; do
skopeo copy "docker://quay.io/infrawatch/${IMAGE}:${IMAGE_TAG}" "docker://quay.io/infrawatch/${IMAGE}:${INSPECTION_TAG}"
done
# login to quay.io registry so we can push bundles to infrawatch-operators organization
echo "${QUAY_INFRAWATCH_OPERATORS_PASSWORD}" | docker login -u="${QUAY_INFRAWATCH_OPERATORS_USERNAME}" --password-stdin quay.io || exit
# Smart Gateway Operator bundle creation
# -- Get hashes for images so they can be replaced in the bundle manifest for relatedImages
echo "-- Get Smart Gateway Operator image hash"
SG_OPERATOR_IMAGE_HASH=$(skopeo inspect docker://quay.io/infrawatch/smart-gateway-operator:"${INSPECTION_TAG}" | jq -c '.Digest' | sed -e 's/^"//' -e 's/"$//' -)
echo "## Smart gateway operator image hash: ${SG_OPERATOR_IMAGE_HASH}"
echo "-- Get sg-core image hash"
SG_CORE_IMAGE_HASH=$(skopeo inspect docker://quay.io/infrawatch/sg-core:"${INSPECTION_TAG}" | jq -c '.Digest' | sed -e 's/^"//' -e 's/"$//' -)
echo "## sg-core image hash: ${SG_CORE_IMAGE_HASH}"
echo "-- Get sg-bridge image hash"
SG_BRIDGE_IMAGE_HASH=$(skopeo inspect docker://quay.io/infrawatch/sg-bridge:"${INSPECTION_TAG}" | jq -c '.Digest' | sed -e 's/^"//' -e 's/"$//' -)
echo "## sg-bridge image hash: ${SG_BRIDGE_IMAGE_HASH}"
echo "-- Create Smart Gateway Operator bundle"
pushd "${GITHUB_WORKSPACE}/smart-gateway-operator/" || exit
mkdir "${SGO_BUNDLE_RESULT_DIR}"
WORKING_DIR=${SGO_BUNDLE_RESULT_DIR} ./build/generate_bundle.sh
popd || exit
echo "-- Replace tag with hash for image paths in Smart Gateway Operator"
sed -i "s#quay.io/infrawatch/smart-gateway-operator:${INSPECTION_TAG}#quay.io/infrawatch/smart-gateway-operator@${SG_OPERATOR_IMAGE_HASH}#g" "${SGO_BUNDLE_RESULT_DIR}/manifests/smart-gateway-operator.clusterserviceversion.yaml"
sed -i "s#quay.io/infrawatch/sg-core:${INSPECTION_TAG}#quay.io/infrawatch/sg-core@${SG_CORE_IMAGE_HASH}#g" "${SGO_BUNDLE_RESULT_DIR}/manifests/smart-gateway-operator.clusterserviceversion.yaml"
sed -i "s#quay.io/infrawatch/sg-bridge:${INSPECTION_TAG}#quay.io/infrawatch/sg-bridge@${SG_BRIDGE_IMAGE_HASH}#g" "${SGO_BUNDLE_RESULT_DIR}/manifests/smart-gateway-operator.clusterserviceversion.yaml"
# Service Telemetry Operator bundle creation
# -- Get hashes for images so they can be replaced in the bundle manifest for relatedImages
echo "-- Get Service Telemetry Operator image hash"
ST_OPERATOR_IMAGE_HASH=$(skopeo inspect docker://quay.io/infrawatch/service-telemetry-operator:"${INSPECTION_TAG}" | jq -c '.Digest' | sed -e 's/^"//' -e 's/"$//' -)
echo "## Service telemetry operator image hash: ${ST_OPERATOR_IMAGE_HASH}"
echo "-- Get Prometheus Webhook SNMP image hash"
PROMETHEUS_WEBHOOK_SNMP_IMAGE_HASH=$(skopeo inspect docker://quay.io/infrawatch/prometheus-webhook-snmp:"${INSPECTION_TAG}" | jq -c '.Digest' | sed -e 's/^"//' -e 's/"$//' -)
echo "## Prometheus webhook SNMP image hash: ${PROMETHEUS_WEBHOOK_SNMP_IMAGE_HASH}"
echo "-- Create Service Telemetry Operator bundle"
pushd "${GITHUB_WORKSPACE}/service-telemetry-operator/" || exit
mkdir "${STO_BUNDLE_RESULT_DIR}"
WORKING_DIR=${STO_BUNDLE_RESULT_DIR} ./build/generate_bundle.sh
popd || exit
echo "-- Replace tag with hash for image paths for Service Telemetry Operator"
sed -i "s#quay.io/infrawatch/service-telemetry-operator:${INSPECTION_TAG}#quay.io/infrawatch/service-telemetry-operator@${ST_OPERATOR_IMAGE_HASH}#g" "${STO_BUNDLE_RESULT_DIR}/manifests/service-telemetry-operator.clusterserviceversion.yaml"
sed -i "s#quay.io/infrawatch/prometheus-webhook-snmp:${INSPECTION_TAG}#quay.io/infrawatch/prometheus-webhook-snmp@${PROMETHEUS_WEBHOOK_SNMP_IMAGE_HASH}#g" "${STO_BUNDLE_RESULT_DIR}/manifests/service-telemetry-operator.clusterserviceversion.yaml"
# -- Validate, build, and push bundles
echo "-- Validate bundles"
for bundle in ${SGO_BUNDLE_RESULT_DIR} ${STO_BUNDLE_RESULT_DIR}
do
operator-sdk bundle validate "${bundle}"
done
echo "-- Build and push Smart Gateway Operator bundle image"
pushd "${SGO_BUNDLE_RESULT_DIR}" || exit
docker build --tag "${SGO_BUNDLE_IMAGE_PATH}:${BUNDLE_TAG}" --file Dockerfile .
SGO_BUNDLE_IMAGE_HASH=$(docker push "${SGO_BUNDLE_IMAGE_PATH}:${BUNDLE_TAG}" | sed -n -e 's/^.*\(sha256:.*\)\(size.*\)$/\1/p' | tr -d '[:space:]')
popd || exit
echo "-- Build and push Service Telemetry Operator bundle image"
pushd "${STO_BUNDLE_RESULT_DIR}" || exit
docker build --tag "${STO_BUNDLE_IMAGE_PATH}:${BUNDLE_TAG}" --file Dockerfile .
STO_BUNDLE_IMAGE_HASH=$(docker push "${STO_BUNDLE_IMAGE_PATH}:${BUNDLE_TAG}" | sed -n -e 's/^.*\(sha256:.*\)\(size.*\)$/\1/p' | tr -d '[:space:]')
popd || exit
echo "-- Build and push index image"
# check if a tag already exists
skopeo inspect --format "{{.Digest}}" "docker://${INDEX_IMAGE_PATH}:${INDEX_IMAGE_TAG}" > /dev/null 2>&1
status=$?
if [ $status -eq 0 ]; then
opm index add --build-tool docker --bundles "${SGO_BUNDLE_IMAGE_PATH}@${SGO_BUNDLE_IMAGE_HASH},${STO_BUNDLE_IMAGE_PATH}@${STO_BUNDLE_IMAGE_HASH}" --from-index "${INDEX_IMAGE_PATH}:${INDEX_IMAGE_TAG}" --tag "${INDEX_IMAGE_PATH}:${INDEX_IMAGE_TAG}" || exit
else
opm index add --build-tool docker --bundles "${SGO_BUNDLE_IMAGE_PATH}@${SGO_BUNDLE_IMAGE_HASH},${STO_BUNDLE_IMAGE_PATH}@${STO_BUNDLE_IMAGE_HASH}" --tag "${INDEX_IMAGE_PATH}:${INDEX_IMAGE_TAG}" || exit
fi
docker push "${INDEX_IMAGE_PATH}:${INDEX_IMAGE_TAG}" || exit