|
| 1 | +# ============================================================================= |
| 2 | +# Devolutions Gateway — Source build for Coolify |
| 3 | +# ============================================================================= |
| 4 | +# Multi-stage build: |
| 5 | +# 1. rust-builder — compile the gateway binary from source |
| 6 | +# 2. official-image — extract libxmf and PowerShell module from official image |
| 7 | +# 3. runtime — assemble the final image |
| 8 | +# |
| 9 | +# Both the gateway binary AND the webapp are built from THIS repo's source. |
| 10 | +# The webapp must be pre-built locally (pnpm build:gateway) because some |
| 11 | +# dependencies (@devolutions/icons) require private registry authentication. |
| 12 | +# The libxmf.so and PowerShell module come from the official published image. |
| 13 | +# ============================================================================= |
| 14 | + |
| 15 | +# Global ARG — must be before any FROM to be usable in FROM lines |
| 16 | +ARG GATEWAY_VERSION=latest |
| 17 | + |
| 18 | +# --------------------------------------------------------------------------- |
| 19 | +# Stage 1: Rust builder |
| 20 | +# --------------------------------------------------------------------------- |
| 21 | +FROM rust:1.90-bookworm AS rust-builder |
| 22 | + |
| 23 | +WORKDIR /src |
| 24 | + |
| 25 | +# Install build dependencies (cmake required by quiche/BoringSSL, go required by quiche) |
| 26 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 27 | + cmake \ |
| 28 | + golang-go \ |
| 29 | + nasm \ |
| 30 | + && rm -rf /var/lib/apt/lists/* |
| 31 | + |
| 32 | +# Copy manifests first for better layer caching |
| 33 | +COPY Cargo.toml Cargo.lock rust-toolchain.toml ./ |
| 34 | +COPY crates crates |
| 35 | +COPY devolutions-gateway devolutions-gateway |
| 36 | +COPY devolutions-agent devolutions-agent |
| 37 | +COPY devolutions-session devolutions-session |
| 38 | +COPY jetsocat jetsocat |
| 39 | +COPY testsuite testsuite |
| 40 | +COPY tools tools |
| 41 | +COPY fuzz fuzz |
| 42 | + |
| 43 | +# Build only the gateway binary in release mode |
| 44 | +RUN cargo build --release --package devolutions-gateway \ |
| 45 | + && cp target/release/devolutions-gateway /usr/local/bin/devolutions-gateway |
| 46 | + |
| 47 | +# --------------------------------------------------------------------------- |
| 48 | +# Stage 2: Extract libxmf + PowerShell module from the official image |
| 49 | +# --------------------------------------------------------------------------- |
| 50 | +FROM devolutions/devolutions-gateway:${GATEWAY_VERSION} AS official-image |
| 51 | + |
| 52 | +# --------------------------------------------------------------------------- |
| 53 | +# Stage 3: Runtime |
| 54 | +# --------------------------------------------------------------------------- |
| 55 | +FROM debian:bookworm-slim |
| 56 | + |
| 57 | +LABEL maintainer="Devolutions Inc." |
| 58 | +LABEL description="Devolutions Gateway — built from source with QUIC agent tunnel" |
| 59 | + |
| 60 | +# Install PowerShell and runtime dependencies |
| 61 | +RUN apt-get update \ |
| 62 | + && apt-get install -y --no-install-recommends wget ca-certificates openssl curl \ |
| 63 | + && ARCH=$(dpkg --print-architecture) \ |
| 64 | + && if [ "$ARCH" = "arm64" ]; then \ |
| 65 | + PWSH_VERSION=7.4.6 \ |
| 66 | + && wget -q "https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-arm64.tar.gz" \ |
| 67 | + && mkdir -p /opt/microsoft/powershell/7 \ |
| 68 | + && tar -xzf "powershell-${PWSH_VERSION}-linux-arm64.tar.gz" -C /opt/microsoft/powershell/7 \ |
| 69 | + && chmod +x /opt/microsoft/powershell/7/pwsh \ |
| 70 | + && ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh \ |
| 71 | + && rm "powershell-${PWSH_VERSION}-linux-arm64.tar.gz"; \ |
| 72 | + else \ |
| 73 | + wget -q https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \ |
| 74 | + && dpkg -i packages-microsoft-prod.deb \ |
| 75 | + && rm packages-microsoft-prod.deb \ |
| 76 | + && apt-get update \ |
| 77 | + && apt-get install -y --no-install-recommends powershell; \ |
| 78 | + fi \ |
| 79 | + && rm -rf /var/lib/apt/lists/* |
| 80 | + |
| 81 | +ENV XDG_CACHE_HOME="/tmp/.cache" |
| 82 | +ENV XDG_DATA_HOME="/tmp/.local/share" |
| 83 | +ENV POWERSHELL_TELEMETRY_OPTOUT="1" |
| 84 | + |
| 85 | +ENV DGATEWAY_CONFIG_PATH="/tmp/devolutions-gateway" |
| 86 | +RUN mkdir -p "$DGATEWAY_CONFIG_PATH" |
| 87 | + |
| 88 | +WORKDIR /opt/devolutions/gateway |
| 89 | + |
| 90 | +ENV DGATEWAY_EXECUTABLE_PATH="/opt/devolutions/gateway/devolutions-gateway" |
| 91 | +ENV DGATEWAY_LIB_XMF_PATH="/opt/devolutions/gateway/libxmf.so" |
| 92 | +ENV DGATEWAY_WEBAPP_PATH="/opt/devolutions/gateway/webapp" |
| 93 | + |
| 94 | +# Gateway binary — built from THIS repo's source code |
| 95 | +COPY --from=rust-builder /usr/local/bin/devolutions-gateway $DGATEWAY_EXECUTABLE_PATH |
| 96 | + |
| 97 | +# Webapp — pre-built locally (pnpm build:gateway), output in webapp/dist/gateway-ui/ |
| 98 | +COPY webapp/dist/gateway-ui/ /opt/devolutions/gateway/webapp/client/ |
| 99 | + |
| 100 | +# libxmf — from official image (native library, not built from source) |
| 101 | +COPY --from=official-image /opt/devolutions/gateway/libxmf.so $DGATEWAY_LIB_XMF_PATH |
| 102 | + |
| 103 | +# PowerShell module — from official image (includes pre-compiled .NET DLLs) |
| 104 | +COPY --from=official-image /opt/microsoft/powershell/7/Modules/DevolutionsGateway /opt/microsoft/powershell/7/Modules/DevolutionsGateway |
| 105 | + |
| 106 | +# Entrypoint script from this repo's source |
| 107 | +COPY package/Linux/entrypoint.ps1 /usr/local/bin/entrypoint.ps1 |
| 108 | +RUN chmod +x /usr/local/bin/entrypoint.ps1 |
| 109 | + |
| 110 | +EXPOSE 7171 |
| 111 | +EXPOSE 8181 |
| 112 | +EXPOSE 4433/udp |
| 113 | + |
| 114 | +HEALTHCHECK --interval=30s --timeout=10s --retries=5 --start-period=15s \ |
| 115 | + CMD curl -sf http://localhost:7171/jet/health || exit 1 |
| 116 | + |
| 117 | +ENTRYPOINT ["pwsh", "-File", "/usr/local/bin/entrypoint.ps1"] |
0 commit comments