-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (56 loc) · 1.78 KB
/
Dockerfile
File metadata and controls
66 lines (56 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
FROM python:3.11-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
AIRFLOW_HOME=/opt/airflow \
AIRFLOW__CORE__EXECUTOR=SequentialExecutor \
AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres/airflow \
AIRFLOW__CORE__FERNET_KEY='' \
AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION=True \
AIRFLOW__CORE__LOAD_EXAMPLES=False
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
postgresql-client \
graphviz \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /opt/airflow
# Copy requirements file
COPY requirements.txt /tmp/requirements.txt
# Install Python packages from requirements.txt
# This ensures a single source of truth and avoids duplication
RUN pip install --no-cache-dir -r /tmp/requirements.txt
# Create entrypoint script
RUN echo '#!/bin/bash\n\
set -e\n\
# Load environment variables from .env file if it exists\n\
if [ -f /opt/airflow/.env ]; then\n\
set -a\n\
source /opt/airflow/.env\n\
set +a\n\
fi\n\
echo "Waiting for PostgreSQL to be ready..."\n\
until pg_isready -h postgres -U airflow; do\n\
echo "PostgreSQL is unavailable - sleeping"\n\
sleep 1\n\
done\n\
echo "PostgreSQL is ready!"\n\
echo "Initializing Airflow database..."\n\
airflow db init || true\n\
echo "Creating Airflow user..."\n\
airflow users create \\\n\
--username airflow_company_atlas \\\n\
--firstname Jiufeng \\\n\
--lastname Li \\\n\
--role Admin \\\n\
--email lijiufeng97@gmail.com \\\n\
--password CompanyAtlas123! || true\n\
exec "$@"' > /entrypoint.sh && chmod +x /entrypoint.sh
# Expose Airflow webserver port
EXPOSE 8080
# Set entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Default command (can be overridden in docker-compose)
CMD ["airflow", "webserver"]