server: Use Dockerfile and build script instead of godockerize (#1971)

This is a replacement which is using the same Dockerfile godockerize
generates, as well as the same build commands. It isn't that nice, but is a
good starting point for improving the Dockerfile.
This commit is contained in:
Keegan Carruthers-Smith 2019-01-21 14:07:29 +02:00 committed by GitHub
parent 9eef8a395e
commit 6c34dfe018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 158 additions and 4 deletions

108
.dockerignore Normal file
View File

@ -0,0 +1,108 @@
.git/
/vagrant_ansible_inventory_default
/.vagrant
# Vim
*.swp
# JetBrains/IntelliJ
.idea
# Emacs
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
.\#*
.dir-locals.el
# Go
*.o
*.a
*.so
# Mac OS X
.DS_Store
# Python
*.py[cod]
__pycache__
# langkit
/workspace/
# Test binaries
*.test
grapher/python/pysonar2/tests
grapher/ruby/rubysonar/target
grapher/ruby/rubysonar/dependency-reduced-pom.xml
grapher/ruby/yard/.bundle
npm-debug.log
yarn-error.log
.codemod.bookmark
.elasticbeanstalk/
.tmp/*.jar
/cmd/frontend/internal/graphqlbackend/node_modules
/ui/artifacts
/ui/node_modules
/ui/assets/_goTemplates.js
/ui/assets/analytics.js
/ui/assets/bundle.js
/ui/assets/bundle.css
/ui/assets/sourcebox.js
/ui/assets/sourcebox.css
/ui/assets/test.js
/ui/assets/test.css
/ui/assets/vs
/ui/assets/*.html
/ui/assets/*.map
/ui/assets/extension
/ui/.tmp
*.json.actual
eb-bundle.zip
/cmd/frontend/internal/app/assets/assets_vfsdata.go
/release/
/conf/private
/provision/kubernetes/gen
/deploy/sourcegraph.com/src
/deploy/sourcegraph/src
# Sublime
*.sublime-project
*.sublime-workspace
.bin/
.env
/vendor/
.gtm/
cmd/src/debug
cmd/gitserver/debug
cmd/indexer/debug
/dev/e2e/log.html
/.gtm/
# Web
node_modules/
/web
# Extensions
/packages/sourcegraph-extension-api/dist
# Management console
/cmd/management-console/web
/cmd/management-console/assets
!/cmd/management-console/assets/assets_vfsdata.go

33
cmd/server/Dockerfile Normal file
View File

@ -0,0 +1,33 @@
# This Dockerfile was generate from github.com/sourcegraph/godockerize. It was
# not written by a human, and as such looks janky. As you change this file,
# please don't be scared to make it more pleasant / remove hadolint ingores.
FROM alpine:3.8
RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/v3.6/main" >> /etc/apk/repositories && \
echo "http://dl-cdn.alpinelinux.org/alpine/v3.6/community" >> /etc/apk/repositories
# hadolint ignore=DL3018
RUN apk add --no-cache 'postgresql-contrib=11.1-r0' 'postgresql=11.1-r0' 'redis=3.2.12-r0' bind-tools ca-certificates curl docker git@edge mailcap nginx openssh-client su-exec tini
# hadolint ignore=DL3017
RUN apk update && apk upgrade
RUN curl -o /usr/local/bin/syntect_server https://storage.googleapis.com/sourcegraph-artifacts/syntect_server/f85a9897d3c23ef84eb219516efdbb2d && chmod +x /usr/local/bin/syntect_server
# hadolint ignore=DL3003,DL3018,DL4006
RUN apk --no-cache add curl jansson-dev libseccomp-dev linux-headers autoconf pkgconfig make automake gcc g++ binutils && curl https://codeload.github.com/universal-ctags/ctags/tar.gz/7918d19fe358fae9bad1c264c4f5dc2dcde5cece | tar xz -C /tmp && cd /tmp/ctags-7918d19fe358fae9bad1c264c4f5dc2dcde5cece && ./autogen.sh && LDFLAGS=-static ./configure --program-prefix=universal- --enable-json --enable-seccomp && make -j8 && make install && cd && rm -rf /tmp/ctags-7918d19fe358fae9bad1c264c4f5dc2dcde5cece && apk --no-cache --purge del curl jansson-dev libseccomp-dev linux-headers autoconf pkgconfig make automake gcc g++ binutils
ENV GO111MODULES=on LANG=en_US.utf8 VERSION=$VERSION
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/server"]
COPY server /usr/local/bin/
COPY management-console /usr/local/bin/
COPY github-proxy /usr/local/bin/
COPY gitserver /usr/local/bin/
COPY query-runner /usr/local/bin/
COPY symbols /usr/local/bin/
COPY repo-updater /usr/local/bin/
COPY searcher /usr/local/bin/
COPY zoekt-archive-index /usr/local/bin/
COPY zoekt-sourcegraph-indexserver /usr/local/bin/
COPY zoekt-webserver /usr/local/bin/
COPY frontend /usr/local/bin/

View File

@ -4,8 +4,17 @@
cd $(dirname "${BASH_SOURCE[0]}")/../..
set -ex
OUTPUT=`mktemp -d -t sgserver`
cleanup() {
rm -rf "$OUTPUT"
}
trap cleanup EXIT
# Environment for building linux binaries
export GO111MODULE=on
GOBIN=$PWD/.bin go install github.com/sourcegraph/godockerize
export GOARCH=amd64
export GOOS=linux
export CGO_ENABLED=0
# Additional images passed in here when this script is called externally by our
# enterprise build scripts.
@ -15,8 +24,7 @@ additional_images=${@:-github.com/sourcegraph/sourcegraph/cmd/frontend}
# our enterprise build scripts.
server_pkg=${SERVER_PKG:-github.com/sourcegraph/sourcegraph/cmd/server}
./.bin/godockerize build --base 'alpine:3.8' -t ${IMAGE} --go-build-flags="-ldflags" --go-build-flags="-X github.com/sourcegraph/sourcegraph/pkg/version.version=${VERSION}" --env VERSION=${VERSION} --env GO111MODULES=on \
$server_pkg \
for pkg in $server_pkg \
github.com/sourcegraph/sourcegraph/cmd/management-console \
github.com/sourcegraph/sourcegraph/cmd/github-proxy \
github.com/sourcegraph/sourcegraph/cmd/gitserver \
@ -26,4 +34,9 @@ server_pkg=${SERVER_PKG:-github.com/sourcegraph/sourcegraph/cmd/server}
github.com/sourcegraph/sourcegraph/cmd/searcher \
github.com/google/zoekt/cmd/zoekt-archive-index \
github.com/google/zoekt/cmd/zoekt-sourcegraph-indexserver \
github.com/google/zoekt/cmd/zoekt-webserver $additional_images
github.com/google/zoekt/cmd/zoekt-webserver $additional_images; do
go build -ldflags "-X github.com/sourcegraph/sourcegraph/pkg/version.version=$VERSION" -buildmode exe -tags dist -o $OUTPUT/$(basename $pkg) $pkg
done
docker build -f Dockerfile -t $IMAGE $OUTPUT