sourcegraph/cmd/worker/build.sh
Dave Try 321e0e9d01
ci: enable bazel builds for docker images (#51241)
Reintroduces the same changes as
https://github.com/sourcegraph/sourcegraph/pull/51104 minus
syntax-highlighter which we're unable to compile with the right
toolchain at the moment.

Tested as a full main-dry-run, as well as running the stack with compose
and checking indexing and syntax-highlighting.

Executors are also built correctly. 


## Test plan

CI + manual test via compose.

---------

Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr>
2023-04-28 10:41:13 +02:00

43 lines
1.2 KiB
Bash

#!/usr/bin/env bash
# This script builds the worker docker image.
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
set -ex
OUTPUT=$(mktemp -d -t sgdockerbuild_XXXXXXX)
cleanup() {
rm -rf "$OUTPUT"
}
trap cleanup EXIT
if [[ "${DOCKER_BAZEL:-false}" == "true" ]]; then
./dev/ci/bazel.sh build //cmd/worker
out=$(./dev/ci/bazel.sh cquery //cmd/worker --output=files)
cp "$out" "$OUTPUT"
docker build -f cmd/worker/Dockerfile -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION
exit $?
fi
# Environment for building linux binaries
export GO111MODULE=on
export GOARCH=amd64
export GOOS=linux
export CGO_ENABLED=0
echo "--- go build"
pkg="github.com/sourcegraph/sourcegraph/cmd/worker"
go build -trimpath -ldflags "-X github.com/sourcegraph/sourcegraph/internal/version.version=$VERSION -X github.com/sourcegraph/sourcegraph/internal/version.timestamp=$(date +%s)" -buildmode exe -tags dist -o "$OUTPUT/$(basename $pkg)" "$pkg"
echo "--- docker build"
docker build -f cmd/worker/Dockerfile -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION