kong-kong
SUCCESS
10m 19s
History Source
SummaryIterations1Transcript8Dockerfile
Dockerfile63 lines · 1994 chars
FROM kong:3.9.1-ubuntu

# Allow opting into building Kong from source via BUILD_FROM_SOURCE; default is false (use prebuilt binaries from base image)
ARG BUILD_FROM_SOURCE=false
ENV DEBIAN_FRONTEND=noninteractive

# Use root for package management
USER root

# Optionally install build dependencies if building from source
RUN if [ "${BUILD_FROM_SOURCE}" = "true" ]; then \
      apt-get update && \
      apt-get install -y --no-install-recommends \
        build-essential \
        curl \
        ca-certificates \
        git \
        unzip \
        pkg-config \
        libyaml-dev \
        libprotobuf-dev \
        libssl-dev \
        python3 \
        python3-setuptools && \
      rm -rf /var/lib/apt/lists/*; \
    else \
      echo "Not building from source; skipping build dependencies."; \
    fi

# Prepare build workspace
RUN mkdir -p /kong
WORKDIR /kong

# Copy repository sources (will not affect runtime if not building from source)
COPY . /kong

# If BUILD_FROM_SOURCE is true, fetch Bazelisk and Rust and attempt to build Kong
RUN if [ "${BUILD_FROM_SOURCE}" = "true" ]; then \
      mkdir -p /usr/local/bin && \
      curl -sS -L https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-amd64 -o /usr/local/bin/bazel && \
      chmod +x /usr/local/bin/bazel && \
      curl -sS -L https://sh.rustup.rs | sh -s -- -y --no-modify-path && \
      . $HOME/.cargo/env; \
      rustup toolchain install stable; \
      rustup default stable; \
      make build-kong && \
      if [ -f bazel-bin/build/kong/kong ]; then \
        cp bazel-bin/build/kong/kong /usr/local/bin/kong; \
        chmod +x /usr/local/bin/kong; \
      fi; \
    else \
      echo "BUILD_FROM_SOURCE is false; skip building from source"; \
    fi

# Expose Kong's common ports
EXPOSE 8000 8443 8001 8002

# Ensure Kong is found in PATH
ENV PATH=/usr/local/bin:$PATH

# Default command: start Kong (will use the prebuilt binary if not building from source)
CMD ["kong", "start"]