Skip to content

Commit

Permalink
Add SnowSQL installation script to Breeze (apache#23065)
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-laj authored Apr 19, 2022
1 parent 5164cdb commit 5144bed
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions BREEZE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ Currently available scripts:
for iTerm2 (Mac OS only)
* ``install_java.sh`` - installs `the OpenJDK 8u41 <https://openjdk.java.net/>`__
* ``install_kubectl.sh`` - installs `the Kubernetes command-line tool, kubectl <https://kubernetes.io/docs/reference/kubectl/kubectl/>`__
* ``install_snowsql.sh`` - installs `SnowSQL <https://docs.snowflake.com/en/user-guide/snowsql.html>`__
* ``install_terraform.sh`` - installs `Terraform <https://www.terraform.io/docs/index.html>`__

Launching Breeze integrations
Expand Down
1 change: 1 addition & 0 deletions TESTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ Currently forwarded credentials are:
* credentials stored in ``${HOME}/.azure`` for ``az`` - Microsoft Azure client
* credentials stored in ``${HOME}/.config`` for ``gcloud`` - Google Cloud client (among others)
* credentials stored in ``${HOME}/.docker`` for ``docker`` client
* credentials stored in ``${HOME}/.snowsql`` for ``snowsql`` - SnowSQL (Snowflake CLI client)

Adding a New System Test
--------------------------
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/docker-compose/forward-credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ services:
- ${HOME}/.azure:/root/.azure:cached
- ${HOME}/.config:/root/.config:cached
- ${HOME}/.docker:/root/.docker:cached
- ${HOME}/.snowsql:/root/.snowsql:cached
85 changes: 85 additions & 0 deletions scripts/in_container/bin/install_snowsql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set -euo pipefail

INSTALL_DIR="/files/opt/snowsql"
BIN_PATH="/files/bin/snowsql"

if [[ $# != "0" && ${1} == "--reinstall" ]]; then
rm -rf "${INSTALL_DIR}"
rm -f "${BIN_PATH}"
fi

hash -r

if command -v snowsql; then
echo 'The "snowsql" command found. Installation not needed. Run with --reinstall to reinstall'
exit 1
fi

SNOWSQL_VERSION=1.2.21
DOWNLOAD_URL="https://sfc-repo.snowflakecomputing.com/snowsql/bootstrap/1.2/linux_x86_64/snowsql-${SNOWSQL_VERSION}-linux_x86_64.bash"

if [[ -e ${BIN_PATH} ]]; then
echo "The binary file (${BIN_PATH}) already exists. This may mean snowsql is already installed."
echo "Run with --reinstall to reinstall."
exit 1
fi

TMP_DIR="$(mktemp -d)"
# shellcheck disable=SC2064
trap "rm -rf ${TMP_DIR}" EXIT

mkdir -p "${INSTALL_DIR}"
echo "Downloading from ${DOWNLOAD_URL}"
curl -# --fail "${DOWNLOAD_URL}" --output "${TMP_DIR}/snowsql.bash"

mkdir -p "${TMP_DIR}/home"

# By default, SnowSQL installs to ~/.snowsql.
# This directory can be changed with SNOWSQL_DOWNLOAD_DIR environment variable at runtime,
# but the installer does not support this yet, so we need to change HOME environment variable and
# copy necessary files
HOME="${TMP_DIR}/home" \
SNOWSQL_LOGIN_SHELL=/dev/null \
SNOWSQL_DEST="${INSTALL_DIR}/bin" \
bash "${TMP_DIR}/snowsql.bash"
mkdir -p "${INSTALL_DIR}/download/"
mv "${TMP_DIR}/home/.snowsql/${SNOWSQL_VERSION}" "${INSTALL_DIR}/download/${SNOWSQL_VERSION}"

# Create wrapper to change default installation directory.
cat > "${INSTALL_DIR}/snowsql" <<EOF
#!/usr/bin/env bash
export SNOWSQL_DOWNLOAD_DIR="${INSTALL_DIR}/download/"
exec /files/opt/snowsql/bin/snowsql "\${@}"
EOF

chmod a+x "${INSTALL_DIR}/snowsql"

ln -s "${INSTALL_DIR}/snowsql" "${BIN_PATH}"

# Coherence check
if ! command -v snowsql > /dev/null; then
echo 'Installation failed. The command "snowsql" was not found.'
exit 1
fi

echo 'Installation complete.'

0 comments on commit 5144bed

Please sign in to comment.