Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (53 loc) · 2.4 KB
/
Copy pathDockerfile
File metadata and controls
64 lines (53 loc) · 2.4 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
FROM python:3.12-slim
WORKDIR /app
# Install dependencies for Azure SQL and ODBC driver
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
apt-transport-https \
software-properties-common \
curl \
gnupg2 \
build-essential \
unixodbc-dev \
libcurl4 \
libssl3
# Remove conflicting ODBC packages
RUN apt-get remove --purge -y libodbc* libodbccr* unixodbc* && apt-get autoremove -y
# Install Microsoft ODBC Driver 18
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg \
&& install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg \
&& echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 unixodbc-dev
# Configure ODBC
RUN echo "[ODBC Data Sources]" >> /etc/odbc.ini && \
echo "AzureSQL = ODBC Driver 18 for SQL Server" >> /etc/odbc.ini && \
echo "" >> /etc/odbc.ini && \
echo "[AzureSQL]" >> /etc/odbc.ini && \
echo "Driver=ODBC Driver 18 for SQL Server" >> /etc/odbc.ini && \
echo "Server=madebayosqlserver.database.windows.net" >> /etc/odbc.ini && \
echo "Database=ussba_db" >> /etc/odbc.ini && \
echo "Uid=adminussba" >> /etc/odbc.ini && \
echo "Pwd=ussba2025RBX" >> /etc/odbc.ini && \
echo "Encrypt=yes" >> /etc/odbc.ini && \
echo "TrustServerCertificate=yes" >> /etc/odbc.ini
# Install wait-for-it.sh
RUN wget -O /wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && \
chmod +x /wait-for-it.sh
# Environment variables
ENV PYTHONUNBUFFERED=1 \
ODBCINI=/etc/odbc.ini \
ACCEPT_EULA=Y
# Install Python packages
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy app code
COPY . .
# Expose port
EXPOSE 8000
# Entry point with error handling and database wait
CMD ["sh", "-c", " \
/wait-for-it.sh madebayosqlserver.database.windows.net:1433 -t 60 -- \
alembic upgrade head || (echo 'Migrations failed. Retrying...' && sleep 5 && alembic upgrade head) && \
python populate_db.py || (echo 'Data population failed. Retrying...' && sleep 5 && python populate_db.py) && \
gunicorn -k uvicorn.workers.UvicornWorker -w 4 main:app --bind 0.0.0.0:80"]