Skip to content

Commit

Permalink
Docker dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
andreax79 committed May 31, 2023
1 parent 636803e commit f289779
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dags/
/logs/
.bash_history
26 changes: 26 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG AIRFLOW_VERSION
ARG AIRFLOW_VERSION

FROM apache/airflow:${AIRFLOW_VERSION}
ARG PLUGIN_VERSION

USER root
# Install git
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git \
&& apt-get autoremove -yqq --purge \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
USER airflow

# Install Airflow
COPY requirements-optional.txt .
RUN pip install --no-cache-dir airflow-code-editor==${PLUGIN_VERSION} -r requirements-optional.txt && rm requirements-optional.txt
# Init airflow db
RUN airflow db init
# Create user 'admin' with password 'admin'
RUN airflow users create -r Admin -u admin -e [email protected] -f admin -l admin -p admin
RUN airflow sync-perm

ENV PYTHONPATH = /home/airflow
38 changes: 37 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
IMAGE_NAME=airflow-code-editor
DEV_IMAGE_NAME=${IMAGE_NAME}-dev
OWNER=andreax79
AIRFLOW_VERSION=2.5.2
AIRFLOW_VERSION=2.6.1
AIRFLOW_PORT=8080
PLUGIN_VERSION=`cat ../airflow_code_editor/VERSION`
VERSION=${AIRFLOW_VERSION}-${PLUGIN_VERSION}

.PHONY: help build test format image push all

help:
@echo "Release:"
@echo "- make image Build docker image"
@echo "- make push Push docker image"
@echo "Development:"
@echo "- make dev-image Build dev image"
@echo "- make dev-shell Start a shell in the dev environment"
@echo "- make webserver Start Airflow webserver from dev image"

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -56,4 +63,33 @@ push-version:
@docker push ${OWNER}/${IMAGE_NAME}:${VERSION}
@docker push ${OWNER}/${IMAGE_NAME}:${AIRFLOW_VERSION}

dev-image:
@cp ../requirements-optional.txt .
@DOCKER_BUILDKIT=1 docker build \
--build-arg PLUGIN_VERSION=${PLUGIN_VERSION} \
--build-arg AIRFLOW_VERSION=${AIRFLOW_VERSION} \
--tag ${DEV_IMAGE_NAME} \
-f Dockerfile.dev \
.
@rm ./requirements-optional.txt

dev-shell:
@touch ${PWD}/.bash_history
@chmod 666 ${PWD}/.bash_history
@docker run --rm -it \
-h airflow \
-v ${PWD}/.bash_history:/home/airflow/.bash_history \
-v ${PWD}/../airflow_code_editor:/home/airflow/.local/lib/python3.7/site-packages/airflow_code_editor/ \
-p ${AIRFLOW_PORT}:${AIRFLOW_PORT} \
${DEV_IMAGE_NAME} \
bash -l

webserver:
@docker run --rm -it \
-h airflow \
-v ${PWD}/../airflow_code_editor:/home/airflow/.local/lib/python3.7/site-packages/airflow_code_editor/ \
-p ${AIRFLOW_PORT}:${AIRFLOW_PORT} \
${DEV_IMAGE_NAME} \
airflow webserver

all: help

0 comments on commit f289779

Please sign in to comment.