Skip to content

Commit

Permalink
[POP-7251] Add entrypoint for using env vars to init dbt profile (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin authored Oct 3, 2023
1 parent e26d9c0 commit e9d5e2d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM python:3.8-slim-bullseye

ENV DBT_PROFILES_DIR=/.dbt
ENV AWS_SHARED_CREDENTIALS_FILE=/.dbt/aws_credentials

ARG UID=1000
ARG GID=1000

Expand All @@ -10,9 +13,15 @@ RUN apt-get update \
libpq-dev \
git \
&& rm -rf /var/lib/apt/lists/ \
&& groupadd -f -g ${GID} -r dbt && useradd -g dbt -l -m -r -u ${UID} dbt \
&& python3 -m pip install -U wheel

ADD entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh \
&& groupadd -f -g ${GID} -r dbt && useradd -g dbt -l -m -r -u ${UID} dbt \
&& mkdir /.dbt \
&& chown dbt:dbt /.dbt

ARG REQUIREMENTS_FILE
ARG DBT_VERSION

Expand All @@ -23,4 +32,5 @@ RUN python3 -m pip install -r /tmp/requirements.txt && rm -f /tmp/requirements.
USER dbt
WORKDIR /dbt

ENTRYPOINT ["/entrypoint.sh"]
CMD ["dbt", "debug"]
7 changes: 6 additions & 1 deletion bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ else
image_name="dbt-${adapter}"
fi

tag="ghcr.io/popsql/${image_name}:${version}"

docker build \
--build-arg REQUIREMENTS_FILE="${requirements_file}" \
--tag "ghcr.io/popsql/${image_name}:${version}" \
--build-arg DBT_VERSION="${version}" \
--tag "${tag}" \
"${BASE_DIR}"

echo "Successfully built image ${tag}"
20 changes: 20 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

if [ -n "${DBT_PROFILES}" ]; then
echo "${DBT_PROFILES}" > /.dbt/profiles.yml
if [ -n "${AWS_CREDENTIALS}" ]; then
echo "${AWS_CREDENTIALS}" > /.dbt/aws_credentials
fi
if [ -n "${BQ_KEYFILE}" ]; then
echo "${BQ_KEYFILE}" > /.dbt/bq_keyfile.json
fi
else
if [ -f ~/.dbt/profiles.yml ]; then
cp ~/.dbt/profiles.yml /.dbt/profiles.yml
fi
if [ -f ~/.aws/credentials ]; then
cp ~/.aws/credentials /.dbt/aws_credentials
fi
fi

exec "$@"

0 comments on commit e9d5e2d

Please sign in to comment.