Skip to content

Instantly share code, notes, and snippets.

@sacundim
Created August 20, 2023 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sacundim/df2493d122c665f29bc701701bd8379c to your computer and use it in GitHub Desktop.
Save sacundim/df2493d122c665f29bc701701bd8379c to your computer and use it in GitHub Desktop.
Generic DBT project Dockerfile
dbt_packages/
logs/
target/
.user.yml
FROM python:3.11-slim
# Install DBT and any other pip dependencies from a
# requirements.txt file in the same directory as the
# Dockerfile (see below for an example)
COPY --link requirements.txt .
RUN --mount=type=cache,target=/root/.cache \
python3 -m pip install -r requirements.txt \
&& rm requirements.txt
# Hook to change the directory in the image to install
# your project to.
#
# docker build --build-arg="DBT_PROJECT_INSTALL_PATH=/my-own-path"
ARG DBT_PROJECT_INSTALL_PATH=/dbt-project
WORKDIR $DBT_PROJECT_INSTALL_PATH
# Install the project's required DBT packages first so as
# to exploit Docker build cache. Ideally we'd just copy
# `packages.yml` to narrowly depend only on what we want
# on this step, but alas the dbt deps command requires
# `dbt_project.yml` as well.
COPY --link packages.yml dbt_project.yml ./
RUN dbt deps
# Now actually install our project
COPY --link . .
# It'd be cool to do `dbt compile` here in order to
# precompute some more state at image build time, but
# that actually has to go to the database which I'd rather
# not do at this step. If you're obsessive and willing to
# mess with Docker build secrets you could go for it here.
# ENTRYPOINT vs. CMD is a whole deal. I'd prefer the former
# for its ergonomics but in practice I run in AWS Batch and it
# doesn't give a good option for overriding ENTRYPOINT when I
# want that.
CMD ["dbt"]
dbt-core==1.5.2
# Put whatever adapter you are using here here
dbt-athena-community==1.5.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment