Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sql): update entry point #652

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/Tre-SQL-Trino/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ FROM trinodb/trino:422
# apt-get remove -y wget && \
# apt-get clean


# Set working directory
WORKDIR /workspace

USER root:root

# Copy entrypoint script
#COPY entrypoint.sh /usr/local/bin/entrypoint.sh

# Make entrypoint script executable
#RUN chmod +x /usr/local/bin/entrypoint.sh

# Set entrypoint
#ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

RUN mkdir -p /data && chown trino:trino /data
RUN chown trino:trino /workspace

# Copy entrypoint script
COPY entrypoint.sh /home/trino/entrypoint.sh
COPY entrypoint.sh /workspace/entrypoint.sh
COPY entrypoint.sh /workspace/runsql.sh

# Make entrypoint script executable
RUN chmod +x /home/trino/entrypoint.sh
RUN chmod +x /workspace/entrypoint.sh
RUN chmod +x /workspace/runsql.sh

USER trino:trino

RUN mkdir -p /workspace/data

# Set entrypoint
ENTRYPOINT ["/home/trino/entrypoint.sh"]
ENTRYPOINT ["/workspace/entrypoint.sh"]
18 changes: 11 additions & 7 deletions src/Tre-SQL-Trino/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/bin/bash

if [[ -z "$TRINO_SERVER_URL" ]]; then
export TRINO_SERVER_URL="http://192.168.70.92:8090"
fi

if [[ -z "$LOCATION" ]]; then
export LOCATION="/workspace/data/result.csv"
fi

# Check if required environment variables are provided
if [[ -z "$TRINO_SERVER_URL" || -z "$SQL_STATEMENT" ]]; then
echo "Please provide TRINO_SERVER_URL and SQL_STATEMENT environment variables."
if [[ -z "$SQL_STATEMENT" ]]; then
echo "SQL_STATEMENT environment variables."
exit 1
fi


# Execute Trino CLI command to run SQL statement and output CSV
trino --server "$TRINO_SERVER_URL" --execute "$SQL_STATEMENT" --output-format CSV > ~/result.csv

ls -la ~/

trino --server "$TRINO_SERVER_URL" --execute "$SQL_STATEMENT" --output-format CSV > $LOCATION
Loading