Skip to content

Commit 34031f6

Browse files
committed
Publish operator and bundle images for RedHat/OpenShift
Updating the build/release scripts to handle publishing the bundle images and running preflight on them. The publish-openshift script downloads the tagged release from DockerHub, retags it correctly for the RedHat scanning repo, pushes it, and finally runs the preflight check on it. The openshift-bundle script largely does the same, only it publishes the bundle image rather than the operator image. The same script is used for both the certified and marketplace bundles. Passing `MARKETPLACE=1` will use the marketplace bundle values rather than the certified ones (default).
1 parent 17a5811 commit 34031f6

5 files changed

+152
-106
lines changed

build/release/teamcity-publish-openshift-bundle.sh

+43-27
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,54 @@ set -euxo pipefail
1717

1818
source "$(dirname "${0}")/teamcity-support.sh"
1919

20+
# Default values are defined for the certified bundle.
21+
RH_PROJECT="5f5a433f9d6546ed7aa8634d"
22+
RH_REGISTRY="scan.connect.redhat.com"
23+
RH_REPO="ospid-857fe786-3eb7-4508-aafd-cc74c1b1dc24/cockroachdb-operator-bundle"
24+
BUNDLE_DIR="bundle/cockroachdb-certified"
2025

21-
tc_start_block "Variable Setup"
22-
VERSION="v"$(cat version.txt)
23-
# Matching the version name regex from within the cockroach code except
24-
# for the `metadata` part at the end because Docker tags don't support
25-
# `+` in the tag name.
26-
# https://github.com/cockroachdb/cockroach/blob/4c6864b44b9044874488cfedee3a31e6b23a6790/pkg/util/version/version.go#L75
27-
image_tag="$(echo "${VERSION}" | grep -E -o '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[-.0-9A-Za-z]+)?$')"
28-
# ^major ^minor ^patch ^preRelease
29-
30-
if [[ -z "$image_tag" ]] ; then
31-
echo "Invalid VERSION \"${VERSION}\". Must be of the format \"vMAJOR.MINOR.PATCH(-PRERELEASE)?\"."
32-
exit 1
26+
# If this is the marketplace bundle, update accordingly.
27+
if ! [[ -z "${MARKETPLACE}" ]]; then
28+
RH_PROJECT="61765afbdd607bfc82e643b8"
29+
RH_REPO="ospid-61765afbdd607bfc82e643b8/cockroachdb-operator-bundle-marketplace"
30+
BUNDLE_DIR="bundle/cockroachdb-certified-rhmp"
3331
fi
3432

35-
rhel_registry="scan.connect.redhat.com"
36-
rh_bundle_image_repository="ospid-857fe786-3eb7-4508-aafd-cc74c1b1dc24/cockroachdb-operator-bundle"
37-
image="$rhel_registry/$rh_bundle_image_repository:$image_tag"
33+
# If it's a dry run, add -dryrun to the image
34+
if ! [[ -z "${DRY_RUN}" ]]; then RH_REPO="${RH_REPO}-dryrun"; fi
3835

39-
if ! [[ -z "${DRY_RUN}" ]] ; then
40-
image="${image}-dryrun"
41-
fi
42-
tc_end_block "Variable Setup"
36+
IMAGE="${RH_REGISTRY}/${RH_REPO}:${TAG}"
37+
38+
main() {
39+
docker_login "${RH_REGISTRY}" "${OPERATOR_REDHAT_REGISTRY_USER}" "${OPERATOR_REDHAT_REGISTRY_KEY}"
40+
41+
generate_bundle
42+
publish_bundle_image
43+
run_preflight
44+
}
45+
46+
generate_bundle() {
47+
# create the certified and marketplace bundles
48+
tc_start_block "Generate bundle"
49+
make release/generate-bundle
50+
tc_end_block "Generate bundle"
51+
}
52+
53+
publish_bundle_image() {
54+
tc_start_block "Make and push bundle image"
4355

56+
pushd "${BUNDLE_DIR}"
57+
docker build -t "${IMAGE}" .
58+
docker push "${IMAGE}"
59+
popd
4460

45-
tc_start_block "Make and push docker images"
46-
configure_docker_creds
47-
docker_login "$rhel_registry" "$OPERATOR_BUNDLE_REDHAT_REGISTRY_USER" "$OPERATOR_BUNDLE_REDHAT_REGISTRY_KEY"
61+
tc_end_block "Make and push bundle image"
62+
}
4863

49-
# TODO(rail): switch to bazel generated images when it supports "FROM: scratch"
50-
cd deploy/certified-metadata-bundle/cockroach-operator
51-
docker build -t $image -f bundle.Dockerfile .
52-
docker push $image
64+
run_preflight() {
65+
bazel build //hack/bin:preflight
66+
PFLT_PYXIS_API_TOKEN="${REDHAT_API_TOKEN}" bazel-bin/hack/bin/preflight \
67+
check operator "${IMAGE}" --docker-config ~/.docker/config.json
68+
}
5369

54-
tc_end_block "Make and push docker images"
70+
main "$@"

build/release/teamcity-publish-openshift.sh

+31-34
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,38 @@ set -euxo pipefail
1717

1818
source "$(dirname "${0}")/teamcity-support.sh"
1919

20+
RH_PROJECT_ID="5e6027425c5456060d5f6084"
21+
RH_REGISTRY="scan.connect.redhat.com"
22+
RH_OPERATOR_IMG="${RH_REGISTRY}/ospid-cf721588-ad8a-4618-938c-5191c5e10ae4/cockroachdb-operator:${TAG}"
2023

21-
tc_start_block "Variable Setup"
22-
VERSION="v"$(cat version.txt)
23-
# Matching the version name regex from within the cockroach code except
24-
# for the `metadata` part at the end because Docker tags don't support
25-
# `+` in the tag name.
26-
# https://github.com/cockroachdb/cockroach/blob/4c6864b44b9044874488cfedee3a31e6b23a6790/pkg/util/version/version.go#L75
27-
image_tag="$(echo "${VERSION}" | grep -E -o '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[-.0-9A-Za-z]+)?$')"
28-
# ^major ^minor ^patch ^preRelease
29-
30-
if [[ -z "$image_tag" ]] ; then
31-
echo "Invalid VERSION \"${VERSION}\". Must be of the format \"vMAJOR.MINOR.PATCH(-PRERELEASE)?\"."
32-
exit 1
33-
fi
34-
35-
rhel_registry="scan.connect.redhat.com"
36-
37-
dh_operator_image="docker.io/cockroachdb/cockroach-operator:$image_tag"
38-
rh_operator_image_repository="$rhel_registry/ospid-cf721588-ad8a-4618-938c-5191c5e10ae4/cockroachdb-operator"
39-
24+
OPERATOR_IMG="docker.io/cockroachdb/cockroach-operator:${TAG}"
4025
if ! [[ -z "${DRY_RUN}" ]] ; then
41-
# The operator image doesn't use the "-dryrun" suffix, it's published in a
42-
# separate repository.
43-
dh_operator_image="docker.io/cockroachdb/cockroach-operator-misc:$image_tag"
44-
image_tag="${image_tag}-dryrun"
26+
OPERATOR_IMG="docker.io/cockroachdb/cockroach-operator-misc:${TAG}-dryrun"
4527
fi
46-
tc_end_block "Variable Setup"
47-
48-
49-
tc_start_block "Make and push docker images"
50-
configure_docker_creds
51-
docker_login "$rhel_registry" "$OPERATOR_REDHAT_REGISTRY_USER" "$OPERATOR_REDHAT_REGISTRY_KEY"
52-
53-
docker pull "$dh_operator_image"
54-
docker tag "$dh_operator_image" "$rh_operator_image_repository:$image_tag"
55-
docker push "$rh_operator_image_repository:$image_tag"
5628

57-
tc_end_block "Make and push docker images"
29+
main() {
30+
docker_login "${RH_REGISTRY}" "${OPERATOR_REDHAT_REGISTRY_USER}" "${OPERATOR_REDHAT_REGISTRY_KEY}"
31+
32+
publish_to_redhat
33+
run_preflight
34+
}
35+
36+
publish_to_redhat() {
37+
tc_start_block "Tag and release docker image"
38+
docker pull "${OPERATOR_IMG}"
39+
docker tag "${OPERATOR_IMG}" "${RH_OPERATOR_IMG}"
40+
docker push "${RH_OPERATOR_IMG}"
41+
tc_end_block "Tag and release docker image"
42+
}
43+
44+
run_preflight() {
45+
bazel build //hack/bin:preflight
46+
PFLT_PYXIS_API_TOKEN="${REDHAT_API_TOKEN}" bazel-bin/hack/bin/preflight \
47+
check container "${RH_OPERATOR_IMG}" \
48+
--certification-project-id="${RH_PROJECT_ID}" \
49+
--docker-config=/home/agent/.docker/config.json \
50+
--list-checks \
51+
--submit
52+
}
53+
54+
main "$@"

build/release/teamcity-publish-release.sh

+41-41
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,45 @@ set -euxo pipefail
1717

1818
source "$(dirname "${0}")/teamcity-support.sh"
1919

20-
tc_start_block "Variable Setup"
21-
VERSION="v"$(cat version.txt)
22-
# Matching the version name regex from within the cockroach code except
23-
# for the `metadata` part at the end because Docker tags don't support
24-
# `+` in the tag name.
25-
# https://github.com/cockroachdb/cockroach/blob/4c6864b44b9044874488cfedee3a31e6b23a6790/pkg/util/version/version.go#L75
26-
image_tag="$(echo "${VERSION}" | grep -E -o '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[-.0-9A-Za-z]+)?$')"
27-
# ^major ^minor ^patch ^preRelease
28-
29-
if [[ -z "$image_tag" ]] ; then
30-
echo "Invalid VERSION \"${VERSION}\". Must be of the format \"vMAJOR.MINOR.PATCH(-PRERELEASE)?\"."
31-
exit 1
32-
fi
33-
34-
docker_registry="docker.io"
35-
operator_image_repository="cockroachdb/cockroach-operator"
36-
37-
if ! [[ -z "${DRY_RUN}" ]] ; then
38-
operator_image_repository="cockroachdb/cockroach-operator-misc"
39-
fi
40-
41-
tc_end_block "Variable Setup"
42-
43-
tc_start_block "Make and push docker images"
44-
configure_docker_creds
45-
docker_login "$docker_registry" "$OPERATOR_DOCKER_ID" "$OPERATOR_DOCKER_ACCESS_TOKEN"
46-
47-
if docker_image_exists "$docker_registry/$operator_image_repository:$image_tag"; then
48-
echo "Docker image $docker_registry/$operator_image_repository:$image_tag already exists"
49-
if [[ -z "${FORCE}" ]] ; then
50-
echo "Use FORCE=1 to force push the docker image."
51-
echo "Alternatively you can delete the tag in Docker Hub."
52-
exit 1
20+
REGISTRY="docker.io"
21+
REPO="cockroachdb/cockroach-operator"
22+
if ! [[ -z "${DRY_RUN}" ]] ; then REPO="${REPO}-misc"; fi
23+
24+
OPERATOR_IMG="${REGISTRY}/${REPO}:${TAG}"
25+
26+
main() {
27+
docker_login "${REGISTRY}" "${OPERATOR_DOCKER_ID}" "${OPERATOR_DOCKER_ACCESS_TOKEN}"
28+
29+
validate_image
30+
publish_to_registry
31+
}
32+
33+
validate_image() {
34+
tc_start_block "Ensure image should be pushed"
35+
36+
if docker_image_exists "${OPERATOR_IMG}"; then
37+
echo "Docker image ${OPERATOR_IMG} already exists!"
38+
39+
if [[ -z "${FORCE}" ]] ; then
40+
echo "Use FORCE=1 to force push the docker image."
41+
echo "Alternatively you can delete the tag in Docker Hub."
42+
exit 1
43+
fi
44+
echo "Forcing docker push..."
5345
fi
54-
echo "Forcing docker push..."
55-
fi
56-
57-
make \
58-
DOCKER_REGISTRY="$docker_registry" \
59-
DOCKER_IMAGE_REPOSITORY="$operator_image_repository" \
60-
release/image
61-
tc_end_block "Make and push docker images"
46+
47+
tc_end_block "Ensure image should be pushed"
48+
}
49+
50+
publish_to_registry() {
51+
tc_start_block "Make and push docker image"
52+
53+
make \
54+
DOCKER_REGISTRY="${REGISTRY}" \
55+
DOCKER_IMAGE_REPOSITORY="${REPO}" \
56+
release/image
57+
58+
tc_end_block "Make and push docker image"
59+
}
60+
61+
main "$@"

build/release/teamcity-support.sh

+30-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Set below with call to ensure_valid_tag
16+
export TAG=""
17+
1518
# Common helpers for teamcity-*.sh scripts.
1619

1720
remove_files_on_exit() {
@@ -29,10 +32,12 @@ tc_end_block() {
2932
}
3033

3134
docker_login() {
32-
local registry=$1
33-
local registry_user=$2
34-
local registry_token=$3
35-
echo "${registry_token}" | docker login --username "${registry_user}" --password-stdin $registry
35+
configure_docker_creds
36+
37+
local registry="${1}"
38+
local registry_user="${2}"
39+
local registry_token="${3}"
40+
echo "${registry_token}" | docker login --username "${registry_user}" --password-stdin "${registry}"
3641
}
3742

3843
configure_docker_creds() {
@@ -55,3 +60,24 @@ docker_image_exists() {
5560
docker pull "$1"
5661
return $?
5762
}
63+
64+
ensure_valid_tag() {
65+
tc_start_block "Extracting image tag"
66+
local version="v$(cat version.txt)"
67+
68+
# Matching the version name regex from within the cockroach code except
69+
# for the `metadata` part at the end because Docker tags don't support
70+
# `+` in the tag name.
71+
# https://github.com/cockroachdb/cockroach/blob/4c6864b44b9044874488cfedee3a31e6b23a6790/pkg/util/version/version.go#L75
72+
TAG="$(echo -n "${version}" | grep -E -o '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[-.0-9A-Za-z]+)?$')"
73+
# ^major ^minor ^patch ^preRelease
74+
75+
if [[ -z "${TAG}" ]] ; then
76+
echo "Invalid VERSION \"${version}\". Must be of the format \"vMAJOR.MINOR.PATCH(-PRERELEASE)?\"."
77+
exit 1
78+
fi
79+
80+
tc_end_block "Extracting image tag"
81+
}
82+
83+
ensure_valid_tag

hack/bundle.sh

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ generate_bundle() {
8989

9090
# Update CSV with correct images, and timestamps
9191
adapt_csv "${dir}" "${img}"
92+
93+
# move the dockerfile into the bundle directory and make it valid
94+
sed \
95+
-e "s+${dir}/++g" bundle.Dockerfile \ # fix up paths
96+
-e "/\s*COPY tests/d" > "${dir}/Dockerfile" # remove scorecard tests
97+
98+
rm bundle.Dockerfile
9299
}
93100

94101
adapt_csv() {

0 commit comments

Comments
 (0)