diff --git a/.travis.yml b/.travis.yml index 0e31ca980d..92369dfb75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,11 +9,18 @@ before_install: - sudo curl https://github.com/mikefarah/yq/releases/download/3.2.1/yq_linux_amd64 -L -o /usr/local/bin/yq-3.2.1 - sudo chmod +x /usr/local/bin/yq-3.2.1 - sudo ln -s /usr/local/bin/yq-3.2.1 /usr/local/bin/yq - - sudo apt install shellcheck -script: bash ci/build.sh + - curl -Lo- https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.x86_64.tar.xz | tar -xJf - + - sudo cp shellcheck-v0.7.1/shellcheck /usr/local/bin + - rm -rf shellcheck-v0.7.1/ branches: only: - master - /^release-v\d+\.\d+$/ - /^v\d+\.\d+\.\d+$/ - /^v\d+\.\d+\.\d+-(alpha|beta|rc)\.\d+$/ +jobs: + include: + - stage: tests + script: bash ci/tests.sh + - stage: build + script: bash ci/build.sh diff --git a/ci/build.sh b/ci/build.sh index c2954982a3..fdb097894b 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -1,6 +1,8 @@ #!/bin/bash +# shellcheck disable=SC2154 VERSION="${TRAVIS_TAG:-0.0.0}" +# shellcheck disable=SC2154 VERSION="${VERSION#v}" : "${DOCKER_TAG:=sumologic/kubernetes-fluentd}" : "${DOCKER_USERNAME:=sumodocker}" @@ -18,126 +20,169 @@ function get_branch_to_checkout() { || echo "${TRAVIS_BRANCH}" } +function bundle_fluentd_plugin() { + local plugin_name="${1}" + local version="${2}" + # Strip everything after "-" (longest match) to avoid gem prerelease behavior + local gem_version="${version%%-*}" + + if [[ -z "${version}" ]] ; then + echo "Please provide the version when bundling fluentd plugins" + exit 1 + fi + pushd "${plugin_name}" || exit 1 + + echo "Building gem ${plugin_name} version ${gem_version} in $(pwd) ..." + sed -i.bak "s/0.0.0/${gem_version}/g" ./"${plugin_name}".gemspec + rm -f ./"${plugin_name}".gemspec.bak + + echo "Install bundler..." + bundle install + + echo "Build gem ${plugin_name} ${gem_version}..." + gem build "${plugin_name}" + mv ./*.gem ../deploy/docker/gems + popd || exit 1 +} + function bundle_fluentd_plugins() { local version="${1}" - if [[ "${version}" == "" ]] ; then + if [[ -z "${version}" ]] ; then echo "Please provide the version when bundling fluentd plugins" exit 1 fi - for i in ./fluent-plugin-*/ ; do - if [[ -d "${i}" ]]; then - ( - cd "${i}" || exit 1 - local plugin_name - plugin_name="$(basename "${i}")" - # Strip everything after "-" (longest match) to avoid gem prerelease behavior - local gem_version="${version%%-*}" - echo "Building gem ${plugin_name} version ${gem_version} in $(pwd) ..." - sed -i.bak "s/0.0.0/${gem_version}/g" ./"${plugin_name}".gemspec - rm -f ./"${plugin_name}".gemspec.bak - - echo "Install bundler..." - bundle install - - echo "Run unit tests..." - bundle exec rake - - echo "Build gem ${plugin_name} ${gem_version}..." - gem build "${plugin_name}" - mv ./*.gem ../deploy/docker/gems - ) - fi - done + find . -maxdepth 1 -name 'fluent-plugin-*' -type 'd' -print | + while read -r line; do + # Run tests in their own context + (bundle_fluentd_plugin "$(basename "${line}")" "${version}") || exit 1 + done } -# Set up Github -if [ -n "$GITHUB_TOKEN" ]; then +function set_up_github() { + local token="${1}" + local branch="${2}" + git config --global user.email "travis@travis-ci.org" git config --global user.name "Travis CI" - git remote add origin-repo "https://${GITHUB_TOKEN}@github.com/SumoLogic/sumologic-kubernetes-collection.git" > /dev/null 2>&1 + git remote add origin-repo "https://${token}@github.com/SumoLogic/sumologic-kubernetes-collection.git" > /dev/null 2>&1 git fetch --unshallow origin-repo - readonly branch_to_checkout="$(get_branch_to_checkout)" - echo "Checking out the ${branch_to_checkout} branch..." - git checkout "${branch_to_checkout}" -fi + readonly branch="$(get_branch_to_checkout)" + echo "Checking out the ${branch} branch..." + git checkout "${branch}" +} -## check the build script with shellcheck -## TODO: the "|| true" prevents the build from failing on shellcheck errors - to be removed -echo "Checking the build script with shellcheck..." -shellcheck ci/build.sh || true +function push_docker_image() { + local version="$1" + + echo "Tagging docker image ${DOCKER_TAG}:local with ${DOCKER_TAG}:${version}..." + docker tag "${DOCKER_TAG}:local" "${DOCKER_TAG}:${version}" + echo "Pushing docker image ${DOCKER_TAG}:${version}..." + echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin + docker push "${DOCKER_TAG}:${version}" +} + +function push_helm_chart() { + local version="$1" + + local sync_dir="${TRAVIS_BUILD_DIR}-helm-sync" + + echo "Pushing new Helm Chart release ${version}" + set -x + + git checkout -- . + sudo helm init --client-only + sudo helm repo add falcosecurity https://falcosecurity.github.io/charts + sudo helm repo add prometheus-community https://prometheus-community.github.io/helm-charts + + # due to helm repo index issue: https://github.com/helm/helm/issues/7363 + # we need to create new package in a different dir, merge the index and move the package back + mkdir -p "${sync_dir}" + sudo helm package deploy/helm/sumologic --dependency-update --version="${version}" --app-version="${version}" --destination "${sync_dir}" + + git fetch origin-repo + git checkout gh-pages + + sudo helm repo index --url https://sumologic.github.io/sumologic-kubernetes-collection/ --merge ./index.yaml "${sync_dir}" + + mv -f "${sync_dir}"/* . + rmdir "${sync_dir}" + + git add -A + git commit -m "Push new Helm Chart release ${version}" + git push --quiet origin-repo gh-pages + set +x +} + +function validate_changes_to_generated_files() { + local changes + local recent_author -# Check for invalid changes to generated yaml files (non-Tag builds) -# Exclude branches that start with "revert-" to allow reverts -if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_EVENT_TYPE" == "pull_request" ] && [[ ! "$TRAVIS_PULL_REQUEST_BRANCH" =~ ^revert- ]]; then # Check most recent commit author. If non-Travis, check for changes made to generated files recent_author=$(git log origin-repo/master..HEAD --format="%an" | grep -m1 "") - if echo "$recent_author" | grep -v -q -i "travis"; then + if echo "${recent_author}" | grep -v -q -i "travis"; then # NOTE(ryan, 2019-08-30): Append "|| true" to command to ignore non-zero exit code - changes=$(git log origin-repo/master..HEAD --name-only --format="" --author="$recent_author" | grep -i "fluentd-sumologic.yaml.tmpl\|fluent-bit-overrides.yaml\|prometheus-overrides.yaml\|falco-overrides.yaml") || true - if [ -n "$changes" ]; then - echo "Aborting due to manual changes detected in the following generated files: $changes" + changes=$(git log origin-repo/master..HEAD --name-only --format="" --author="${recent_author}" | grep -i "fluentd-sumologic.yaml.tmpl\|fluent-bit-overrides.yaml\|prometheus-overrides.yaml\|falco-overrides.yaml") || true + if [ -n "${changes}" ]; then + echo "Aborting due to manual changes detected in the following generated files: ${changes}" exit 1 fi fi -fi +} -# Test if template files are generated correctly for various values.yaml -echo "Test helm templates generation" -if ./tests/run.sh; then - echo "Helm templates generation test passed" -else - echo "Tracing templates generation test failed" - exit 1 -fi +function build_docker_image() { + local tag + local no_cache + tag="${1}" -# Test upgrade script -echo "Test upgrade script..." -if ./tests/upgrade_script/run.sh; then - echo "Upgrade Script test passed" -else - echo "Upgrade Script test failed" - exit 1 -fi + echo "Building docker image with ${tag}:local in $(pwd)..." + pushd ./deploy/docker || exit 1 + no_cache="--no-cache" + if [[ "${DOCKER_USE_CACHE}" == "true" ]]; then + no_cache="" + fi + docker build . -f ./Dockerfile -t "${tag}:local" ${no_cache:+"--no-cache"} + rm -f ./gems/*.gem + popd || exit 1 -bundle_fluentd_plugins "${VERSION}" || (echo "Failed bundling fluentd plugins" && exit 1) + echo "Test docker image locally..." + ruby deploy/test/test_docker.rb || exit 1 +} -echo "Building docker image with $DOCKER_TAG:local in $(pwd)..." -cd ./deploy/docker || exit 1 -no_cache="--no-cache" -if [[ "$DOCKER_USE_CACHE" == "true" ]]; then - no_cache="" -fi -docker build . -f ./Dockerfile -t "$DOCKER_TAG:local" ${no_cache:+"--no-cache"} -rm -f ./gems/*.gem -cd ../.. || exit 1 +function generate_overrides() { + local with_files + local prometheus_remote_write + local branch -echo "Test docker image locally..." -ruby deploy/test/test_docker.rb + branch="${1}" -# Check for changes that require re-generating overrides yaml files -if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then echo "Generating deployment yaml from helm chart..." echo "# This file is auto-generated." > deploy/kubernetes/fluentd-sumologic.yaml.tmpl sudo helm init --client-only sudo helm repo add falcosecurity https://falcosecurity.github.io/charts sudo helm repo add prometheus-community https://prometheus-community.github.io/helm-charts - cd deploy/helm/sumologic || exit 1 - sudo helm dependency update - cd ../../../ || exit 1 + sudo helm dependency update deploy/helm/sumologic # NOTE(ryan, 2019-11-06): helm template -execute is going away in Helm 3 so we will need to revisit this # https://github.com/helm/helm/issues/5887 with_files=$(find deploy/helm/sumologic/templates/ -maxdepth 1 -iname "*.yaml" | sed 's#deploy/helm/sumologic/templates#-x templates#g' | sed 's/yaml/yaml \\/g') - eval 'sudo helm template deploy/helm/sumologic $with_files --namespace "\$NAMESPACE" --name collection --set dryRun=true >> deploy/kubernetes/fluentd-sumologic.yaml.tmpl --set sumologic.endpoint="bogus" --set sumologic.accessId="bogus" --set sumologic.accessKey="bogus"' - - if [[ $(git diff deploy/kubernetes/fluentd-sumologic.yaml.tmpl) ]]; then - echo "Detected changes in 'fluentd-sumologic.yaml.tmpl', committing the updated version to $TRAVIS_PULL_REQUEST_BRANCH..." + # shellcheck disable=SC2086 + helm template deploy/helm/sumologic \ + ${with_files} \ + --namespace "\$NAMESPACE" \ + --name collection \ + --set dryRun=true >> deploy/kubernetes/fluentd-sumologic.yaml.tmpl \ + --set sumologic.endpoint="bogus" \ + --set sumologic.accessId="bogus" \ + --set sumologic.accessKey="bogus" + + if [[ -n $(git diff deploy/kubernetes/fluentd-sumologic.yaml.tmpl) ]]; then + echo "Detected changes in 'fluentd-sumologic.yaml.tmpl', committing the updated version to ${branch}..." git add deploy/kubernetes/fluentd-sumologic.yaml.tmpl git commit -m "Generate new 'fluentd-sumologic.yaml.tmpl'" - git push --quiet origin-repo "$TRAVIS_PULL_REQUEST_BRANCH" + git push --quiet origin-repo "${branch}" else echo "No changes in 'fluentd-sumologic.yaml.tmpl'." fi @@ -146,12 +191,22 @@ if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then echo "# This file is auto-generated." > deploy/kubernetes/setup-sumologic.yaml.tmpl with_files=$(find deploy/helm/sumologic/templates/setup/ -maxdepth 1 -iname "*.yaml" | sed 's#deploy/helm/sumologic/templates#-x templates#g' | sed 's/yaml/yaml \\/g') - eval 'sudo helm template deploy/helm/sumologic $with_files --namespace "\$NAMESPACE" --name collection --set dryRun=true >> deploy/kubernetes/setup-sumologic.yaml.tmpl --set sumologic.accessId="\$SUMOLOGIC_ACCESSID" --set sumologic.accessKey="\$SUMOLOGIC_ACCESSKEY" --set sumologic.collectorName="\$COLLECTOR_NAME" --set sumologic.clusterName="\$CLUSTER_NAME"' - if [[ $(git diff deploy/kubernetes/setup-sumologic.yaml.tmpl) ]]; then - echo "Detected changes in 'setup-sumologic.yaml.tmpl', committing the updated version to $TRAVIS_PULL_REQUEST_BRANCH..." + # shellcheck disable=SC2086 + helm template deploy/helm/sumologic \ + ${with_files} \ + --namespace "\$NAMESPACE" \ + --name collection \ + --set dryRun=true >> deploy/kubernetes/setup-sumologic.yaml.tmpl \ + --set sumologic.accessId="\$SUMOLOGIC_ACCESSID" \ + --set sumologic.accessKey="\$SUMOLOGIC_ACCESSKEY" \ + --set sumologic.collectorName="\$COLLECTOR_NAME" \ + --set sumologic.clusterName="\$CLUSTER_NAME" + + if [[ -n $(git diff deploy/kubernetes/setup-sumologic.yaml.tmpl) ]]; then + echo "Detected changes in 'setup-sumologic.yaml.tmpl', committing the updated version to ${branch}..." git add deploy/kubernetes/setup-sumologic.yaml.tmpl git commit -m "Generate new 'setup-sumologic.yaml.tmpl'" - git push --quiet origin-repo "$TRAVIS_PULL_REQUEST_BRANCH" + git push --quiet origin-repo "${branch}" else echo "No changes in 'setup-sumologic.yaml.tmpl'." fi @@ -182,75 +237,56 @@ if [ -n "$GITHUB_TOKEN" ] && [ "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then prometheus_remote_write="${prometheus_remote_write//&/\\&}" prometheus_remote_write="${prometheus_remote_write//$'\n'/\\n}" echo "// This file is autogenerated" > deploy/kubernetes/kube-prometheus-sumo-logic-mixin.libsonnet - sed "s#\[\/\*REMOTE_WRITE\*\/\]#$prometheus_remote_write#" ci/jsonnet-mixin.tmpl | sed 's#"http://$(CHART).$(NAMESPACE).svc.cluster.local:9888\/#$._config.sumologicCollectorSvc + "#g' | sed 's/+: /+: /' | sed -r 's/"(\w*)":/\1:/g' > deploy/kubernetes/kube-prometheus-sumo-logic-mixin.libsonnet + # shellcheck disable=SC2016 + sed "s#\[\/\*REMOTE_WRITE\*\/\]#${prometheus_remote_write}#" ci/jsonnet-mixin.tmpl \ + | sed 's#"http://$(CHART).$(NAMESPACE).svc.cluster.local:9888\/#$._config.sumologicCollectorSvc + "#g' \ + | sed 's/+: /+: /' \ + | sed -r 's/"(\w*)":/\1:/g' > deploy/kubernetes/kube-prometheus-sumo-logic-mixin.libsonnet echo "Copy falco section from 'values.yaml' to 'falco-overrides.yaml'" echo "# This file is auto-generated." > deploy/helm/falco-overrides.yaml # Copy lines of falco section and remove indention from values.yaml yq r deploy/helm/sumologic/values.yaml falco | yq d - enabled >> deploy/helm/falco-overrides.yaml - if [ "$(git diff deploy/helm/metrics-server-overrides.yaml)" ] || [ "$(git diff deploy/helm/fluent-bit-overrides.yaml)" ] || [ "$(git diff deploy/helm/prometheus-overrides.yaml)" ] || [ "$(git diff deploy/helm/falco-overrides.yaml)" ] || [ "$(git diff deploy/kubernetes/kube-prometheus-sumo-logic-mixin.libsonnet)" ]; then - echo "Detected changes in 'fluent-bit-overrides.yaml', 'prometheus-overrides.yaml', 'falco-overrides.yaml', or 'kube-prometheus-sumo-logic-mixin.libsonnet', committing the updated version to $TRAVIS_PULL_REQUEST_BRANCH..." + if [ -n "$(git diff deploy/helm/metrics-server-overrides.yaml)" ] || [ -n "$(git diff deploy/helm/fluent-bit-overrides.yaml)" ] || [ -n "$(git diff deploy/helm/prometheus-overrides.yaml)" ] || [ -n "$(git diff deploy/helm/falco-overrides.yaml)" ] || [ -n "$(git diff deploy/kubernetes/kube-prometheus-sumo-logic-mixin.libsonnet)" ]; then + echo "Detected changes in 'fluent-bit-overrides.yaml', 'prometheus-overrides.yaml', 'falco-overrides.yaml', or 'kube-prometheus-sumo-logic-mixin.libsonnet', committing the updated version to ${TRAVIS_PULL_REQUEST_BRANCH}..." git add deploy/helm/*-overrides.yaml git add deploy/kubernetes/kube-prometheus-sumo-logic-mixin.libsonnet git commit -m "Generate new overrides yaml/libsonnet file(s)." - git push --quiet origin-repo "$TRAVIS_PULL_REQUEST_BRANCH" + git push --quiet origin-repo "${branch}" else echo "No changes in the generated overrides files." fi -fi - -function push_docker_image() { - local version="$1" - - echo "Tagging docker image $DOCKER_TAG:local with $DOCKER_TAG:$version..." - docker tag "$DOCKER_TAG:local" "$DOCKER_TAG:$version" - echo "Pushing docker image $DOCKER_TAG:$version..." - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker push "$DOCKER_TAG:$version" } -function push_helm_chart() { - local version="$1" - - local sync_dir="${TRAVIS_BUILD_DIR}-helm-sync" - - echo "Pushing new Helm Chart release $version" - set -x - - git checkout -- . - sudo helm init --client-only - sudo helm repo add falcosecurity https://falcosecurity.github.io/charts - sudo helm repo add prometheus-community https://prometheus-community.github.io/helm-charts - - # due to helm repo index issue: https://github.com/helm/helm/issues/7363 - # we need to create new package in a different dir, merge the index and move the package back - mkdir -p "${sync_dir}" - sudo helm package deploy/helm/sumologic --dependency-update --version="${version}" --app-version="${version}" --destination "${sync_dir}" - - git fetch origin-repo - git checkout gh-pages +# Set up Github +if [ -n "${GITHUB_TOKEN}" ]; then + set_up_github "${GITHUB_TOKEN}" "$(get_branch_to_checkout)" +fi - sudo helm repo index --url https://sumologic.github.io/sumologic-kubernetes-collection/ --merge ./index.yaml "${sync_dir}" +# Check for invalid changes to generated yaml files (non-Tag builds) +# Exclude branches that start with "revert-" to allow reverts +if [ -n "${GITHUB_TOKEN}" ] && [ "${TRAVIS_EVENT_TYPE}" == "pull_request" ] && [[ ! "${TRAVIS_PULL_REQUEST_BRANCH}" =~ ^revert- ]]; then + validate_changes_to_generated_files || (echo "Aborting due to manual changes detected in generated files" && exit 1) +fi - mv -f "${sync_dir}"/* . - rmdir "${sync_dir}" +bundle_fluentd_plugins "${VERSION}" || (echo "Failed bundling fluentd plugins" && exit 1) +build_docker_image "${DOCKER_TAG}" || (echo "Error during building docker image" && exit 1) - git add -A - git commit -m "Push new Helm Chart release $version" - git push --quiet origin-repo gh-pages - set +x -} +# Check for changes that require re-generating overrides yaml files +if [ -n "${GITHUB_TOKEN}" ] && [ "${TRAVIS_EVENT_TYPE}" == "pull_request" ]; then + generate_overrides "${TRAVIS_PULL_REQUEST_BRANCH}" || (echo "Error generating override files" && exit 1) +fi -if [ -n "$DOCKER_PASSWORD" ] && [ -n "$TRAVIS_TAG" ]; then - push_docker_image "$VERSION" - push_helm_chart "$VERSION" +if [ -n "${DOCKER_PASSWORD}" ] && [ -n "${TRAVIS_TAG}" ]; then + push_docker_image "${VERSION}" + push_helm_chart "${VERSION}" -elif [ -n "$DOCKER_PASSWORD" ] && [[ "$TRAVIS_BRANCH" == "master" || "$TRAVIS_BRANCH" =~ ^release-v[0-9]+\.[0-9]+$ ]] && [ "$TRAVIS_EVENT_TYPE" == "push" ]; then +elif [ -n "${DOCKER_PASSWORD}" ] && [[ "${TRAVIS_BRANCH}" == "master" || "${TRAVIS_BRANCH}" =~ ^release-v[0-9]+\.[0-9]+$ ]] && [ "${TRAVIS_EVENT_TYPE}" == "push" ]; then dev_build_tag=$(git describe --tags --always) dev_build_tag=${dev_build_tag#v} - push_docker_image "$dev_build_tag" - push_helm_chart "$dev_build_tag" + push_docker_image "${dev_build_tag}" + push_helm_chart "${dev_build_tag}" else echo "Skip Docker pushing" diff --git a/ci/tests.sh b/ci/tests.sh new file mode 100755 index 0000000000..f94730b706 --- /dev/null +++ b/ci/tests.sh @@ -0,0 +1,75 @@ +#!/bin/bash +set -e + +VERSION="${TRAVIS_TAG:-0.0.0}" +VERSION="${VERSION#v}" + +readonly ROOT_DIR="$(dirname "$(dirname "${0}")")" +cd "${ROOT_DIR}" + +function test_fluentd_plugin() { + local plugin_name="${1}" + local version="${2}" + # Strip everything after "-" (longest match) to avoid gem prerelease behavior + local gem_version="${version%%-*}" + local result + + pushd "${plugin_name}" || exit 1 + + if [[ -z "${version}" ]] ; then + echo "Please provide the version when bundling fluentd plugins" + exit 1 + fi + + echo "Preparing gem ${plugin_name} version ${gem_version} in $(pwd) for testing ..." + sed -i.bak "s/0.0.0/${gem_version}/g" ./"${plugin_name}".gemspec + rm -f ./"${plugin_name}".gemspec.bak + + echo "Install bundler..." + bundle install + + echo "Run unit tests..." + bundle exec rake + + readonly result=$? + popd || exit 1 + if [ "${result}" -ne "0" ]; then + exit 1 + fi +} + +function test_fluentd_plugins() { + local version="${1}" + + if [[ -z "${version}" ]] ; then + echo "Please provide the version when bundling fluentd plugins" + exit 1 + fi + + find . -maxdepth 1 -name 'fluent-plugin-*' -type 'd' -print | + while read -r line; do + # Run tests in their own context + test_fluentd_plugin "$(basename "${line}")" "${version}" || exit 1 + done +} + +echo "Checking the bash scripts with shellcheck..." + find . ! -path '*deploy/helm/sumologic/conf/setup/setup.sh' ! -path "*/tmp/*" -name '*.sh' -type 'f' -print | + while read -r file; do + # Run tests in their own context + echo "Checking ${file} with shellcheck" + shellcheck --enable all "${file}" + done + +# Test if template files are generated correctly for various values.yaml +echo "Test helm templates generation" +./tests/run.sh || (echo "Failed testing templates" && exit 1) + +# Test upgrade script +echo "Test upgrade script..." +./tests/upgrade_script/run.sh || (echo "Failed testing upgrade script" && exit 1) + +# Test fluentd plugins +test_fluentd_plugins "${VERSION}" || (echo "Failed testing fluentd plugins" && exit 1) + +echo "DONE" diff --git a/deploy/docker/entrypoint.sh b/deploy/docker/entrypoint.sh index a4dcb7ef57..d3dc2ad888 100755 --- a/deploy/docker/entrypoint.sh +++ b/deploy/docker/entrypoint.sh @@ -2,10 +2,13 @@ #source vars if file exists DEFAULT=/etc/default/fluentd +ADDITIONAL_PLUGINS="${ADDITIONAL_PLUGINS:-}" +FLUENTD_CONF="${FLUENTD_CONF:-}" -if [ -r $DEFAULT ]; then +if [ -r "${DEFAULT}" ]; then set -o allexport - . $DEFAULT + # shellcheck disable=SC1090 + . "${DEFAULT}" set +o allexport fi @@ -16,11 +19,11 @@ fi # If user does not supply config file or plugins, use the default if [ "$1" = "fluentd" ]; then - if ! echo $@ | grep ' \-c' ; then - set -- "$@" -c /fluentd/etc/${FLUENTD_CONF} + if ! echo "$@" | grep ' \-c' ; then + set -- "$@" -c "/fluentd/etc/${FLUENTD_CONF}" fi - if ! echo $@ | grep ' \-p' ; then + if ! echo "$@" | grep ' \-p' ; then set -- "$@" -p /fluentd/plugins fi fi @@ -28,7 +31,7 @@ fi # Install custom plugins if specified by user if [ -n "${ADDITIONAL_PLUGINS}" ]; then for plugin in ${ADDITIONAL_PLUGINS}; do - gem install ${plugin} + gem install "${plugin}" done fi diff --git a/deploy/helm/sumologic/upgrade-1.0.0.sh b/deploy/helm/sumologic/upgrade-1.0.0.sh index 2156264962..75ce3a8b3f 100755 --- a/deploy/helm/sumologic/upgrade-1.0.0.sh +++ b/deploy/helm/sumologic/upgrade-1.0.0.sh @@ -126,10 +126,10 @@ readonly EXPECTED_PROMETHEUS_METRICS_CHANGES="/prometheus.metrics.state # https://slides.com/perk/how-to-train-your-bash#/41 readonly LOG_FILE="/tmp/$(basename "$0").log" -info() { echo -e "[INFO] $*" | tee -a "$LOG_FILE" >&2 ; } -warning() { echo -e "[WARNING] $*" | tee -a "$LOG_FILE" >&2 ; } -error() { echo -e "[ERROR] $*" | tee -a "$LOG_FILE" >&2 ; } -fatal() { echo -e "[FATAL] $*" | tee -a "$LOG_FILE" >&2 ; exit 1 ; } +info() { echo -e "[INFO] $*" | tee -a "${LOG_FILE}" >&2 ; } +warning() { echo -e "[WARNING] $*" | tee -a "${LOG_FILE}" >&2 ; } +error() { echo -e "[ERROR] $*" | tee -a "${LOG_FILE}" >&2 ; } +fatal() { echo -e "[FATAL] $*" | tee -a "${LOG_FILE}" >&2 ; exit 1 ; } function print_help_and_exit() { readonly MAN="Thank you for upgrading to v1.0.0 of the Sumo Logic Kubernetes Collection Helm chart. @@ -157,7 +157,7 @@ Returns: For more details, please refer to Migration steps and Changelog here: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/release-v1.0/deploy/docs/v1_migration_doc.md" - echo "$MAN" + echo "${MAN}" exit 0 } @@ -176,7 +176,7 @@ function compare_versions() { local no_lower_than="${1}" local app_version="${2}" - if [[ "$(printf '%s\n' "${app_version}" "$no_lower_than" | sort -V | head -n 1)" == "${no_lower_than}" ]]; then + if [[ "$(printf '%s\n' "${app_version}" "${no_lower_than}" | sort -V | head -n 1)" == "${no_lower_than}" ]]; then echo "pass" else echo "fail" @@ -206,19 +206,19 @@ function check_bash_version() { } function create_temp_file() { - echo -n > ${TEMP_FILE} + echo -n > "${TEMP_FILE}" } function migrate_customer_keys() { # Convert variables to arrays set +e - IFS=$'\n' read -r -d ' ' -a MAPPINGS <<< "$KEY_MAPPINGS" + IFS=$'\n' read -r -d ' ' -a MAPPINGS <<< "${KEY_MAPPINGS}" readonly MAPPINGS - IFS=$'\n' read -r -d ' ' -a MAPPINGS_MULTIPLE <<< "$KEY_MAPPINGS_MULTIPLE" + IFS=$'\n' read -r -d ' ' -a MAPPINGS_MULTIPLE <<< "${KEY_MAPPINGS_MULTIPLE}" readonly MAPPINGS_MULTIPLE - IFS=$'\n' read -r -d ' ' -a MAPPINGS_EMPTY <<< "$KEY_MAPPINGS_EMPTY" + IFS=$'\n' read -r -d ' ' -a MAPPINGS_EMPTY <<< "${KEY_MAPPINGS_EMPTY}" readonly MAPPINGS_EMPTY - IFS=$'\n' read -r -d ' ' -a CASTS_STRING <<< "$KEY_CASTS_STRING" + IFS=$'\n' read -r -d ' ' -a CASTS_STRING <<< "${KEY_CASTS_STRING}" readonly CASTS_STRING set -e @@ -231,8 +231,8 @@ function migrate_customer_keys() { IFS=':' read -r -a maps <<< "${i}" if [[ ${maps[0]} == "${key}" ]]; then info "Mapping ${key} into ${maps[1]}" - yq w -i ${TEMP_FILE} -- "${maps[1]}" "$(yq r "${OLD_VALUES_YAML}" -- "${maps[0]}")" - yq d -i ${TEMP_FILE} -- "${maps[0]}" + yq w -i "${TEMP_FILE}" -- "${maps[1]}" "$(yq r "${OLD_VALUES_YAML}" -- "${maps[0]}")" + yq d -i "${TEMP_FILE}" -- "${maps[0]}" fi done elif [[ ${MAPPINGS_MULTIPLE[*]} =~ ${key}: ]]; then @@ -243,25 +243,25 @@ function migrate_customer_keys() { if [[ ${maps[0]} == "${key}" ]]; then for element in "${maps[@]:1}"; do info "- ${element}" - yq w -i ${TEMP_FILE} -- "${element}" "$(yq r "${OLD_VALUES_YAML}" -- "${maps[0]}")" - yq d -i ${TEMP_FILE} -- "${maps[0]}" + yq w -i "${TEMP_FILE}" -- "${element}" "$(yq r "${OLD_VALUES_YAML}" -- "${maps[0]}")" + yq d -i "${TEMP_FILE}" -- "${maps[0]}" done fi done else - yq w -i ${TEMP_FILE} -- "${key}" "$(yq r "${OLD_VALUES_YAML}" -- "${key}")" + yq w -i "${TEMP_FILE}" -- "${key}" "$(yq r "${OLD_VALUES_YAML}" -- "${key}")" fi if [[ "${MAPPINGS_EMPTY[*]}" =~ ${key} ]]; then info "Removing ${key}" - yq d -i ${TEMP_FILE} -- "${key}" + yq d -i "${TEMP_FILE}" -- "${key}" fi if [[ "${CASTS_STRING[*]}" =~ ${key} ]]; then info "Casting ${key} to str" # As yq doesn't cast `on` and `off` from bool to cast, we use sed based casts - yq w -i ${TEMP_FILE} -- "${key}" "$(yq r "${OLD_VALUES_YAML}" "${key}")__YQ_REPLACEMENT_CAST" - sed -i.bak 's/\(^.*: \)\(.*\)__YQ_REPLACEMENT_CAST/\1"\2"/g' ${TEMP_FILE} + yq w -i "${TEMP_FILE}" -- "${key}" "$(yq r "${OLD_VALUES_YAML}" "${key}")__YQ_REPLACEMENT_CAST" + sed -i.bak 's/\(^.*: \)\(.*\)__YQ_REPLACEMENT_CAST/\1"\2"/g' "${TEMP_FILE}" fi done echo @@ -288,21 +288,21 @@ FILTER=" # Apply changes if required if [ "$(yq r "${OLD_VALUES_YAML}" -- sumologic.addStream)" == "false" ] || [ "$(yq r "${OLD_VALUES_YAML}" -- sumologic.addTime)" == "false" ]; then info "Creating fluentd.logs.containers.extraFilterPluginConf to preserve addStream/addTime functionality" - yq w -i ${TEMP_FILE} -- fluentd.logs.containers.extraFilterPluginConf "$FILTER" + yq w -i "${TEMP_FILE}" -- fluentd.logs.containers.extraFilterPluginConf "${FILTER}" fi } function migrate_pre_upgrade_hook() { # Keep pre-upgrade hook - if [[ -n "$(yq r ${TEMP_FILE} -- sumologic.setup)" ]]; then + if [[ -n "$(yq r "${TEMP_FILE}" -- sumologic.setup)" ]]; then info "Updating setup hooks (sumologic.setup.*.annotations[helm.sh/hook]) to 'pre-install,pre-upgrade'" - yq w -i ${TEMP_FILE} -- 'sumologic.setup.*.annotations[helm.sh/hook]' 'pre-install,pre-upgrade' + yq w -i "${TEMP_FILE}" -- 'sumologic.setup.*.annotations[helm.sh/hook]' 'pre-install,pre-upgrade' fi } function check_falco_state() { # Print information about falco state - if [[ "$(yq r ${TEMP_FILE} -- falco.enabled)" == 'true' ]]; then + if [[ "$(yq r "${TEMP_FILE}" -- falco.enabled)" == 'true' ]]; then info 'falco will be enabled. Change "falco.enabled" to "false" if you want to disable it (default for 1.0)' else info 'falco will be disabled. Change "falco.enabled" to "true" if you want to enable it' @@ -330,12 +330,12 @@ function migrate_prometheus_metrics() { metrics_length="$(yq r -l "${OLD_VALUES_YAML}" -- 'prometheus-operator.prometheus.prometheusSpec.remoteWrite')" metrics_length="$(( metrics_length - 1))" - for i in $(seq 0 ${metrics_length}); do + for i in $(seq 0 "${metrics_length}"); do metric_name="$(yq r "${OLD_VALUES_YAML}" -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].url" | grep -oE '/prometheus\.metrics.*' || true)" metric_regex_length="$(yq r -l "${OLD_VALUES_YAML}" -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs")" metric_regex_length="$(( metric_regex_length - 1))" - for j in $(seq 0 ${metric_regex_length}); do + for j in $(seq 0 "${metric_regex_length}"); do metric_regex_action=$(yq r "${OLD_VALUES_YAML}" -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].action") if [[ "${metric_regex_action}" = "keep" ]]; then break @@ -348,7 +348,7 @@ function migrate_prometheus_metrics() { regex_0_17="$(get_release_regex "${metric_name}" '^\s*\+' 'head')" regex="$(get_regex "${i}" "${j}")" if [[ "${regex_0_17}" = "${regex}" ]]; then - yq w -i ${TEMP_FILE} -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}" + yq w -i "${TEMP_FILE}" -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}" else warning "Changes of regex for 'prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}]' (${metric_name}) detected, please migrate it manually" fi @@ -359,12 +359,12 @@ function migrate_prometheus_metrics() { regex_0_17="$(get_release_regex "${metric_name}" '^\s*\+' 'head')" regex="$(get_regex "${i}" "${j}")" if [[ "${regex_0_17}" = "${regex}" ]]; then - yq w -i ${TEMP_FILE} -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}" + yq w -i "${TEMP_FILE}" -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}" else regex_1_0="$(get_release_regex "${metric_name}" '^\s*-' 'tail')" regex_0_17="$(get_release_regex "${metric_name}" '^\s*\+' 'tail')" if [[ "${regex_0_17}" = "${regex}" ]]; then - yq w -i ${TEMP_FILE} -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}" + yq w -i "${TEMP_FILE}" -- "prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}].regex" "${regex_1_0}" else warning "Changes of regex for 'prometheus-operator.prometheus.prometheusSpec.remoteWrite[${i}].writeRelabelConfigs[${j}]' (${metric_name}) detected, please migrate it manually" fi @@ -375,15 +375,15 @@ function migrate_prometheus_metrics() { function fix_fluentbit_env() { # Fix fluent-bit env - if [[ -n "$(yq r ${TEMP_FILE} -- fluent-bit.env)" ]]; then + if [[ -n "$(yq r "${TEMP_FILE}" -- fluent-bit.env)" ]]; then info "Patching fluent-bit CHART environmental variable" - yq w -i ${TEMP_FILE} -- "fluent-bit.env(name==CHART).valueFrom.configMapKeyRef.key" "fluentdLogs" + yq w -i "${TEMP_FILE}" -- "fluent-bit.env(name==CHART).valueFrom.configMapKeyRef.key" "fluentdLogs" fi } function fix_prometheus_service_monitors() { # Fix prometheus service monitors - if [[ -n "$(yq r ${TEMP_FILE} -- prometheus-operator.prometheus.additionalServiceMonitors)" ]]; then + if [[ -n "$(yq r "${TEMP_FILE}" -- prometheus-operator.prometheus.additionalServiceMonitors)" ]]; then info "Patching prometheus-operator.prometheus.additionalServiceMonitors" yq d -i "${TEMP_FILE}" -- "prometheus-operator.prometheus.additionalServiceMonitors(name==${HELM_RELEASE_NAME}-${NAMESPACE})" yq d -i "${TEMP_FILE}" -- "prometheus-operator.prometheus.additionalServiceMonitors(name==${HELM_RELEASE_NAME}-${NAMESPACE}-otelcol)" @@ -438,9 +438,9 @@ prometheus-operator: app: ${HELM_RELEASE_NAME}-${NAMESPACE}-fluentd-events" | yq m -a -i "${TEMP_FILE}" - fi - if [[ -n "$(yq r ${TEMP_FILE} -- prometheus-operator.prometheus.prometheusSpec.containers)" ]]; then + if [[ -n "$(yq r "${TEMP_FILE}" -- prometheus-operator.prometheus.prometheusSpec.containers)" ]]; then info "Patching prometheus CHART environmental variable" - yq w -i ${TEMP_FILE} -- "prometheus-operator.prometheus.prometheusSpec.containers(name==prometheus-config-reloader).env(name==CHART).valueFrom.configMapKeyRef.key" "fluentdMetrics" + yq w -i "${TEMP_FILE}" -- "prometheus-operator.prometheus.prometheusSpec.containers(name==prometheus-config-reloader).env(name==CHART).valueFrom.configMapKeyRef.key" "fluentdMetrics" fi } @@ -449,7 +449,7 @@ function check_user_image() { readonly USER_VERSION="$(yq r "${OLD_VALUES_YAML}" -- image.tag)" if [[ -n "${USER_VERSION}" ]]; then if [[ "${USER_VERSION}" =~ ^"${PREVIOUS_VERSION}"\.[[:digit:]]+$ ]]; then - yq w -i ${TEMP_FILE} -- image.tag 1.0.0 + yq w -i "${TEMP_FILE}" -- image.tag 1.0.0 info "Changing image.tag from '${USER_VERSION}' to '1.0.0'" else warning "You are using unsupported version: ${USER_VERSION}" @@ -459,30 +459,30 @@ function check_user_image() { } function migrate_fluentbit_db_path() { - grep 'tail-db/tail-containers-state.db' ${TEMP_FILE} 1>/dev/null 2>&1 || return 0 + grep 'tail-db/tail-containers-state.db' "${TEMP_FILE}" 1>/dev/null 2>&1 || return 0 # New fluent-bit db path info 'Replacing tail-db/tail-containers-state.db to tail-db/tail-containers-state-sumo.db' warning 'Please ensure that new fluent-bit configuration is correct' - sed -i.bak 's?tail-db/tail-containers-state.db?tail-db/tail-containers-state-sumo.db?g' ${TEMP_FILE} + sed -i.bak 's?tail-db/tail-containers-state.db?tail-db/tail-containers-state-sumo.db?g' "${TEMP_FILE}" } function fix_yq() { # account for yq bug that stringifies empty maps - sed -i.bak "s/'{}'/{}/g" ${TEMP_FILE} + sed -i.bak "s/'{}'/{}/g" "${TEMP_FILE}" } function rename_temp_file() { - mv ${TEMP_FILE} new_values.yaml + mv "${TEMP_FILE}" new_values.yaml } function cleanup_bak_file() { - rm ${TEMP_FILE}.bak + rm "${TEMP_FILE}.bak" } function echo_footer() { DONE="\nThank you for upgrading to v1.0.0 of the Sumo Logic Kubernetes Collection Helm chart.\nA new yaml file has been generated for you. Please check the current directory for new_values.yaml." - echo -e "$DONE" + echo -e "${DONE}" } check_if_print_help_and_exit "${OLD_VALUES_YAML}" diff --git a/tests/functions.sh b/tests/functions.sh index 27124918ef..547d151fc0 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -1,5 +1,8 @@ #!/bin/bash + +TEST_TEMPLATE="${TEST_TEMPLATE:-}" + function test_start() { echo -e "[.] $*"; } diff --git a/tests/run.sh b/tests/run.sh index b697fb4734..ad8aa090a6 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,7 +1,8 @@ #!/bin/bash -readonly SCRIPT_PATH="$( dirname $(realpath ${0}) )" +readonly SCRIPT_PATH="$( dirname "$(realpath "${0}")" )" readonly CONFIG_FILES=$(find "${SCRIPT_PATH}"/* -maxdepth 1 -name 'config.sh') +# shellcheck disable=SC1090 source "${SCRIPT_PATH}/functions.sh" export TEST_SUCCESS=true @@ -9,8 +10,9 @@ export TEST_SUCCESS=true prepare_environment "${SCRIPT_PATH}/../deploy/helm/sumologic" for config_file in ${CONFIG_FILES}; do - test_dir="$( dirname $(realpath ${config_file}) )" + test_dir="$( dirname "$(realpath "${config_file}")" )" echo "Performing tests for $(basename "${test_dir}")" + # shellcheck disable=SC1090 source "${config_file}" set_variables "${test_dir}" prepare_tests diff --git a/tests/upgrade_script/run.sh b/tests/upgrade_script/run.sh index 81eb2f3c50..63b5373b99 100755 --- a/tests/upgrade_script/run.sh +++ b/tests/upgrade_script/run.sh @@ -7,17 +7,24 @@ # 1> tests/upgrade_script/static/${test_name}.log 2>&1 \ # && cp new_values.yaml tests/upgrade_script/static/${test_name}.output.yaml -SCRIPT_PATH="$( dirname "$(realpath ${0})" )" +SCRIPT_PATH="$( dirname "$(realpath "${0}")" )" +# shellcheck disable=SC1090 source "${SCRIPT_PATH}/../functions.sh" readonly TEST_TMP_OUT="${SCRIPT_PATH}/tmp/out.log" set_variables "${SCRIPT_PATH}" +# reassign variables from set_variables +TEST_SCRIPT_PATH="${TEST_SCRIPT_PATH}" +TEST_STATICS_PATH="${TEST_STATICS_PATH}" +TEST_INPUT_FILES="${TEST_INPUT_FILES}" +TEST_OUT="${TEST_OUT}" + prepare_tests TEST_SUCCESS=true for input_file in ${TEST_INPUT_FILES}; do - test_name="$(echo "${input_file}" | sed -e 's/.input.yaml$//g')" + test_name="${input_file//.input.yaml/}" output_file="${test_name}.output.yaml" log_file="${test_name}.log" diff --git a/vagrant/Makefile b/vagrant/Makefile index 2a815ba1f1..80874ea3aa 100755 --- a/vagrant/Makefile +++ b/vagrant/Makefile @@ -14,6 +14,9 @@ local_values_file = ${root_dir}vagrant/values.local.yaml name = collection namespace = sumologic +test: + ${root_dir}ci/tests.sh + build: cd ${root_dir} && DOCKER_USE_CACHE=true ${root_dir}ci/build.sh ${mkfile_path} \ diff --git a/vagrant/forwarding/forward-dashboard.sh b/vagrant/forwarding/forward-dashboard.sh index 4198f5d726..c7146cb893 100755 --- a/vagrant/forwarding/forward-dashboard.sh +++ b/vagrant/forwarding/forward-dashboard.sh @@ -2,4 +2,4 @@ DASHBOARD_POD="$(kubectl get pods --all-namespaces | grep -i kubernetes-dashboard | awk '{print $2}')" -kubectl -n kube-system port-forward $DASHBOARD_POD --address 0.0.0.0 8443:8443 +kubectl -n kube-system port-forward "${DASHBOARD_POD}" --address 0.0.0.0 8443:8443 diff --git a/vagrant/forwarding/forward-prometheus.sh b/vagrant/forwarding/forward-prometheus.sh index a74c41ce91..b0c64f37cb 100755 --- a/vagrant/forwarding/forward-prometheus.sh +++ b/vagrant/forwarding/forward-prometheus.sh @@ -2,4 +2,4 @@ PROM_POD="$(kubectl get pods --all-namespaces | grep -i prometheus-0 | awk '{print $2}')" -kubectl -n sumologic port-forward $PROM_POD --address 0.0.0.0 9090:9090 +kubectl -n sumologic port-forward "${PROM_POD}" --address 0.0.0.0 9090:9090 diff --git a/vagrant/k8s/application_metrics/jmx/jmxexporter/docker/Dockerfile b/vagrant/k8s/application_metrics/jmx/jmxexporter/docker/Dockerfile index 1b9a0935e4..c1aee6e3fa 100644 --- a/vagrant/k8s/application_metrics/jmx/jmxexporter/docker/Dockerfile +++ b/vagrant/k8s/application_metrics/jmx/jmxexporter/docker/Dockerfile @@ -1,4 +1,4 @@ FROM tomcat:jdk8-adoptopenjdk-openj9 -RUN apt-get update && apt-get install -y wget -RUN wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.13.0/jmx_prometheus_javaagent-0.13.0.jar -O /jmx_prometheus_javaagent-0.13.0.jar +RUN apt-get update && apt-get install -y curl +RUN curl -L https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.13.0/jmx_prometheus_javaagent-0.13.0.jar -o /jmx_prometheus_javaagent-0.13.0.jar ENV CATALINA_OPTS "-javaagent:/jmx_prometheus_javaagent-0.13.0.jar=8888:/config.yaml" diff --git a/vagrant/k8s/application_metrics/jmx/jolokia/agent/Dockerfile b/vagrant/k8s/application_metrics/jmx/jolokia/agent/Dockerfile index 8cc9dd597e..3c7f2c45d9 100644 --- a/vagrant/k8s/application_metrics/jmx/jolokia/agent/Dockerfile +++ b/vagrant/k8s/application_metrics/jmx/jolokia/agent/Dockerfile @@ -1,5 +1,5 @@ FROM tomcat:jdk8-adoptopenjdk-openj9 -RUN apt-get update && apt-get install -y wget -RUN wget https://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/1.6.2/jolokia-jvm-1.6.2-agent.jar -O /jolokia-jvm-1.6.2-agent.jar +RUN apt-get update && apt-get install -y curl +RUN curl -L https://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/1.6.2/jolokia-jvm-1.6.2-agent.jar -o /jolokia-jvm-1.6.2-agent.jar COPY entrypoint.sh /entrypoint.sh CMD ["/entrypoint.sh"] diff --git a/vagrant/k8s/application_metrics/jmx/jolokia/docker/Dockerfile b/vagrant/k8s/application_metrics/jmx/jolokia/docker/Dockerfile index 63d62c1ba0..d3bcedd78e 100644 --- a/vagrant/k8s/application_metrics/jmx/jolokia/docker/Dockerfile +++ b/vagrant/k8s/application_metrics/jmx/jolokia/docker/Dockerfile @@ -1,4 +1,4 @@ FROM tomcat:jdk8-adoptopenjdk-openj9 -RUN apt-get update && apt-get install -y wget -RUN wget https://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/1.6.2/jolokia-jvm-1.6.2-agent.jar -O /jolokia-jvm-1.6.2-agent.jar +RUN apt-get update && apt-get install -y curl +RUN curl -L https://search.maven.org/remotecontent?filepath=org/jolokia/jolokia-jvm/1.6.2/jolokia-jvm-1.6.2-agent.jar -o /jolokia-jvm-1.6.2-agent.jar ENV CATALINA_OPTS "-javaagent:/jolokia-jvm-1.6.2-agent.jar" diff --git a/vagrant/provision.sh b/vagrant/provision.sh index 274c7c4123..ff81d37472 100644 --- a/vagrant/provision.sh +++ b/vagrant/provision.sh @@ -41,8 +41,8 @@ HELM_2_VERSION=v2.16.9 HELM_3_VERSION=v3.2.4 mkdir /opt/helm2 /opt/helm3 -curl https://get.helm.sh/helm-${HELM_2_VERSION}-linux-amd64.tar.gz | tar -xz -C /opt/helm2 -curl https://get.helm.sh/helm-${HELM_3_VERSION}-linux-amd64.tar.gz | tar -xz -C /opt/helm3 +curl "https://get.helm.sh/helm-${HELM_2_VERSION}-linux-amd64.tar.gz" | tar -xz -C /opt/helm2 +curl "https://get.helm.sh/helm-${HELM_3_VERSION}-linux-amd64.tar.gz" | tar -xz -C /opt/helm3 ln -s /opt/helm2/linux-amd64/helm /usr/bin/helm2 ln -s /opt/helm3/linux-amd64/helm /usr/bin/helm3 @@ -79,7 +79,12 @@ done # install requirements for ci/build.sh snap install ruby --channel=2.6/stable --classic gem install bundler -apt install -y gcc g++ libsnappy-dev shellcheck +apt install -y gcc g++ libsnappy-dev + +SHELLCHECK_VERSION=v0.7.1 +curl -Lo- "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar -xJf - +sudo cp "shellcheck-${SHELLCHECK_VERSION}/shellcheck" /usr/local/bin +rm -rf "shellcheck-${SHELLCHECK_VERSION}/" # Init helm tiller sudo -H -u vagrant -i helm2 init --wait @@ -89,7 +94,7 @@ kubectl -n kube-system get services | grep -i kubernetes-dashboard | awk '{print echo echo Dashboard token: -echo $(/sumologic/vagrant/scripts/get-dashboard-token.sh) +/sumologic/vagrant/scripts/get-dashboard-token.sh echo ln -s /sumologic/vagrant/scripts/sumo-make.sh /usr/local/bin/sumo-make diff --git a/vagrant/scripts/sumo-make-completion.sh b/vagrant/scripts/sumo-make-completion.sh index 90e21728f1..b821b8fe13 100644 --- a/vagrant/scripts/sumo-make-completion.sh +++ b/vagrant/scripts/sumo-make-completion.sh @@ -1,4 +1,4 @@ -#/usr/bin/env bash +#!/usr/bin/env bash -targets=$(cat /sumologic/vagrant/Makefile | grep -oE '^\S*\:' | sed 's/\:$//g') +targets=$(grep -oE '^\S*\:' /sumologic/vagrant/Makefile | sed 's/\:$//g') complete -W "${targets}" sumo-make