Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Wolfi images #47182

Merged
merged 58 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
49e572d
Add initial buildWolfiDockerImage implementation
willdollman Jan 31, 2023
1874e05
Add ops set for building wolfi images
willdollman Jan 31, 2023
77a7275
Build wolfi images on branches and tweak package/base logic
willdollman Jan 31, 2023
7c088d9
Build candidate wolfi image
willdollman Jan 31, 2023
d22c18a
Add wolfi-specific build scripts for gitserver
willdollman Jan 31, 2023
2146757
Move Wolfi build files from cmd/ to enterprise/cmd
willdollman Jan 31, 2023
b0012fe
Re-enable wolfi docker push
willdollman Jan 31, 2023
9c75a06
Add wolfi builds for frontend
willdollman Jan 31, 2023
818f95e
Add github-proxy wolfi build
willdollman Jan 31, 2023
16b0d48
Add loadtest wolfi build
willdollman Jan 31, 2023
44e1149
Add migrator build
willdollman Jan 31, 2023
ccf1cb0
Update wolfi base image location
willdollman Feb 2, 2023
ede1c66
Add wolfi builds for OSS frontend and gitserver
willdollman Feb 2, 2023
bf8afa8
Add enterprise/migrator build script
willdollman Feb 2, 2023
217df1a
Add wolfi builds for repo-updater
willdollman Feb 2, 2023
1d51b94
Add wolfi builds for searcher
willdollman Feb 2, 2023
1862fa6
Add wolfi builds for symbols
willdollman Feb 2, 2023
880f6b9
Build additional full images
willdollman Feb 2, 2023
fd4fafb
Add wolfi builds for batcheshelper
willdollman Feb 2, 2023
a1028a1
Add wolfi build for precise code intel
willdollman Feb 2, 2023
d17877c
Add wolfi build for enterprise worker
willdollman Feb 2, 2023
26af851
Fix wolfi base image for precise code intel
willdollman Feb 2, 2023
c81407c
Always build x86_64 Wolfi images
willdollman Feb 2, 2023
0a2cc44
Build symbols again
willdollman Feb 2, 2023
285fae4
Try using non-Alpine golang container for symbols build
willdollman Feb 2, 2023
2c9f4a3
Revert to alpine golang build env
willdollman Feb 2, 2023
fd8ee3d
Build full wolfi images on the bazel queue
willdollman Feb 3, 2023
3be6b3e
Disable building symbols and bazel runner for now
willdollman Feb 3, 2023
f687b20
Tweak local-build scripts
willdollman Feb 3, 2023
ce0fc9e
Add rough initial versions of server wolfi builds
willdollman Feb 3, 2023
8db3b56
Try building images with bazel agent again
willdollman Feb 3, 2023
f099623
Actually use bazel for gitserver builds
willdollman Feb 3, 2023
fdcc1a5
Build symbols in chainguard:go
willdollman Feb 3, 2023
33e275b
Build all Go binaries for Wolfi with Bazel
willdollman Feb 3, 2023
1e403d9
Add wolfi build scripts for embeddings image
willdollman Apr 7, 2023
157a7bd
Rough initial version of the server image
willdollman Apr 12, 2023
c37af38
Specify platform for symbols go-build
willdollman Apr 12, 2023
a31e23a
Build 3rd party Wolfi images (#47368)
willdollman Apr 20, 2023
4fedb1d
Add bind-tools to all base images
willdollman Apr 20, 2023
5754459
Make docker build commands more consistent
willdollman Apr 20, 2023
53b494a
Add wolfi build scripts for llm-proxy
willdollman Apr 20, 2023
4425f4d
Add wolfi build scripts for executor-kubernetes
willdollman Apr 20, 2023
5662a68
Update build-wolfi.sh scripts to match latest build.sh scripts
willdollman Apr 20, 2023
1771885
shellfmt build.sh scripts
willdollman Apr 20, 2023
1ed2df9
Set up proper deps for wolfi images and base images
willdollman Apr 20, 2023
4ab2586
Add buildAllBaseImages no-op command
willdollman Apr 20, 2023
095023a
Use stepKeys in wolfi base image dependencies
willdollman Apr 20, 2023
cb080df
Sanitize stepKeys
willdollman Apr 20, 2023
30a478d
Remove some completed TODOs
willdollman Apr 24, 2023
d8ece3f
Remove images from wolfi pipeline
willdollman Apr 24, 2023
0985a7c
Regenerate CI reference
willdollman Apr 24, 2023
110688a
Remove symbols build flag
willdollman Apr 24, 2023
2a89c24
Add hadolint ignores to use of latest with Wolfi images
willdollman Apr 24, 2023
55e5cb8
Fix CMD formatting
willdollman Apr 24, 2023
c1ebf0b
Fix symbols go-build script
willdollman Apr 24, 2023
681b821
Merge branch 'main' into wolfi/build-wolfi
willdollman Apr 24, 2023
7878dad
Specify exact Wolfi images to build
willdollman Apr 24, 2023
b4e44bb
sg generate
willdollman Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/frontend/Dockerfile.wolfi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dockerfile for Wolfi-based images
# This is currently being tested in parallel to Alpine - you don't need to update this
# file if you change the regular Dockerfile.

# hadolint ignore=DL3007
FROM us.gcr.io/sourcegraph-dev/wolfi-sourcegraph-base:latest

ARG COMMIT_SHA="unknown"
ARG DATE="unknown"
ARG VERSION="unknown"

LABEL org.opencontainers.image.revision=${COMMIT_SHA}
LABEL org.opencontainers.image.created=${DATE}
LABEL org.opencontainers.image.version=${VERSION}
LABEL com.sourcegraph.github.url=https://github.com/sourcegraph/sourcegraph/commit/${COMMIT_SHA}

ENV CONFIGURATION_MODE=server PGDATABASE=sg PGHOST=pgsql PGPORT=5432 PGSSLMODE=disable PGUSER=sg CODEINTEL_PGDATABASE=sg CODEINTEL_PGHOST=codeintel-db CODEINTEL_PGPORT=5432 CODEINTEL_PGSSLMODE=disable CODEINTEL_PGUSER=sg PUBLIC_REPO_REDIRECTS=true
USER sourcegraph

CMD ["serve"]
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/frontend"]
COPY frontend /usr/local/bin/
28 changes: 28 additions & 0 deletions cmd/frontend/build-wolfi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# We want to build multiple go binaries, so we use a custom build step on CI.
cd "$(dirname "${BASH_SOURCE[0]}")"/../..
set -ex

OUTPUT=$(mktemp -d -t sgdockerbuild_XXXXXXX)
cleanup() {
rm -rf "$OUTPUT"
}
trap cleanup EXIT

# 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/frontend"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't port the bazel build in that one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just been tracking what the build.sh script on main does, and for this image it doesn't use bazel - https://github.com/sourcegraph/sourcegraph/blob/main/cmd/frontend/build.sh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's because in our branch, it's done in a build-bazel.sh

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 $IMAGE"
docker build -f cmd/frontend/Dockerfile.wolfi -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION
21 changes: 21 additions & 0 deletions cmd/github-proxy/Dockerfile.wolfi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dockerfile for Wolfi-based images
# This is currently being tested in parallel to Alpine - you don't need to update this
# file if you change the regular Dockerfile.

# hadolint ignore=DL3007
FROM us.gcr.io/sourcegraph-dev/wolfi-sourcegraph-base:latest

ARG COMMIT_SHA="unknown"
ARG DATE="unknown"
ARG VERSION="unknown"

LABEL org.opencontainers.image.revision=${COMMIT_SHA}
LABEL org.opencontainers.image.created=${DATE}
LABEL org.opencontainers.image.version=${VERSION}
LABEL com.sourcegraph.github.url=https://github.com/sourcegraph/sourcegraph/commit/${COMMIT_SHA}

ENV LOG_REQUEST=true
USER sourcegraph

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/github-proxy"]
COPY github-proxy /usr/local/bin/
44 changes: 44 additions & 0 deletions cmd/github-proxy/build-wolfi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# We want to build multiple go binaries, so we use a custom build step on CI.
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

bazel build //cmd/github-proxy \
--stamp \
--workspace_status_command=./dev/bazel_stamp_vars.sh \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64

out=$(bazel cquery //cmd/github-proxy --output=files)
cp "$out" "$OUTPUT"

docker build -f cmd/github-proxy/Dockerfile.wolfi -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

pkg="github.com/sourcegraph/sourcegraph/cmd/github-proxy"
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"

docker build -f cmd/github-proxy/Dockerfile.wolfi -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION
23 changes: 23 additions & 0 deletions cmd/gitserver/Dockerfile.wolfi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Dockerfile for Wolfi-based images
# This is currently being tested in parallel to Alpine - you don't need to update this
# file if you change the regular Dockerfile.

# hadolint ignore=DL3007
FROM us.gcr.io/sourcegraph-dev/wolfi-gitserver-base:latest

ARG COMMIT_SHA="unknown"
ARG DATE="unknown"
ARG VERSION="unknown"

LABEL org.opencontainers.image.revision=${COMMIT_SHA}
LABEL org.opencontainers.image.created=${DATE}
LABEL org.opencontainers.image.version=${VERSION}
LABEL com.sourcegraph.github.url=https://github.com/sourcegraph/sourcegraph/commit/${COMMIT_SHA}

RUN mkdir -p /data/repos && chown -R sourcegraph:sourcegraph /data/repos
USER sourcegraph

WORKDIR /

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/gitserver"]
COPY gitserver /usr/local/bin/
45 changes: 45 additions & 0 deletions cmd/gitserver/build-wolfi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

# We want to build multiple go binaries, so we use a custom build step on CI.
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
bazel build //cmd/gitserver \
--stamp \
--workspace_status_command=./dev/bazel_stamp_vars.sh \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64

out=$(bazel cquery //cmd/gitserver --output=files)
cp "$out" "$OUTPUT"

docker build -f cmd/gitserver/Dockerfile.wolfi -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

pkg="github.com/sourcegraph/sourcegraph/cmd/gitserver"
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"

docker build -f cmd/gitserver/Dockerfile.wolfi -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION
18 changes: 18 additions & 0 deletions cmd/loadtest/Dockerfile.wolfi
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Dockerfile for Wolfi-based images
# This is currently being tested in parallel to Alpine - you don't need to update this
# file if you change the regular Dockerfile.

# hadolint ignore=DL3007
FROM us.gcr.io/sourcegraph-dev/wolfi-sourcegraph-base:latest

ARG COMMIT_SHA="unknown"
ARG DATE="unknown"
ARG VERSION="unknown"

LABEL org.opencontainers.image.revision=${COMMIT_SHA}
LABEL org.opencontainers.image.created=${DATE}
LABEL org.opencontainers.image.version=${VERSION}
LABEL com.sourcegraph.github.url=https://github.com/sourcegraph/sourcegraph/commit/${COMMIT_SHA}

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/loadtest"]
COPY loadtest /usr/local/bin/
44 changes: 44 additions & 0 deletions cmd/loadtest/build-wolfi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# We want to build multiple go binaries, so we use a custom build step on CI.
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

bazel build //cmd/loadtest \
--stamp \
--workspace_status_command=./dev/bazel_stamp_vars.sh \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64

out=$(bazel cquery //cmd/loadtest --output=files)
cp "$out" "$OUTPUT"

docker build -f cmd/loadtest/Dockerfile.wolfi -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

pkg="github.com/sourcegraph/sourcegraph/cmd/loadtest"
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"

docker build -f cmd/loadtest/Dockerfile.wolfi -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION
21 changes: 21 additions & 0 deletions cmd/migrator/Dockerfile.wolfi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dockerfile for Wolfi-based images
# This is currently being tested in parallel to Alpine - you don't need to update this
# file if you change the regular Dockerfile.

# hadolint ignore=DL3007
FROM us.gcr.io/sourcegraph-dev/wolfi-sourcegraph-base:latest

ARG COMMIT_SHA="unknown"
ARG DATE="unknown"
ARG VERSION="unknown"

LABEL org.opencontainers.image.revision=${COMMIT_SHA}
LABEL org.opencontainers.image.created=${DATE}
LABEL org.opencontainers.image.version=${VERSION}
LABEL com.sourcegraph.github.url=https://github.com/sourcegraph/sourcegraph/commit/${COMMIT_SHA}

USER sourcegraph

ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/migrator"]
COPY migrator /usr/local/bin/
COPY schema-descriptions /schema-descriptions
115 changes: 115 additions & 0 deletions cmd/migrator/build-wolfi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env bash

# This script builds the migrator 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

bazel build //cmd/migrator \
--stamp \
--workspace_status_command=./dev/bazel_stamp_vars.sh \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64

out=$(bazel cquery //cmd/migrator --output=files)
cp "$out" "$OUTPUT"

docker build -f cmd/migrator/Dockerfile.wolfi -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=${1:-"github.com/sourcegraph/sourcegraph/cmd/migrator"}
output="$OUTPUT/$(basename "$pkg")"
# shellcheck disable=SC2153
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" "$pkg"

echo "--- compile schema descriptions"
mkdir -p "${OUTPUT}/schema-descriptions"

# See internal/database/migration/cliutil/drift-schemas/generate-all.sh
gcs_versions=(
v3.20.0 v3.20.1
v3.21.0 v3.21.1 v3.21.2
v3.22.0 v3.22.1
v3.23.0
v3.24.0 v3.24.1
v3.25.0 v3.25.1 v3.25.2
v3.26.0 v3.26.1 v3.26.2 v3.26.3
v3.27.0 v3.27.1 v3.27.2 v3.27.3 v3.27.4 v3.27.5
v3.28.0
v3.29.0 v3.29.1
v3.30.0 v3.30.1 v3.30.2 v3.30.3 v3.30.4
v3.31.0 v3.31.1 v3.31.2
v3.32.0 v3.32.1
v3.33.0 v3.33.1 v3.33.2
v3.34.0 v3.34.1 v3.34.2
v3.35.0 v3.35.1 v3.35.2
v3.36.0 v3.36.1 v3.36.2 v3.36.3
v3.37.0
v3.38.0 v3.38.1
v3.39.0 v3.39.1
v3.40.0 v3.40.1 v3.40.2
v3.41.0 v3.41.1
)
gcs_filenames=(
internal_database_schema.json
internal_database_schema.codeintel.json
internal_database_schema.codeinsights.json
)

function download_gcs() {
outfile="${OUTPUT}/schema-descriptions/${1}-${2}"
if ! curl -fsSL "https://storage.googleapis.com/sourcegraph-assets/migrations/drift/${1}-${2}" 2>/dev/null >"${outfile}"; then
rm "${outfile}"
fi
}

for version in "${gcs_versions[@]}"; do
echo "Persisting schemas for ${version} from GCS..."
for filename in "${gcs_filenames[@]}"; do
download_gcs "${version}" "${filename}"
done
done

git_versions=(
v3.42.0 v3.42.1 v3.42.2
v3.43.0 v3.43.1 v3.43.2
v4.0.0 v4.0.1
v4.1.0 v4.1.1 v4.1.2 v4.1.3
v4.2.0 v4.2.1
v4.3.0 v4.3.1
v4.4.0 v4.4.1 v4.4.2
v4.5.0 v4.5.1
v5.0.0
)
for version in "${git_versions[@]}"; do
echo "Persisting schemas for ${version} from Git..."
git show "${version}:internal/database/schema.json" >"${OUTPUT}/schema-descriptions/${version}-internal_database_schema.json"
git show "${version}:internal/database/schema.codeintel.json" >"${OUTPUT}/schema-descriptions/${version}-internal_database_schema.codeintel.json"
git show "${version}:internal/database/schema.codeinsights.json" >"${OUTPUT}/schema-descriptions/${version}-internal_database_schema.codeinsights.json"
done

echo "--- docker build"
docker build -f cmd/migrator/Dockerfile.wolfi -t "$IMAGE" "$OUTPUT" \
--progress=plain \
--build-arg COMMIT_SHA \
--build-arg DATE \
--build-arg VERSION
Loading