11ARG OPA_BUILD=permit
2+ ARG TARGETPLATFORM
3+ ARG TARGETARCH
4+
5+ # RUST BUILD STAGE -----------------------------------
6+ # Build the Rust PDP binary for all targets
7+ # ----------------------------------------------------
8+ # BIG thanks to
9+ # - https://medium.com/@vladkens/fast-multi-arch-docker-build-for-rust-projects-a7db42f3adde
10+ # - https://stackoverflow.com/questions/70561544/rust-openssl-could-not-find-directory-of-openssl-installation
11+ # couldn't get this to work without the help of those two sources
12+ # (1) this stage will be run always on current arch
13+ # zigbuild & Cargo targets added
14+ FROM --platform=$BUILDPLATFORM rust:1.85-alpine AS rust_chef
15+ WORKDIR /app
16+ ENV PKGCONFIG_SYSROOTDIR=/
17+ RUN apk add --no-cache musl-dev openssl-dev zig pkgconf perl make
18+
19+ RUN cargo install --locked cargo-zigbuild cargo-chef
20+ RUN rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl
21+
22+ # (2) nothing changed
23+ FROM rust_chef AS rust_planner
24+ COPY . .
25+ RUN cargo chef prepare --recipe-path recipe.json
26+
27+ # (3) building project deps: need to specify all targets; zigbuild used
28+ FROM rust_chef AS rust_builder
29+ COPY --from=rust_planner /app/recipe.json recipe.json
30+ ENV OPENSSL_DIR=/usr
31+ RUN cargo chef cook --recipe-path recipe.json --release --zigbuild \
32+ --target x86_64-unknown-linux-musl --target aarch64-unknown-linux-musl
33+
34+ # (4) actuall project build for all targets
35+ # binary renamed to easier copy in runtime stage
36+ COPY . .
37+ RUN cargo zigbuild -r --target x86_64-unknown-linux-musl --target aarch64-unknown-linux-musl && \
38+ mkdir -p /app/linux/arm64/ && \
39+ mkdir -p /app/linux/amd64/ && \
40+ cp target/aarch64-unknown-linux-musl/release/pdp-server /app/linux/arm64/pdp && \
41+ cp target/x86_64-unknown-linux-musl/release/pdp-server /app/linux/amd64/pdp
42+
43+
244# OPA BUILD STAGE -----------------------------------
345# Build OPA from source or download precompiled binary
446# ---------------------------------------------------
@@ -37,21 +79,20 @@ RUN mkdir -p /app/backup && chmod -R 777 /app/backup
3779
3880# Install necessary libraries in a single RUN command
3981RUN apk update && \
40- apk add --no-cache bash build-base libffi-dev libressl-dev musl-dev zlib-dev gcompat
82+ apk add --no-cache bash build-base libffi-dev libressl-dev musl-dev zlib-dev gcompat wget
4183
4284# Copy OPA binary from the build stage
4385COPY --from=opa_build --chmod=755 /opa /app/bin/opa
4486
87+ # Copy the Rust PDP binary from the builder stage
88+ ARG TARGETPLATFORM
89+ COPY --from=rust_builder --chmod=755 /app/${TARGETPLATFORM}/pdp /app/pdp
90+
4591# Environment variables for OPA
4692ENV OPAL_INLINE_OPA_EXEC_PATH="/app/bin/opa"
4793
48- # Copy required scripts
49- COPY scripts /app/scripts
50-
5194# Set permissions and ownership for the application
5295RUN mkdir -p /config && chown -R permit:permit /config
53- RUN chmod +x /app/scripts/wait-for-it.sh && \
54- chmod +x /app/scripts/start.sh
5596
5697# Ensure the `permit` user has the correct permissions for home directory and binaries
5798RUN chown -R permit:permit /home/permit /app /usr/local/bin
@@ -61,7 +102,6 @@ USER permit
61102
62103# Copy Kong routes and Gunicorn config
63104COPY kong_routes.json /config/kong_routes.json
64- COPY ./scripts/gunicorn_conf.py ./gunicorn_conf.py
65105
66106USER root
67107
@@ -77,17 +117,14 @@ USER permit
77117# Copy the application code
78118COPY ./horizon /app/horizon
79119
120+ USER permit
121+
80122# Version file for the application
81123COPY ./permit_pdp_version /app/permit_pdp_version
82124
83125# Set the PATH to ensure the local binary paths are used
84126ENV PATH="/app/bin:/home/permit/.local/bin:$PATH"
85127
86- # Uvicorn configuration
87- ENV UVICORN_NUM_WORKERS=1
88- ENV UVICORN_ASGI_APP="horizon.main:app"
89- ENV UVICORN_PORT=7000
90-
91128# opal configuration --------------------------------
92129ENV OPAL_SERVER_URL="https://opal.permit.io"
93130ENV OPAL_LOG_DIAGNOSE="false"
@@ -108,11 +145,9 @@ ENV PDP_VERSION_FILE_PATH="/app/permit_pdp_version"
108145# and it is here as a safety measure on purpose.
109146ENV OPAL_AUTH_PUBLIC_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDe2iQ+/E01P2W5/EZwD5NpRiSQ8/r/k18pFnym+vWCSNMWpd9UVpgOUWfA9CAX4oEo5G6RfVVId/epPH/qVSL87uh5PakkLZ3E+PWVnYtbzuFPs/lHZ9HhSqNtOQ3WcPDTcY/ST2jyib2z0sURYDMInSc1jnYKqPQ6YuREdoaNdPHwaTFN1tEKhQ1GyyhL5EDK97qU1ejvcYjpGm+EeE2sjauHYn2iVXa2UA9fC+FAKUwKqNcwRTf3VBLQTE6EHGWbxVzXv1Feo8lPZgL7Yu/UPgp7ivCZhZCROGDdagAfK9sveYjkKiWCLNUSpado/E5Vb+/1EVdAYj6fCzk45AdQzA9vwZefP0sVg7EuZ8VQvlz7cU9m+XYIeWqduN4Qodu87rtBYtSEAsru/8YDCXBDWlLJfuZb0p/klbte3TayKnQNSWD+tNYSJHrtA/3ZewP+tGDmtgLeB38NLy1xEsgd31v6ISOSCTHNS8ku9yWQXttv0/xRnuITr8a3TCLuqtUrNOhCx+nKLmYF2cyjYeQjOWWpn/Z6VkZvOa35jhG1ETI8IwE+t5zXqrf2s505mh18LwA1DhC8L/wHk8ZG7bnUe56QwxEo32myUBN8nHdu7XmPCVP8MWQNLh406QRAysishWhXVs/+0PbgfBJ/FxKP8BXW9zqzeIG+7b/yk8tRHQ=="
110147
111-
112-
113-
114148# We ignore this callback because we are sunsetting this feature in favor of the new inline OPA data updater
115149ENV PDP_IGNORE_DEFAULT_DATA_UPDATE_CALLBACKS_URLS='["http://localhost:8181/v1/data/permit/rebac/cache_rebuild"]'
150+
116151# if we are using the custom OPA binary, we need to load the permit plugin,
117152# if we don't then we MUST not add a non existing plugin
118153FROM main AS main-vanilla
@@ -125,8 +160,16 @@ ENV PDP_OPA_PLUGINS='{"permit_graph":{}}'
125160
126161FROM main-${OPA_BUILD} AS application
127162
128- # 7000 sidecar port
163+ # Environment variables with defaults
164+ ENV PDP_HORIZON_HOST=0.0.0.0
165+ ENV PDP_HORIZON_PORT=7001
166+ ENV PDP_PORT=7000
167+ ENV PDP_PYTHON_PATH=python3
168+
169+ # 7000 pdp port
170+ # 7001 horizon port
129171# 8181 opa port
130- EXPOSE 7000 8181
172+ EXPOSE 7000 7001 8181
173+
131174# Run the application using the startup script
132- CMD ["/app/scripts/start.sh " ]
175+ CMD ["/app/pdp " ]
0 commit comments