|
1 | 1 | # Dockerfile |
2 | 2 |
|
3 | | -# Use Ubuntu to install 3 versions of Python for testing |
4 | | -# For production, you could use python:3.8-slim |
| 3 | +# Use Ubuntu to install Python and uv |
| 4 | +# For production, you could use python:3.11-slim |
5 | 5 |
|
6 | 6 | FROM ubuntu:22.04@sha256:3c61d3759c2639d4b836d32a2d3c83fa0214e36f195a3421018dbaaf79cbe37f |
7 | 7 |
|
8 | 8 | # set work directory |
9 | | -WORKDIR /carbonserver |
| 9 | +WORKDIR /app |
10 | 10 | # set env variables |
11 | 11 | ENV PYTHONDONTWRITEBYTECODE 1 |
12 | 12 | ENV PYTHONUNBUFFERED 1 |
13 | 13 | # Prevent apt to ask for region |
14 | 14 | ENV DEBIAN_FRONTEND noninteractive |
15 | 15 |
|
16 | 16 | RUN apt-get update && apt-get upgrade -y && \ |
17 | | - apt-get install -y software-properties-common && \ |
| 17 | + apt-get install -y software-properties-common curl && \ |
18 | 18 | add-apt-repository ppa:deadsnakes/ppa -y && \ |
19 | 19 | apt-get update && \ |
20 | | - apt-get install -y gcc libpq-dev python3.11 python3-pip |
| 20 | + apt-get install -y gcc libpq-dev python3.11 python3.11-dev |
21 | 21 |
|
22 | | -# Copy the requirements file from the project root |
23 | | -# COPY ./requirements/requirements-dev.txt /carbonserver/requirements-dev.txt |
24 | | -# RUN pip install -r /carbonserver/requirements-dev.txt |
| 22 | +RUN ln -sf /usr/bin/python3.11 /usr/bin/python && \ |
| 23 | + ln -sf /usr/bin/python3.11 /usr/bin/python3 |
25 | 24 |
|
26 | | -RUN ln -sf /usr/bin/pip3 /usr/bin/pip && \ |
27 | | - ln -sf /usr/bin/python3.11 /usr/bin/python && \ |
28 | | - ln -sf /usr/bin/python3.11 /usr/bin/python3 |
| 25 | +# Download the latest UV installer |
| 26 | +ADD https://astral.sh/uv/install.sh /uv-installer.sh |
29 | 27 |
|
30 | | -COPY ./requirements/requirements-api.txt /carbonserver/requirements-api.txt |
31 | | -RUN pip install -r /carbonserver/requirements-api.txt --require-hashes |
| 28 | +# Run the installer then remove it |
| 29 | +RUN sh /uv-installer.sh && rm /uv-installer.sh |
| 30 | + |
| 31 | +# Ensure the installed binary is on the `PATH` |
| 32 | +ENV PATH="/root/.local/bin/:$PATH" |
| 33 | + |
| 34 | +# Copy project files |
| 35 | +COPY pyproject.toml /app/ |
| 36 | +COPY codecarbon /app/codecarbon |
| 37 | +COPY carbonserver /app/carbonserver |
| 38 | + |
| 39 | +# Install dependencies using uv with the api dependency group |
| 40 | +RUN uv pip install --system -e ".[api]" |
32 | 41 |
|
33 | 42 | COPY ./carbonserver/docker/entrypoint.sh /opt |
34 | 43 | RUN chmod a+x /opt/entrypoint.sh |
35 | 44 |
|
36 | | -# Copy everything from carbonserver directory to the container |
37 | | -COPY carbonserver /carbonserver |
| 45 | +WORKDIR /app/carbonserver |
38 | 46 |
|
39 | 47 | EXPOSE 8000 |
40 | 48 | ENTRYPOINT ["/opt/entrypoint.sh"] |
0 commit comments