Skip to content

Commit

Permalink
Add 2.0 migration script wrapper - upgrade-2.0 to Docker image (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek-sumo authored and pmalek committed Jan 13, 2021
1 parent c28d009 commit 2c6045a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ FROM alpine:3.12
ENV HELM_VERSION="3.4.2"
ENV YQ_VERSION="3.4.1"
ENV KUBECTL_VERSION="v1.18.14"
ENV UPGRADE_2_0_SCRIPT_URL="https://raw.githubusercontent.com/SumoLogic/sumologic-kubernetes-collection/main/deploy/helm/sumologic/upgrade-2.0.0.sh"
RUN set -ex \
&& apk update \
&& apk upgrade \
Expand All @@ -42,7 +43,9 @@ RUN set -ex \
&& curl -LJ https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -o /usr/bin/yq \
&& chmod +x /usr/bin/yq \
&& curl -LJ https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/bin/kubectl \
&& chmod +x /usr/bin/kubectl
&& chmod +x /usr/bin/kubectl \
&& curl -LJ "${UPGRADE_2_0_SCRIPT_URL}" -o /usr/local/bin/upgrade-2.0.0.sh \
&& chmod +x /usr/local/bin/upgrade-2.0.0.sh

COPY \
./src/ssh/motd \
Expand All @@ -56,6 +59,7 @@ COPY \
./src/commands/tools-usage \
./src/commands/template \
./src/commands/template-dependency \
./src/commands/upgrade-2.0 \
/usr/bin/

COPY ./src/commands/template-prometheus-mixin \
Expand Down
2 changes: 1 addition & 1 deletion ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function build_docker_image() {
}

function test_docker_image() {
local apps="stress-tester k8s-api-test receiver-mock check pvc-cleaner fix-log-symlinks tools-usage template template-dependency template-prometheus-mixin"
local apps="stress-tester k8s-api-test receiver-mock check pvc-cleaner fix-log-symlinks tools-usage template template-dependency template-prometheus-mixin upgrade-2.0"

echo
echo "Running docker image tests..."
Expand Down
63 changes: 63 additions & 0 deletions src/commands/upgrade-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -euo pipefail
IFS=$'\n\t'

readonly SCRIPT_PATH="/usr/local/bin/upgrade-2.0.0.sh"

function print_help() {
echo "2.0 k8s migration script."
echo "This script outputs migrated values file on stdout (and saves it in new_values.yaml in current working directory inside the container)."
echo "Logs produced by the migration script are available on stderr."
echo
echo "Usage:"
echo " upgrade-2.0 <VALUES_FILE.yaml>"
}

function err() {
echo "${1}" >&2
}

if [[ ${#} -ge 1 && "${1}" == "--help" ]]; then
print_help
exit 0
fi

FILE=""
if [[ ${#} -eq 0 ]]; then
readonly STDIN_WAIT_S="${STDIN_WAIT_S:-10}"
# Take data from stdin if available and put into temporary file
readonly TMPFILE="$(mktemp /tmp/values.yaml.XXXXXX)"
# Kubectl can take some time before stdin is available for reading
# thats why we check if just before it's required
if read -t "${STDIN_WAIT_S}" REPLY; then
# Save first line read from stdin
echo "${REPLY}" > "${TMPFILE}"
# Save rest of the stdin
cat <&0 >> "${TMPFILE}"
fi

if [[ ! -s "${TMPFILE}" ]]; then
err "Values file was not provided on stdin (or it was provided empty). Aborting."
exit 1
fi

FILE="${TMPFILE}"
else
FILE="${1}"
if [[ ! -f "${FILE}" ]]; then
err "Provided file \"${FILE}\" doesn't exist"
exit 1
fi
fi

# In case migration script fails we want to handle the error ourselves
set +e
"${SCRIPT_PATH}" "${FILE}" >&2
readonly EXIT_STATUS=$?
if [[ ${EXIT_STATUS} -ne 0 ]]; then
err "Upgrade script failed"
exit 1
fi

cat new_values.yaml

0 comments on commit 2c6045a

Please sign in to comment.