Skip to content

Commit 3c0dd65

Browse files
authored
all: Replace godockerize with Dockerfiles (sourcegraph#1976)
We use a branch of godockerize which generates a build.sh and Dockerfile instead of directly building the docker image. https://github.com/sourcegraph/godockerize/tree/gen-build This was run on all main entrypoints (excluding a few which already have a build.sh / shouldn't be docker images): go list -f '{{ if (eq .Name "main") }}{{.ImportPath}}{{ end }}' ./... \ | grep cmd | grep -v goreman | grep -v 'schemadoc' | grep -v /server \ | while read pkg; do godockerize build $pkg; done The build.sh should likely be refactored into using a shared shell script. But for now this gives us a nice and easy to change replacement. This commit also removes godockerize from CI and our go.mod.
1 parent 7d79756 commit 3c0dd65

24 files changed

Lines changed: 364 additions & 22 deletions

File tree

cmd/frontend/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Dockerfile was generated from github.com/sourcegraph/godockerize. It
2+
# was not written by a human, and as such looks janky. As you change this
3+
# file, please don't be scared to make it more pleasant / remove hadolint
4+
# ignores.
5+
6+
FROM alpine:3.8
7+
# hadolint ignore=DL3018
8+
RUN apk add --no-cache bind-tools ca-certificates mailcap tini
9+
RUN addgroup -S sourcegraph && adduser -S -G sourcegraph -h /home/sourcegraph sourcegraph
10+
ENV CONFIGURATION_MODE=server PGDATABASE=sg PGHOST=pgsql PGPORT=5432 PGSSLMODE=disable PGUSER=sg PUBLIC_REPO_REDIRECTS=true
11+
USER sourcegraph
12+
CMD ["serve"]
13+
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/frontend"]
14+
COPY frontend /usr/local/bin/

cmd/frontend/build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# We want to build multiple go binaries, so we use a custom build step on CI.
4+
cd $(dirname "${BASH_SOURCE[0]}")/../..
5+
set -ex
6+
7+
OUTPUT=`mktemp -d -t sgdockerbuild_XXXXXXX`
8+
cleanup() {
9+
rm -rf "$OUTPUT"
10+
}
11+
trap cleanup EXIT
12+
13+
# Environment for building linux binaries
14+
export GO111MODULE=on
15+
export GOARCH=amd64
16+
export GOOS=linux
17+
export CGO_ENABLED=0
18+
19+
for pkg in github.com/sourcegraph/sourcegraph/cmd/frontend; do
20+
go build -ldflags "-X github.com/sourcegraph/sourcegraph/pkg/version.version=$VERSION" -buildmode exe -tags dist -o $OUTPUT/$(basename $pkg) $pkg
21+
done
22+
23+
docker build -f cmd/frontend/Dockerfile -t $IMAGE $OUTPUT

cmd/github-proxy/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This Dockerfile was generated from github.com/sourcegraph/godockerize. It
2+
# was not written by a human, and as such looks janky. As you change this
3+
# file, please don't be scared to make it more pleasant / remove hadolint
4+
# ignores.
5+
6+
FROM alpine:3.8
7+
# hadolint ignore=DL3018
8+
RUN apk add --no-cache bind-tools ca-certificates mailcap tini
9+
RUN addgroup -S sourcegraph && adduser -S -G sourcegraph -h /home/sourcegraph sourcegraph
10+
ENV LOG_REQUEST=true
11+
USER sourcegraph
12+
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/github-proxy"]
13+
COPY github-proxy /usr/local/bin/

cmd/github-proxy/build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# We want to build multiple go binaries, so we use a custom build step on CI.
4+
cd $(dirname "${BASH_SOURCE[0]}")/../..
5+
set -ex
6+
7+
OUTPUT=`mktemp -d -t sgdockerbuild_XXXXXXX`
8+
cleanup() {
9+
rm -rf "$OUTPUT"
10+
}
11+
trap cleanup EXIT
12+
13+
# Environment for building linux binaries
14+
export GO111MODULE=on
15+
export GOARCH=amd64
16+
export GOOS=linux
17+
export CGO_ENABLED=0
18+
19+
for pkg in github.com/sourcegraph/sourcegraph/cmd/github-proxy; do
20+
go build -ldflags "-X github.com/sourcegraph/sourcegraph/pkg/version.version=$VERSION" -buildmode exe -tags dist -o $OUTPUT/$(basename $pkg) $pkg
21+
done
22+
23+
docker build -f cmd/github-proxy/Dockerfile -t $IMAGE $OUTPUT

cmd/gitserver/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Dockerfile was generated from github.com/sourcegraph/godockerize. It
2+
# was not written by a human, and as such looks janky. As you change this
3+
# file, please don't be scared to make it more pleasant / remove hadolint
4+
# ignores.
5+
6+
FROM alpine:3.8
7+
RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
8+
echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
9+
# hadolint ignore=DL3018
10+
RUN apk add --no-cache bind-tools ca-certificates git@edge mailcap openssh-client tini
11+
RUN addgroup -S sourcegraph && adduser -S -G sourcegraph -h /home/sourcegraph sourcegraph && mkdir -p /data/repos && chown -R sourcegraph:sourcegraph /data/repos
12+
USER sourcegraph
13+
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/gitserver"]
14+
COPY gitserver /usr/local/bin/

cmd/gitserver/build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# We want to build multiple go binaries, so we use a custom build step on CI.
4+
cd $(dirname "${BASH_SOURCE[0]}")/../..
5+
set -ex
6+
7+
OUTPUT=`mktemp -d -t sgdockerbuild_XXXXXXX`
8+
cleanup() {
9+
rm -rf "$OUTPUT"
10+
}
11+
trap cleanup EXIT
12+
13+
# Environment for building linux binaries
14+
export GO111MODULE=on
15+
export GOARCH=amd64
16+
export GOOS=linux
17+
export CGO_ENABLED=0
18+
19+
for pkg in github.com/sourcegraph/sourcegraph/cmd/gitserver; do
20+
go build -ldflags "-X github.com/sourcegraph/sourcegraph/pkg/version.version=$VERSION" -buildmode exe -tags dist -o $OUTPUT/$(basename $pkg) $pkg
21+
done
22+
23+
docker build -f cmd/gitserver/Dockerfile -t $IMAGE $OUTPUT

cmd/loadtest/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This Dockerfile was generated from github.com/sourcegraph/godockerize. It
2+
# was not written by a human, and as such looks janky. As you change this
3+
# file, please don't be scared to make it more pleasant / remove hadolint
4+
# ignores.
5+
6+
FROM alpine:3.8
7+
# hadolint ignore=DL3018
8+
RUN apk add --no-cache bind-tools ca-certificates mailcap tini
9+
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/loadtest"]
10+
COPY loadtest /usr/local/bin/

cmd/loadtest/build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# We want to build multiple go binaries, so we use a custom build step on CI.
4+
cd $(dirname "${BASH_SOURCE[0]}")/../..
5+
set -ex
6+
7+
OUTPUT=`mktemp -d -t sgdockerbuild_XXXXXXX`
8+
cleanup() {
9+
rm -rf "$OUTPUT"
10+
}
11+
trap cleanup EXIT
12+
13+
# Environment for building linux binaries
14+
export GO111MODULE=on
15+
export GOARCH=amd64
16+
export GOOS=linux
17+
export CGO_ENABLED=0
18+
19+
for pkg in github.com/sourcegraph/sourcegraph/cmd/loadtest; do
20+
go build -ldflags "-X github.com/sourcegraph/sourcegraph/pkg/version.version=$VERSION" -buildmode exe -tags dist -o $OUTPUT/$(basename $pkg) $pkg
21+
done
22+
23+
docker build -f cmd/loadtest/Dockerfile -t $IMAGE $OUTPUT

cmd/management-console/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This Dockerfile was generated from github.com/sourcegraph/godockerize. It
2+
# was not written by a human, and as such looks janky. As you change this
3+
# file, please don't be scared to make it more pleasant / remove hadolint
4+
# ignores.
5+
6+
FROM alpine:3.8
7+
# hadolint ignore=DL3018
8+
RUN apk add --no-cache bind-tools ca-certificates mailcap tini
9+
RUN addgroup -S sourcegraph && adduser -S -G sourcegraph -h /home/sourcegraph sourcegraph
10+
ENV PGDATABASE=sg PGHOST=pgsql PGPORT=5432 PGSSLMODE=disable PGUSER=sg
11+
USER sourcegraph
12+
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/management-console"]
13+
COPY management-console /usr/local/bin/

cmd/management-console/build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# We want to build multiple go binaries, so we use a custom build step on CI.
4+
cd $(dirname "${BASH_SOURCE[0]}")/../..
5+
set -ex
6+
7+
OUTPUT=`mktemp -d -t sgdockerbuild_XXXXXXX`
8+
cleanup() {
9+
rm -rf "$OUTPUT"
10+
}
11+
trap cleanup EXIT
12+
13+
# Environment for building linux binaries
14+
export GO111MODULE=on
15+
export GOARCH=amd64
16+
export GOOS=linux
17+
export CGO_ENABLED=0
18+
19+
for pkg in github.com/sourcegraph/sourcegraph/cmd/management-console; do
20+
go build -ldflags "-X github.com/sourcegraph/sourcegraph/pkg/version.version=$VERSION" -buildmode exe -tags dist -o $OUTPUT/$(basename $pkg) $pkg
21+
done
22+
23+
docker build -f cmd/management-console/Dockerfile -t $IMAGE $OUTPUT

0 commit comments

Comments
 (0)