Code Monkey home page Code Monkey logo

airflow-django's Introduction

Airflow-Django

Apache-Airflow는 데이터 파이프 라인을 스케줄링 및 모니터링하는 오픈소스입니다. Django 내부에 비즈니스 로직이 강하게 엮여있어서 별도로 분리하기 힘든 경우 해당 프로세스를 Airflow에서 직접 실행하도록 구성였습니다.

Environments

  • Language:
    • Python 3.10
  • Framework:
    • Airflow 2.2.4
    • Celery 5.1.2
    • Django 4.0
  • Container:
    • Docker 20.10.10
  • Database:
    • PostrgreSQL 12.7

1. Architecture

Airflow는 docker compose를 이용하여 구성하였고, DockerOperator를 이용하여 Django 컨테이너를 실행하도록 하였습니다. CeleryExecutor를 사용하여 작업을 분산된 환경에서 실행 가능하도록 하였습니다.

2. Quick Start

2.1 환경 변수 설정

실행할 django 이미지 및 DB 접속 정보를 입력합니다. 기본적으로 PostgreSQL 기준으로 작성되었습니다.

$> cp .env.example .env
$> vim .env

# === Dotenv Files === #

# - Django
DJANGO_DEFAULT_IMAGE=django-app:latest
...

2.1.1 다른 DB 연동

PostgreSQL 이외에 다른 Database를 사용하는 경우 해당 DB 연동 라이브러리를 추가하고 docker-compose.yml 파일을 수정해주세요.

$> poetry add mysqlclient
# docker-compose.yml
    environment:
      AIRFLOW__CORE__SQL_ALCHEMY_CONN: mysql://${AIRFLOW_DB_USER}:${AIRFLOW_DB_PASSWORD}@ ...
...

2.2 Airflow 실행

$> docker-compose up -d

2.2.1 User 생성

초기 실행하는 경우 DB에 유저 정보를 입력합니다.

$> airflow db init
$> airflow users create \
    --username miintto \
    --firstname Minjae \
    --lastname Park \
    --role Admin \
    --email [email protected]

2.3 Job 실행

2.3.1 Airflow Webserver 접속

localhost 혹은 실행된 서버 도메인의 8080번 포트로 접속합니다.

2.3.2 Django 실행

실행할 Django 이미지를 미리 빌드합니다.

$> docker build -t django-app -f django/Dockerfile .

job 실행!

Graph 페이지로 들어가 실행 상태를 체크힙니다.

모든 작업이 정상적으로 완료되었습니다.

airflow-django's People

Contributors

miintto avatar

Stargazers

Jung Sang-jun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.