¡Hola, amigos!

In this post, I will quickly descibe how you can build your own drone.io docker image.

Drone is very popular container native CI/CD platform. Not long time ago, there was release of new 1.0 version of drone. Which brang a lot of cool features and new license. The license tells that we can use Enterprise version of drone for free without any limits by building our own docker image if we are individuals or startup (read the licence for more detail).

So, how to build it?

Instructions

First, clone the drone repo to your local machine.

git clone [email protected]:drone/drone.git

Second, checkout to version of drone you want to build. For example, I want to build v1.3.1:

git checkout v1.3.1

We will use single dockerfile to build the image. To do so, we need to add extra step to existing dockerfile which is in docker directory. Let’s say we want to build docker image for linux OS and amd64 architecture, then we will edit docker/Dockerfile.server.linux.amd64.

If you check the dockerfile you will see, that binaries are just copied into docker image during the build and they are built outside of the docker build. So, the step we will add to dockerfile is go build step.

To build the binary, we need to know what version of go is used for building binary in original docker image. We can find it in drone.yml build step. For version 1.3.1 of drone golang:1.12.9 docker image is used for building binaries.

Then, we use same image to build binary in our dockerfile:

docker/Dockerfile.server.linux.amd64
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
FROM golang:1.12.9 as builder

WORKDIR /go/src/github.com/drone/drone
COPY . .

ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 1
ENV REPO github.com/drone/drone
ENV GO111MODULE on
RUN go build -tags nolimit -ldflags "-extldflags \"-static\"" -o release/linux/${GOARCH}/drone-server ${REPO}/cmd/drone-server

FROM alpine:3.9 as alpine
RUN apk add -U --no-cache ca-certificates

FROM alpine:3.9
EXPOSE 80 443
VOLUME /data

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 --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

COPY --from=builder /go/src/github.com/drone/drone/release/linux/amd64/drone-server /bin/
ENTRYPOINT ["/bin/drone-server"]

Also we need to delete .dockerignore file from root of the repo.

rm .dockerignore

Then we build docker image like:

docker build -t alikhil/drone:1.3.1 -f docker/Dockerfile.server.linux.amd64 .

That’s all! Now you can use own newly built docker image instead of official one if your use case meet license conditions.