Skip to content

Custom Drone Docker build

Custom Drone Docker build refers to the process of compiling the Drone CI server from source to bypass the build limits found in the official versions. The standard open-source edition of Drone typically imposes a restriction of approximately 5,000 builds, which requires the user to manually compile the software using go build to unlock full functionality or access enterprise features without licensing.^[400-devops-04-ci-cd-pipelines-drone.md]

Build Flags

To remove functional restrictions during compilation, specific build tags must be used with the go build command.

  • Enterprise Edition (Unlimited): Use -tags "nolimit" to remove limits^[400-devops-04-ci-cd-pipelines-drone.md].
  • Open Source Edition (Unlimited): Use -tags "oss nolimit"^[400-devops-04-ci-cd-pipelines-drone.md].

Docker Build Example

The following Dockerfile demonstrates how to compile a nolimit version of Drone (specifically version 2.15.0) inside a Docker container.^[400-devops-04-ci-cd-pipelines-drone.md]

This method uses a multi-stage build process to ensure the final image remains lightweight.

Stage 1: Builder

This stage downloads the source code and compiles the binary.

FROM golang:1.18-alpine AS Builder

# Configure mirrors and timezone
RUN sed -i 's/https:\/\/dl-cdn.alpinelinux.org/http:\/\/mirrors.tuna.tsinghua.edu.cn/' /etc/apk/repositories && \
    echo "Asia/Shanghai" > /etc/timezone

# Install build dependencies and configure [Go modules](<./go-modules.md>)
RUN apk add build-base && \
    go env -w GO111MODULE=on 

# Define Drone Version
ENV DRONE_VERSION 2.15.0

WORKDIR /src

# Download and extract source code
RUN apk add curl && curl -L https://github.com/drone/drone/archive/refs/tags/v${DRONE_VERSION}.tar.gz -o v${DRONE_VERSION}.tar.gz && \
    tar zxvf v${DRONE_VERSION}.tar.gz && rm v${DRONE_VERSION}.tar.gz

WORKDIR /src/drone-${DRONE_VERSION}

# Download dependencies
RUN go mod download

# Set compile flags and build (nolimit tag)
ENV CGO_CFLAGS="-g -O2 -Wno-return-local-addr"
RUN go build -ldflags "-extldflags \"-static\"" -tags="nolimit" github.com/drone/drone/cmd/drone-server

Stage 2: Certs & Final Image

The final stage sets up the runtime environment, copies the compiled binary, and configures default environment variables for the Drone server^[400-devops-04-ci-cd-pipelines-drone.md].

# Stage for certificates
FROM alpine:3.13 AS Certs
RUN sed -i 's/https:\/\/dl-cdn.alpinelinux.org/http:\/\/mirrors.tuna.tsinghua.edu.cn/' /etc/apk/repositories && \
    echo "Asia/Shanghai" > /etc/timezone
RUN apk add -U --no-cache ca-certificates

# Final runtime image
FROM alpine:3.16
EXPOSE 80 443
VOLUME /data

RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

# Environment configuration
ENV GODEBUG netdns=go
ENV XDG_CACHE_HOME /data
ENV DRONE_DATABASE_DRIVER sqlite3
ENV DRONE_DATABASE_DATASOURCE /data/database.sqlite
ENV DRONE_RUNNER_OS=linux
ENV DRONE_RUNNER_ARCH=amd64
ENV DRONE_SERVER_PORT=:80
ENV DRONE_SERVER_HOST=localhost
ENV DRONE_DATADOG_ENABLED=true
ENV DRONE_DATADOG_ENDPOINT=https://stats.drone.ci/api/v1/series

# Copy certs and binary
COPY --from=Certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=Builder /src/drone-2.15.0/drone-server /bin/drone-server

ENTRYPOINT ["/bin/drone-server"]

To build the image using this Dockerfile, run the following command in the same directory:

docker build -t yudady/drone:2.15.0 .
^[400-devops-04-ci-cd-pipelines-drone.md]

Sources

  • 400-devops-04-ci-cd-pipelines-drone.md