-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: run DBT from devcontainer (#3515)
- Loading branch information
Showing
7 changed files
with
176 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,46 @@ | ||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3/.devcontainer/base.Dockerfile | ||
FROM python:3.9 | ||
|
||
# [Choice] Python version: 3, 3.9, 3.8, 3.7, 3.6 | ||
ARG VARIANT="3.9" | ||
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} | ||
LABEL org.opencontainers.image.source=https://github.com/cal-itp/data-infra | ||
|
||
# [Option] Install Node.js | ||
ARG INSTALL_NODE="true" | ||
ARG NODE_VERSION="lts/*" | ||
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi | ||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
USER=calitp | ||
|
||
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. | ||
# COPY requirements.txt /tmp/pip-tmp/ | ||
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ | ||
# && rm -rf /tmp/pip-tmp | ||
# install gcloud CLI | ||
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates curl gnupg | ||
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ | ||
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg && \ | ||
apt-get update -y && apt-get install -y google-cloud-cli | ||
|
||
# [Optional] Uncomment this section to install additional OS packages. | ||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
# && apt-get -y install --no-install-recommends <your-package-list-here> | ||
# install pygraphviz deps | ||
RUN apt-get update && apt-get install -y libgdal-dev libgraphviz-dev graphviz-dev | ||
|
||
# [Optional] Uncomment this line to install global node packages. | ||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1 | ||
# create and switch to non-root user for devcontainer | ||
RUN useradd --create-home --shell /bin/bash $USER && \ | ||
chown -R $USER:$USER /home/$USER | ||
USER $USER | ||
|
||
# setup warehouse deps | ||
WORKDIR /home/$USER/app/warehouse | ||
# pip install location for non-root | ||
ENV PATH="$PATH:/home/$USER/.local/bin" | ||
# upgrade pip, install poetry | ||
RUN python -m pip install --upgrade pip && pip install poetry | ||
|
||
# copy source files | ||
COPY ./warehouse/pyproject.toml pyproject.toml | ||
COPY ./warehouse/poetry.lock poetry.lock | ||
COPY ./warehouse/dbt_project.yml dbt_project.yml | ||
COPY ./warehouse/packages.yml packages.yml | ||
|
||
# install warehouse deps | ||
RUN poetry install | ||
RUN poetry run dbt deps | ||
|
||
# install dev deps | ||
RUN pip install black memray pre-commit | ||
|
||
# switch back to app root | ||
WORKDIR /home/$USER/app | ||
# CMD for devcontainers | ||
CMD ["sleep", "infinity"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
services: | ||
dev: | ||
build: | ||
context: .. | ||
dockerfile: .devcontainer/Dockerfile | ||
image: data_infra:dev | ||
entrypoint: sleep infinity | ||
environment: | ||
- DBT_PROFILES_DIR=/home/calitp/.dbt | ||
- GOOGLE_APPLICATION_CREDENTIALS=/home/calitp/.config/gcloud/application_default_credentials.json | ||
volumes: | ||
- ..:/home/calitp/app | ||
- ~/.dbt:/home/calitp/.dbt | ||
- ~/.config/gcloud:/home/calitp/.config/gcloud | ||
|
||
dbt: | ||
build: | ||
context: .. | ||
dockerfile: .devcontainer/Dockerfile | ||
image: data_infra:dev | ||
entrypoint: ["poetry", "run", "dbt"] | ||
environment: | ||
- DBT_PROFILES_DIR=/home/calitp/.dbt | ||
- GOOGLE_APPLICATION_CREDENTIALS=/home/calitp/.config/gcloud/application_default_credentials.json | ||
volumes: | ||
- ..:/home/calitp/app | ||
- ~/.dbt:/home/calitp/.dbt | ||
- ~/.config/gcloud:/home/calitp/.config/gcloud | ||
working_dir: /home/calitp/app/warehouse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,37 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3 | ||
{ | ||
"name": "Python 3", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"context": "..", | ||
"args": { | ||
// Update 'VARIANT' to pick a Python version: 3, 3.6, 3.7, 3.8, 3.9 | ||
"VARIANT": "3.8", | ||
// Options | ||
"INSTALL_NODE": "false", | ||
"NODE_VERSION": "lts/*" | ||
} | ||
}, | ||
|
||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"terminal.integrated.shell.linux": "/bin/bash", | ||
"python.pythonPath": "/usr/local/bin/python", | ||
"python.languageServer": "Pylance", | ||
"python.linting.enabled": true, | ||
"python.linting.pylintEnabled": true, | ||
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", | ||
"python.formatting.blackPath": "/usr/local/py-utils/bin/black", | ||
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", | ||
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit", | ||
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", | ||
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", | ||
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", | ||
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", | ||
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", | ||
"name": "cal-itp/data-infra", | ||
"dockerComposeFile": ["./compose.yml"], | ||
"service": "dev", | ||
"runServices": ["dev"], | ||
"workspaceFolder": "/home/calitp/app", | ||
"postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"], | ||
"customizations": { | ||
"vscode": { | ||
"settings": { | ||
"terminal.integrated.defaultProfile.linux": "bash", | ||
"terminal.integrated.profiles.linux": { | ||
"bash": { | ||
"path": "/bin/bash" | ||
} | ||
}, | ||
"editor.formatOnSave": true, | ||
"files.trimTrailingWhitespace": true, | ||
"files.insertFinalNewline": true | ||
}, | ||
"files.insertFinalNewline": true, | ||
"files.encoding": "utf8", | ||
"files.eol": "\n", | ||
"python.languageServer": "Pylance" | ||
}, | ||
|
||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"davidanson.vscode-markdownlint", | ||
"bierner.markdown-mermaid", | ||
"mhutchie.git-graph" | ||
], | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "pip3 install --user -r requirements.txt", | ||
|
||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode", | ||
"portsAttributes": { | ||
"8000": { | ||
"label": "documentation website" | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
set -u | ||
|
||
# workaround VS Code devcontainer .git mounting issue | ||
git config --global --add safe.directory /home/calitp/app | ||
|
||
# initialize hook environments | ||
pre-commit install --install-hooks --overwrite | ||
|
||
cd warehouse/ | ||
|
||
if [ ! -f ~/.dbt/profiles.yml ]; then | ||
poetry run dbt init | ||
fi | ||
|
||
poetry run dbt debug | ||
|
||
if [[ $? != 0 ]]; then | ||
gcloud init | ||
gcloud auth application-default login | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.