forked from kevinjqliu/iceberg-rest-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
139 lines (98 loc) · 4.11 KB
/
Dockerfile
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
########################################################################################
ARG BASE_IMAGE=python:3.11
FROM ${BASE_IMAGE} AS runtime-base
WORKDIR /home/iceberg/iceberg_rest
# Make sure terminal does not wait at a prompt
ENV DEBIAN_FRONTEND=nonintercative
# Install curl for healthcheck
RUN apt-get update && apt-get install --no-install-recommends -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create iceberg user
RUN groupadd iceberg && \
useradd -rms /bin/bash -g iceberg iceberg && \
chown -R iceberg:iceberg /home/iceberg
# Create a directory for the sqlite database
RUN mkdir -p /tmp/warehouse && \
chown -R iceberg:iceberg /tmp/warehouse
########################################################################################
FROM runtime-base AS build-base
ARG POETRY_VERSION=1.8.3
ARG POETRY_HOME="/opt/poetry"
# Use bash shell
SHELL ["/bin/bash", "-c"]
# Make sure terminal does not wait at a prompt
ENV DEBIAN_FRONTEND=nonintercative
# Install system packages
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
curl \
libmariadb-dev-compat \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
ENV POETRY_HOME=${POETRY_HOME} \
POETRY_VERSION=${POETRY_VERSION}
RUN curl -sSL https://install.python-poetry.org/ | python3
# Add Poetry to the path
ENV PATH="$POETRY_HOME/bin:$PATH"
# Copy in the submodules
COPY vendor/ vendor/
# Copy in the config files
COPY pyproject.toml poetry.lock poetry.toml .gitmodules ./
########################################################################################
FROM build-base AS build-prod
ARG EXTRAS=base
# Install the dependencies first so they are cached
RUN poetry install --no-root --extras "${EXTRAS}"
########################################################################################
FROM build-base AS build-dev
# Install the dependencies first so they are cached
RUN poetry install --no-root --with dev --all-extras
########################################################################################
FROM runtime-base AS prod
# Add the virtualenv from the build-prod stage into the runtime image
COPY --from=build-prod /home/iceberg/iceberg_rest/.venv /home/iceberg/iceberg_rest/.venv
ENV PATH="/home/iceberg/iceberg_rest/.venv/bin:$PATH"
# Give the iceberg user ownership of the iceberg_rest directory
RUN chown -R iceberg:iceberg /home/iceberg/iceberg_rest
# Switch to iceberg user
USER iceberg
# Add the source code
COPY pyproject.toml ./
COPY src/ src/
COPY README.md README.md
# Install the source package
RUN pip install . --no-deps
# Serve the app in production mode
CMD ["uvicorn", "src.iceberg_rest.main:app", "--host", "0.0.0.0", "--port", "8000"]
# Healthcheck
HEALTHCHECK --interval=5m --timeout=30s --start-period=30s --retries=5 \
CMD curl -f http://localhost:8000/v1/config || exit 1
########################################################################################
FROM runtime-base AS dev
# Make sure terminal does not wait at a prompt
# Make sure python does not write pyc files, i.e. pytest_cache
ENV DEBIAN_FRONTEND=noninteractive PYTHONDONTWRITEBYTECODE=1
# Install system packages required for dev.
# Git is required to run pre-commit during ci.
RUN apt-get update && apt-get install --no-install-recommends -y \
git \
&& rm -rf /var/lib/apt/lists/*
# Add the virtualenv from the build-prod stage into the runtime image
COPY --from=build-dev /home/iceberg/iceberg_rest/.venv /home/iceberg/iceberg_rest/.venv
ENV PATH="/home/iceberg/iceberg_rest/.venv/bin:$PATH"
# Give the iceberg user ownership of the iceberg_rest directory
RUN chown -R iceberg:iceberg /home/iceberg/iceberg_rest
# Switch to iceberg user
USER iceberg
# Add the source code
COPY pyproject.toml poetry.lock poetry.toml ./
COPY src/ src/
COPY tests/ tests/
COPY README.md README.md
# Install the source package
RUN pip install . --no-deps
# Serve the app in development mode
CMD ["uvicorn", "src.iceberg_rest.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
########################################################################################