Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
*: rework scripts to reuse code and easily add new versions
Browse files Browse the repository at this point in the history
Uses bash functions to a VERSIONS file to make it easier to just add new
Ceph versions instead of having to duplicate the same script over and
over again.

Signed-off-by: Alexander Trost <galexrt@googlemail.com>
  • Loading branch information
galexrt committed Dec 12, 2022
1 parent cac2d10 commit 2cec24c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 58 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/docker-image-rebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ jobs:
- name: Build and Push the Docker image to DockerHub
run: |
src/build-push-container-imgs-quincy.sh
src/build-push-container-imgs-pacific.sh
src/build-push-container-imgs.sh
7 changes: 7 additions & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ceph versions to build images for
# See https://docs.ceph.com/en/latest/releases/index.html

# Ceph Pacific
v16
# Ceph Quincy
v17
2 changes: 0 additions & 2 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ RUN dnf install -y python3-pip xmlsec1 xmlsec1-nss xmlsec1-openssl && \
REMOVED_SIZE=$((INITIAL_SIZE - FINAL_SIZE)) && \
echo "Cleaning process removed ${REMOVED_SIZE}MB" && \
echo "Dropped container size from ${INITIAL_SIZE}MB to ${FINAL_SIZE}MB";


87 changes: 87 additions & 0 deletions src/_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

SCRIPT_DIR="$(dirname "${0}")"

REPO_QUAY_TAGS_PAGE_SIZE="${REPO_QUAY_TAGS_PAGE_SIZE:-50}"

# Usage: [VERSION_REGEX]
getCephPointRelease() {
VERSION_REGEX="${1}"
if [ -z "${VERSION_REGEX}" ]; then
echo "No argument given to getCephPointRelease (needed: version regex) ..."
return 1
fi
CEPH_POINT_RELEASE=$(curl -s -L \
"https://quay.io/api/v1/repository/ceph/ceph/tag?page_size=${REPO_QUAY_TAGS_PAGE_SIZE}" | \
jq -r '."tags"[].name' | \
sort -r --version-sort | \
grep "${VERSION_REGEX}" | \
head -n 1)
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to get the Ceph Point Release from quay.io API."
return 1
fi

if [ -z "${CEPH_POINT_RELEASE}" ]; then
echo "Empty Ceph point release found. quay.io/ceph/ceph repo doesn't seem to have a tag for version regex '${VERSION_REGEX}'"
exit 2
fi

echo "${CEPH_POINT_RELEASE}"
}

# Usage: [CEPH_POINT_RELEASE]
checkIfAlreadyExists() {
CEPH_POINT_RELEASE="${1}"
if [ -z "${CEPH_POINT_RELEASE}" ]; then
echo "No argument given to checkIfAlreadyExists (needed: ceph point release) ..."
return 2
fi

if curl -s "https://registry.hub.docker.com/v2/repositories/koorinc/koor-ceph-container/tags/?page_size=${REPO_QUAY_TAGS_PAGE_SIZE}" | jq -r '.results[].name' | grep -q "$CEPH_POINT_RELEASE"; then
return 0
fi

return 1
}

# Usage: [CEPH_POINT_RELEASE]
buildAndPushCephPointRelease() {
CEPH_POINT_RELEASE="${1}"
if [ -z "${CEPH_POINT_RELEASE}" ]; then
echo "No argument given to buildAndPushCephPointRelease (needed: ceph point release) ..."
return 1
fi

if checkIfAlreadyExists "${CEPH_POINT_RELEASE}"; then
echo "Container for ${CEPH_POINT_RELEASE} already available at koorinc's Docker Hub, skipping build."
return 0
fi

docker build \
--build-arg CEPH_POINT_RELEASE="${CEPH_POINT_RELEASE}" \
--file "${SCRIPT_DIR}/Dockerfile" \
--tag "${CONTAINER_REGISTRY}/${CONTAINER_REPO}:${CEPH_POINT_RELEASE}" \
.

docker push "${CONTAINER_REGISTRY}/${CONTAINER_REPO}:${CEPH_POINT_RELEASE}"
}

# Usage: [VERSION_REGEX]
buildAndPushCephWrapper() {
VERSION_REGEX="${1}"
if [ -z "${VERSION_REGEX}" ]; then
echo "No argument given to buildAndPushCephWrapper (needed: version regex) ..."
return 1
fi

CEPH_POINT_RELEASE=$(getCephPointRelease "$VERSION_REGEX")
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to get the Ceph Point Release"
return 1
fi

buildAndPushCephPointRelease "${CEPH_POINT_RELEASE}"
}
20 changes: 0 additions & 20 deletions src/build-push-container-imgs-base.sh

This file was deleted.

17 changes: 0 additions & 17 deletions src/build-push-container-imgs-pacific.sh

This file was deleted.

16 changes: 0 additions & 16 deletions src/build-push-container-imgs-quincy.sh

This file was deleted.

11 changes: 11 additions & 0 deletions src/build-push-container-imgs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -ex

# shellcheck disable=SC1091
source "$(dirname "${0}")/_common.sh"

while IFS= read -r VERSION; do
if ! buildAndPushCephWrapper "${VERSION}"; then
echo "Error during buildAndPushCephWrapper, exiting 1"
exit 1
fi
done < <(grep -Po '^[^\W]+' "${SCRIPT_DIR}/../VERSIONS")

0 comments on commit 2cec24c

Please sign in to comment.