Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Helm Chart: Add imagelist to the helm chart (#3638)
Browse files Browse the repository at this point in the history
* Add imagelist generation

* Ensure patched files are removed. Add to concourse pipeline
  • Loading branch information
nwmac authored and richard-cox committed Jun 13, 2019
1 parent 696ef8a commit 86c1b06
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 74 deletions.
6 changes: 6 additions & 0 deletions deploy/ci/tasks/dev-releases/create-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ run:
IMAGE_TAG=${GIT_TAG}
cd ${STRATOS}/deploy/kubernetes/
patchHelmChart ${GIT_TAG} ${DOCKER_ORG} ${DOCKER_REGISTRY} ./console ${RELEASE_VERSION} ${VERSION}
# Generate Helm package
updateHelmDependency
# Generate imagelist
./imagelist-gen.sh ./console
# Package console Helm Chart
helm package console
cp console*.tgz ${ROOT_DIR}/helm-chart/console-helm-chart-${RELEASE_VERSION}-${COMMIT}.tgz
cd ${ROOT_DIR}/helm-chart/
Expand Down
175 changes: 101 additions & 74 deletions deploy/kubernetes/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#
#####

set -eu
set -u

CYAN="\033[96m"
YELLOW="\033[93m"
RESET="\033[0m"
BOLD="\033[1m"

# Set defaults
PROD_RELEASE=false
Expand All @@ -21,6 +26,7 @@ ADD_OFFICIAL_TAG="false"
TAG_LATEST="false"
NO_PUSH="true"
DOCKER_REG_DEFAULTS="true"

while getopts ":ho:r:t:Tclb:On" opt; do
case $opt in
h)
Expand Down Expand Up @@ -70,22 +76,48 @@ while getopts ":ho:r:t:Tclb:On" opt; do
done

echo
echo "PRODUCTION BUILD/RELEASE: ${PROD_RELEASE}"
echo "REGISTRY: ${DOCKER_REGISTRY}"
echo "ORG: ${DOCKER_ORG}"
echo "TAG: ${TAG}"
echo "BASE_IMAGE_TAG: ${BASE_IMAGE_TAG}"
printf "${CYAN}${BOLD}"

echo "==========================================================================="
echo "== Stratos Image and Helm Chart build =="
echo "==========================================================================="

printf "${RESET}${CYAN}"
echo
echo "PRODUCTION BUILD/RELEASE : ${PROD_RELEASE}"
echo "REGISTRY : ${DOCKER_REGISTRY}"
echo "ORG : ${DOCKER_ORG}"
echo "TAG : ${TAG}"
echo "BASE_IMAGE_TAG : ${BASE_IMAGE_TAG}"

printf "${RESET}"
echo

if [ "${NO_PUSH}" != "false" ]; then
echo "Images will NOT be pushed"
printf "${YELLOW}Images will ${BOLD}NOT${RESET}${YELLOW} be pushed${RESET}\n"
else
echo "Images will be pushed"
echo " REGISTRY: ${DOCKER_REGISTRY}"
echo " ORG: ${DOCKER_ORG}"
printf "${YELLOW}${BOLD}Images will be pushed${RESET}\n"
echo " REGISTRY : ${DOCKER_REGISTRY}"
echo " ORG : ${DOCKER_ORG}"
fi

echo
echo "Starting build"
printf "${CYAN}${BOLD}Starting build${RESET}\n"
echo

function log {
set +e
printf "${BOLD}${YELLOW}"
echo
echo "==========================================================================="
echo "$1"
echo "==========================================================================="
echo
printf "${RESET}"
set -e
}

set -e

# Copy values template
__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Expand All @@ -97,89 +129,70 @@ function patchAndPushImage {
DOCKER_FILE=${2}
FOLDER=${3}
TARGET=${4:-none}
PATCHED_DOCKER_FILE="${DOCKER_FILE}.patched"

patchDockerfile ${DOCKER_FILE} ${FOLDER}
buildAndPublishImage ${NAME} ${DOCKER_FILE} ${FOLDER} ${TARGET}
unPatchDockerfile ${DOCKER_FILE} ${FOLDER}
buildAndPublishImage ${NAME} "${PATCHED_DOCKER_FILE}" ${FOLDER} ${TARGET}

rm -rf ${FOLDER}/${PATCHED_DOCKER_FILE}
rm -rf ${FOLDER}/${PATCHED_DOCKER_FILE}.bak
}

function patchDockerfile {
DOCKER_FILE=${1}
FOLDER=${2}
PATCHED_DOCKER_FILE=${DOCKER_FILE}.patched

# Replace registry/organization
pushd ${FOLDER} > /dev/null 2>&1
pwd
ls
rm -rf ${PATCHED_DOCKER_FILE}
cp ${DOCKER_FILE} ${PATCHED_DOCKER_FILE}
if [ "${DOCKER_REG_DEFAULTS}" == "false" ]; then
sed -i.bak "s@splatform@${DOCKER_REGISTRY}/${DOCKER_ORG}@g" ${FOLDER}/${DOCKER_FILE}
sed -i.bak "s@splatform@${DOCKER_REGISTRY}/${DOCKER_ORG}@g" ${FOLDER}/${PATCHED_DOCKER_FILE}
fi
sed -i.bak "s/opensuse/${BASE_IMAGE_TAG}/g" ${FOLDER}/${DOCKER_FILE}
sed -i.bak "s/opensuse/${BASE_IMAGE_TAG}/g" ${FOLDER}/${PATCHED_DOCKER_FILE}
popd > /dev/null 2>&1

}

function unPatchDockerfile {
DOCKER_FILE=${1}
FOLDER=${2}

# Replace registry/organization
pushd ${FOLDER} > /dev/null 2>&1
pwd
if [ "${DOCKER_REG_DEFAULTS}" == "false" ]; then
sed -i.bak "s@${DOCKER_REGISTRY}/${DOCKER_ORG}@splatform@g" ${FOLDER}/${DOCKER_FILE}
fi
sed -i.bak "s/${BASE_IMAGE_TAG}/opensuse/g" ${FOLDER}/${DOCKER_FILE}
popd > /dev/null 2>&1
#
# MAIN -------------------------------------------------------------------------------------------
#

}
pushd "${STRATOS_PATH}" > /dev/null 2>&1
STRATOS_PATH="$(pwd)"
popd > /dev/null 2>&1
echo "Base path: ${STRATOS_PATH}"

function buildJetstream {
echo
echo "-- Building the Stratos Backend"
# cleanup output, intermediate artifacts
cleanup

echo
echo "-- Build & publish the runtime container image for the Console jetstream"
patchAndPushImage stratos-jetstream deploy/Dockerfile.bk "${STRATOS_PATH}" prod-build
}
# Clean any old patched docker files left if previously errored
# rm -rf ${STRATOS_PATH}/deploy/Dockerfile.*.patched
# rm -rf ${STRATOS_PATH}/deploy/Dockerfile.*.bak
# rm -rf ${STRATOS_PATH}/deploy/Dockerfile.*.patched.bak

function buildPostflightJob {
# Build the postflight container
echo
echo "-- Build & publish the runtime container image for the postflight job"
patchAndPushImage stratos-postflight-job deploy/Dockerfile.bk "${STRATOS_PATH}" postflight-job
}
updateTagForRelease

function buildMariaDb {
echo
echo "-- Building/publishing MariaDB"
# Download and retag image to save bandwidth
patchAndPushImage stratos-mariadb Dockerfile.mariadb "${STRATOS_PATH}/deploy/db"
}
# Build all of the components that make up the Console

function buildUI {
# Build and push an image based on the nginx container
echo
echo "-- Building/publishing the runtime container image for the Console web server"
# Download and retag image to save bandwidth
patchAndPushImage stratos-console deploy/Dockerfile.ui "${STRATOS_PATH}" prod-build
}
log "-- Build & publish the runtime container image for Jetstream (backend)"
patchAndPushImage stratos-jetstream deploy/Dockerfile.bk "${STRATOS_PATH}" prod-build

# MAIN ------------------------------------------------------
#
# Build the postflight container
log "-- Build & publish the runtime container image for the postflight job"
patchAndPushImage stratos-postflight-job deploy/Dockerfile.bk "${STRATOS_PATH}" postflight-job

# Set the path to the portal jetstream
STRATOS_PATH=${STRATOS_PATH}
# Build and push an image based on the mariab db container
log "-- Building/publishing MariaDB"
patchAndPushImage stratos-mariadb Dockerfile.mariadb "${STRATOS_PATH}/deploy/db"

# cleanup output, intermediate artifacts
cleanup

updateTagForRelease
# Build and push an image based on the nginx container (Front-end)
log "-- Building/publishing the runtime container image for the Console web server (frontend)"
patchAndPushImage stratos-console deploy/Dockerfile.ui "${STRATOS_PATH}" prod-build

# Build all of the components that make up the Console
buildJetstream
buildPostflightJob
buildMariaDb
buildUI
log "-- Building Helm Chart"

# Don't change the chart in the repo, copy it and modify it locally

Expand All @@ -200,15 +213,29 @@ sed -i.bak -e 's/organization: splatform/organization: '"${DOCKER_ORG}"'/g' valu
sed -i.bak -e 's/hostname: docker.io/hostname: '"${DOCKER_REGISTRY}"'/g' values.yaml

sed -i.bak -e 's/version: 0.1.0/version: '"${TAG}"'/g' Chart.yaml

sed -i.bak -e 's/appVersion: 0.1.0/appVersion: '"${TAG}"'/g' Chart.yaml
rm -rf *.bak

# Generate image list
echo ${STRATOS_PATH}
echo
${STRATOS_PATH}/deploy/kubernetes/imagelist-gen.sh .

popd > /dev/null

set +e

printf "${BOLD}${YELLOW}"
echo
echo "Build complete...."
echo "Registry: ${DOCKER_REGISTRY}"
echo "Org: ${DOCKER_ORG}"
echo "Tag: ${TAG}"
printf "${CYAN}"
echo " Registry : ${DOCKER_REGISTRY}"
echo " Org : ${DOCKER_ORG}"
echo " Tag : ${TAG}"
printf "${RESET}"

echo "To deploy using Helm, execute the following: "
echo "helm install helm-chart --namespace console --name my-console"
echo
echo "To deploy using Helm, execute the following:"
echo
echo " helm install helm-chart --namespace console --name my-console"
echo
23 changes: 23 additions & 0 deletions deploy/kubernetes/imagelist-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Colours
CYAN="\033[96m"
YELLOW="\033[93m"
RESET="\033[0m"
BOLD="\033[1m"

__DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

printf "${BOLD}${CYAN}Generating ${YELLOW}imagelist.txt${RESET}\n"
echo ""


CHART_FOLDER=${1}
pushd ${CHART_FOLDER} > /dev/null
helm template -f ${__DIRNAME}/imagelist.values.yaml ${CHART_FOLDER} | grep "image:" | grep --extended --only-matching '([^"/[:space:]]+/)?[^"/[:space:]]+/[^:[:space:]]+:[a-zA-Z0-9\._-]+' | sort | uniq | awk -F'/' '{print $2}' > imagelist.txt
popd > /dev/null

printf "${CYAN}"
cat ${CHART_FOLDER}/imagelist.txt
printf "${RESET}"
echo ""
8 changes: 8 additions & 0 deletions deploy/kubernetes/imagelist.values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Values to be used to render the Helm Chart to ensure we get the full list of images in the Chart

# i.e. with all features enabled

# Use empty docker repository so names are consistent
kube:
registry:
hostname:

0 comments on commit 86c1b06

Please sign in to comment.