Skip to content

Commit 7aadb73

Browse files
SNOW-2114096: Implementing prober script image builder (#2340)
Co-authored-by: Maxim Mishchenko <[email protected]>
1 parent 539d675 commit 7aadb73

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

prober/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM alpine:3.18
2+
3+
RUN apk add --no-cache \
4+
bash \
5+
git \
6+
make \
7+
g++ \
8+
zlib-dev \
9+
openssl-dev \
10+
libffi-dev
11+
12+
ENV HOME="/root"
13+
WORKDIR ${HOME}
14+
RUN git clone --depth=1 https://github.com/pyenv/pyenv.git .pyenv
15+
ENV PYENV_ROOT="${HOME}/.pyenv"
16+
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"
17+
18+
19+
# Build arguments for Python versions and Snowflake connector versions
20+
ARG PYTHON_VERSIONS="3.8.20 3.9.22 3.10.17"
21+
ARG SNOWFLAKE_CONNECTOR_VERSIONS="3.14.0 3.13.2 3.13.1"
22+
23+
24+
# Install Python versions
25+
RUN eval "$(pyenv init --path)" && \
26+
for version in $PYTHON_VERSIONS; do \
27+
pyenv install $version || echo "Failed to install Python $version"; \
28+
done
29+
30+
31+
# Create virtual environments for each combination of Python and Snowflake connector versions
32+
RUN for python_version in $PYTHON_VERSIONS; do \
33+
for connector_version in $SNOWFLAKE_CONNECTOR_VERSIONS; do \
34+
venv_path="/venvs/python_${python_version}_connector_${connector_version}"; \
35+
$PYENV_ROOT/versions/$python_version/bin/python -m venv $venv_path && \
36+
$venv_path/bin/pip install --upgrade pip && \
37+
$venv_path/bin/pip install snowflake-connector-python==$connector_version; \
38+
done; \
39+
done
40+
41+
# Copy the prober script into the container
42+
RUN mkdir -p /prober/probes/
43+
COPY __init__.py /prober
44+
# COPY parameters.json /prober
45+
COPY setup.py /prober
46+
COPY entrypoint.sh /prober
47+
COPY probes/* /prober/probes
48+
49+
# Install /prober in editable mode for each virtual environment
50+
RUN for venv in /venvs/*; do \
51+
source $venv/bin/activate && \
52+
pip install -e /prober && \
53+
deactivate; \
54+
done

prober/entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# Initialize an empty string to hold all parameters
4+
params=""
5+
6+
# Parse command-line arguments dynamically
7+
while [[ "$#" -gt 0 ]]; do
8+
params="$params $1 $2"
9+
shift 2
10+
done
11+
12+
# Run main.py with all available virtual environments
13+
for venv in /venvs/*; do
14+
echo "Running main.py with virtual environment: $(basename "$venv")"
15+
source "$venv/bin/activate"
16+
prober $params
17+
deactivate
18+
done

prober/probes/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def connect(connection_parameters: dict):
2929
database=connection_parameters["database"],
3030
schema=connection_parameters["schema"],
3131
role=connection_parameters["role"],
32-
authenticator="KEY_PAIR_AUTHENTICATOR",
33-
private_key=connection_parameters["private_key"],
32+
authenticator=connection_parameters["authenticator"],
33+
private_key_file=connection_parameters["private_key_file"],
3434
)
3535
return connection
3636
except Exception as e:

prober/probes/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import logging
33

4+
from probes import login # noqa
45
from probes.logging_config import initialize_logger
56
from probes.registry import PROBES_FUNCTIONS
67

@@ -19,8 +20,12 @@ def main():
1920
parser.add_argument("--account", required=True, help="Account")
2021
parser.add_argument("--schema", required=True, help="Schema")
2122
parser.add_argument("--warehouse", required=True, help="Warehouse")
23+
parser.add_argument("--database", required=True, help="Datanase")
2224
parser.add_argument("--user", required=True, help="Username")
23-
parser.add_argument("--private_key", required=True, help="Private key")
25+
parser.add_argument(
26+
"--auth", required=True, help="Authenticator (e.g., KEY_PAIR_AUTHENTICATOR)"
27+
)
28+
parser.add_argument("--private_key_file", required=True, help="Private key pwd")
2429

2530
# Parse arguments
2631
args = parser.parse_args()
@@ -32,13 +37,14 @@ def main():
3237
"account": args.account,
3338
"schema": args.schema,
3439
"warehouse": args.warehouse,
40+
"database": args.database,
3541
"user": args.user,
36-
"private_key": args.private_key,
42+
"authenticator": args.auth,
43+
"private_key_file": args.private_key_file,
3744
}
3845

3946
for function_name, function in PROBES_FUNCTIONS.items():
4047
try:
41-
logging.info("BBB")
4248
logging.error(f"Running probe: {function_name}")
4349
function(connection_params)
4450
except Exception as e:

0 commit comments

Comments
 (0)