-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
79 lines (61 loc) · 2.12 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
ARG APP_FACTORY=app:create_app
ARG APP_HOST=0.0.0.0
ARG APP_PORT=5000
ARG USERNAME=foxconnect
FROM ndunnett/python:noble-3.13 as base
ARG APP_FACTORY
ARG APP_HOST
ARG APP_PORT
ARG USERNAME
ENV FC_APP_FACTORY="$APP_FACTORY" FC_APP_HOST="$APP_HOST" FC_APP_PORT="$APP_PORT"
ENV FC_USERNAME="$USERNAME" FC_HOME="/home/$USERNAME"
ENV FC_REPO_PATH="$FC_HOME/repo"
ENV PATH="$FC_HOME/.cargo/bin:$PATH"
ENV PYO3_PYTHON="$FC_REPO_PATH/.venv/bin/python" UV_LINK_MODE=copy
ENV QUART_FOXDATA_ICC_DUMPS_PATH="$FC_HOME/icc_dumps"
ENV QUART_FOXDATA_DATA_PICKLE_PATH="$FC_HOME/data.pickle"
# create new user and project directories
RUN set -eux; \
useradd --create-home --user-group --no-log-init "$FC_USERNAME"; \
mkdir -p "$FC_HOME" "$FC_REPO_PATH"; \
chown -R "$FC_USERNAME:$FC_USERNAME" "$FC_HOME"
WORKDIR "$FC_REPO_PATH"
FROM base AS dev
ARG DEBIAN_FRONTEND=noninteractive
# update and install dev tools
RUN set -eux; \
apt update; \
apt install -y wget zsh git; \
apt clean; \
rm -rf /var/lib/apt/lists/*
# change user
USER "$FC_USERNAME"
# install uv
COPY --from=ghcr.io/astral-sh/uv:0.5 /uv /uvx /bin/
# install rust
RUN set -eux; wget -qO - https://sh.rustup.rs | sh -s -- -y
# install nvm, node, yarn
ARG NVM_GH_API=https://api.github.com/repos/nvm-sh/nvm/releases/latest
ARG NVM_DIR="$FC_HOME/.nvm"
ARG NODE_ENV=production
ENV NVM_DIR="$NVM_DIR" NODE_ENV="$NODE_ENV"
RUN set -ex; \
NVM_VERSION="$(wget -qO - "$NVM_GH_API" | grep tag_name | cut -d\" -f4)"; \
NVM_INSTALL_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$NVM_VERSION/install.sh"; \
wget -qO - "$NVM_INSTALL_URL" | bash; \
. "$NVM_DIR/nvm.sh"; \
nvm install 20; \
corepack enable
# replace entrypoint
CMD sleep infinity
FROM dev AS builder
# build project
COPY --chown="$FC_USERNAME:$FC_USERNAME" . "$FC_REPO_PATH"
RUN set -ex; uv sync
FROM base AS production
# copy built project and set user
USER "$FC_USERNAME"
COPY --from=builder --chown="$FC_USERNAME:$FC_USERNAME" "$FC_REPO_PATH" "$FC_REPO_PATH"
# replace entrypoint
CMD . "$FC_REPO_PATH/.venv/bin/activate"; \
hypercorn "$FC_APP_FACTORY()" --bind "$FC_APP_HOST:$FC_APP_PORT"