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

Improve deployment #143

Merged
merged 40 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5f17e82
build(docker): move dockerfile and add compose file
May 18, 2024
274ceec
refactor(airflow): change airflow home file path
Jul 6, 2024
63be6a6
fix(dags): broken attachment file path
Jul 6, 2024
11c0fc8
build(airflow): set airflow home env variable
Jul 6, 2024
430ee50
fix(airflow): not load example dags
Jul 6, 2024
0ba4446
build(docker): configurable airflow and python version
Jul 6, 2024
664a56f
build(pip): solve requirements from poetry and install dependencies f…
Jul 6, 2024
514fc95
build(docker): file path
Jul 6, 2024
20ed3e8
build(pip): update deps
Jul 6, 2024
6e3d0ef
fix(pip): solve some deps runtime error
Jul 6, 2024
9743a70
build(docker): add entrypoint script
Jul 7, 2024
3b2d034
build(docker): update compose files
Jul 7, 2024
b208a82
fix(airflow): update env template
Jul 7, 2024
dd52d9a
build(makefile): add deployment alias
Jul 7, 2024
5837994
docs(project): update README, add contribute, maintain, and deploymen…
Jul 7, 2024
2a67908
build(npm): remove un-used config files
Jul 7, 2024
8ede6cb
fix(project): misc
Jul 7, 2024
5166cde
docs(project): add more contributing steps
Jul 7, 2024
04b1242
build(ci): restore docker image ci config change
Jul 7, 2024
eddf1bc
build(docker): restore and change test dockerfile
Jul 7, 2024
7a5c76d
fix(docker): create fernet key if not exists
Jul 7, 2024
c563ae4
build(project): use pip and constraint file to manage deps
Jul 20, 2024
b283f66
fix(docker): not upgrade pip
Jul 20, 2024
309058f
docs(project): update README
Jul 20, 2024
a161d16
fix(docker): add env variable check on entry script
Jul 20, 2024
5f58673
fix(ods): questionnaire test error
Jul 20, 2024
fc16627
docs(project): misc
Jul 20, 2024
8b0e911
build(docker): create fernet key if not exists
Jul 20, 2024
34874b1
docs(project): misc
Jul 20, 2024
1ed4c1b
refactor(dags): tpying
Aug 17, 2024
185dfdf
build(python): remove poetry and move dev deps to another requiremens…
Aug 17, 2024
d3d72bf
docs(project): add venv setup guide
Aug 17, 2024
45cdf8f
docs(project): change production project path
Aug 17, 2024
de60e7d
ci(python): install dependencies with pip
Aug 17, 2024
7b0bfeb
fix(project): upgrade airflow to v1.10.15
Aug 17, 2024
6783283
style(project): reformat
Aug 17, 2024
3dfdb09
style(project): recover pyproject.toml style rule
Aug 17, 2024
e5f4375
style(project): reformat
Aug 17, 2024
b047fa1
ci(docker): use gcp artifact-registry
Aug 31, 2024
16e015a
docs(project): update
Sep 1, 2024
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
2 changes: 0 additions & 2 deletions .env.sh

This file was deleted.

6 changes: 3 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# get the complete env from other volunteers, please
AIRFLOW_HOME=/opt/airflow
BIGQUERY_PROJECT=pycontw-225217
DATATEAM_DISCORD_WEBHOOK=<>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I feel this might be something we should make it configurable. 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is AIRFLOW_HOME redundant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I mean BIGQUERY_PROJECT

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

developer may use their own GCP project for testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's why I think making it configurable might be a good idea. WDYT?

GOOGLE_APPLICATION_CREDENTIALS=/usr/local/airflow/service-account.json
GOOGLE_APPLICATION_CREDENTIALS=/opt/airflow/service-account.json
AIRFLOW__CORE__FERNET_KEY=paste-your-fernet-key-here
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:

- name: Install dependencies
run: |
pip install -U poetry==1.6.1
poetry install
pip install -r requirements.txt -r requirements-dev.txt -c constraints-3.8.txt
pip install black==19.10b0 click==7.1.2

- name: Run linters
run: make lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# project stuff
.env.production
.env.staging
env
env.sh
Expand Down
31 changes: 18 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM apache/airflow:1.10.13-python3.8
ARG AIRFLOW_VERSION=1.10.15
ARG PYTHON_VERSION=3.8

FROM apache/airflow:${AIRFLOW_VERSION}-python${PYTHON_VERSION}

USER root
ENV POETRY_CACHE_DIR='/var/cache/pypoetry' \
GOOGLE_APPLICATION_CREDENTIALS='/usr/local/airflow/service-account.json'

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C \
Expand All @@ -10,19 +12,22 @@ RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 \
# 1. if you don't need postgres, remember to remove postgresql-dev and sqlalchemy
# 2. libglib2.0-0 libsm6 libxext6 libxrender-dev libgl1-mesa-dev are required by opencv
# 3. git is required by pip install git+https
&& pip install --no-cache-dir -U poetry==1.6.1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY pyproject.toml pyproject.toml
COPY poetry.toml poetry.toml
COPY poetry.lock poetry.lock
COPY entrypoint.sh /entrypoint.sh

RUN python -m poetry install --no-interaction --no-ansi --no-dev \
# Cleaning poetry installation's cache for production:
&& rm -rf "$POETRY_CACHE_DIR" \
&& pip uninstall -yq poetry
RUN chmod +x /entrypoint.sh

USER airflow
COPY dags /usr/local/airflow/dags
COPY airflow.cfg airflow.cfg

COPY ./requirements.txt ${AIRFLOW_HOME}/requirements.txt
COPY ./constraints-3.8.txt ${AIRFLOW_HOME}/constraints-3.8.txt

RUN pip install --no-cache-dir -r ${AIRFLOW_HOME}/requirements.txt --constraint constraints-3.8.txt

COPY airflow.cfg ${AIRFLOW_HOME}/airflow.cfg

COPY --chown=airflow:root dags ${AIRFLOW_HOME}/dags

ENTRYPOINT ["/entrypoint.sh"]
39 changes: 35 additions & 4 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
FROM davidtnfsh/pycon_etl:prod
ENV AIRFLOW_TEST_MODE=True
ENV FERNET_KEY="uMnRC6ingT/WjPzPiXLvbWTJYzaA3sJdJRVkinceVp4="
ARG AIRFLOW_VERSION=1.10.15
ARG PYTHON_VERSION=3.8

FROM apache/airflow:${AIRFLOW_VERSION}-python${PYTHON_VERSION}

USER root
COPY airflow.test.cfg airflow.cfg

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C \
&& apt-get update \
&& apt-get install -y --no-install-recommends git \
# 1. if you don't need postgres, remember to remove postgresql-dev and sqlalchemy
# 2. libglib2.0-0 libsm6 libxext6 libxrender-dev libgl1-mesa-dev are required by opencv
# 3. git is required by pip install git+https
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

USER airflow

COPY ./requirements.txt ${AIRFLOW_HOME}/requirements.txt
COPY ./requirements-dev.txt ${AIRFLOW_HOME}/requirements-dev.txt
COPY ./constraints-3.8.txt ${AIRFLOW_HOME}/constraints-3.8.txt

RUN pip install --no-cache-dir -r ${AIRFLOW_HOME}/requirements.txt -r ${AIRFLOW_HOME}/requirements-dev.txt --constraint constraints-3.8.txt

COPY airflow.cfg ${AIRFLOW_HOME}/airflow.cfg

COPY --chown=airflow:root dags ${AIRFLOW_HOME}/dags

ENV AIRFLOW_TEST_MODE=True

ENTRYPOINT ["/entrypoint.sh"]
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
VENV_PREFIX=poetry run

lint:
$(VENV_PREFIX) black . --check
$(VENV_PREFIX) isort --check-only .
$(VENV_PREFIX) flake8 .
$(VENV_PREFIX) mypy dags/ tests/
black . --check
isort --check-only .
flake8 .
mypy dags/ tests/

format:
$(VENV_PREFIX) black .
$(VENV_PREFIX) isort .
black .
isort .

test:
PYTHONPATH=./dags $(VENV_PREFIX) pytest
PYTHONPATH=./dags pytest

coverage:
PYTHONPATH=./dags $(VENV_PREFIX) pytest --cov=dags tests
PYTHONPATH=./dags pytest --cov=dags tests

build-dev:
docker-compose -f ./docker-compose-dev.yml build

deploy-dev:
docker-compose -f ./docker-compose-dev.yml up -d

down-dev:
docker-compose -f ./docker-compose-dev.yml down

deploy-prod:
docker-compose -f ./docker-compose.yml up -d

down-prod:
docker-compose -f ./docker-compose.yml down
Loading
Loading