mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:12:02 +00:00
Reverts sourcegraph/sourcegraph#64351 ## Test plan Need to test on main due to main-only CI steps (even with main dry-run)
116 lines
3.7 KiB
Python
116 lines
3.7 KiB
Python
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
|
load("//dev:oci_defs.bzl", "image_repository", "oci_image", "oci_push", "oci_tarball")
|
|
load("//dev:oci_defs.bzl", "pkg_tar")
|
|
load("@container_structure_test//:defs.bzl", "container_structure_test")
|
|
|
|
go_library(
|
|
name = "migrator_lib",
|
|
srcs = ["main.go"],
|
|
importpath = "github.com/sourcegraph/sourcegraph/cmd/migrator",
|
|
tags = [TAG_INFRA_RELEASE],
|
|
visibility = ["//visibility:private"],
|
|
deps = [
|
|
"//cmd/migrator/shared",
|
|
"//internal/env",
|
|
"//internal/oobmigration/migrations/register",
|
|
"//internal/sanitycheck",
|
|
"//internal/version",
|
|
"@com_github_sourcegraph_log//:log",
|
|
],
|
|
)
|
|
|
|
go_binary(
|
|
name = "migrator",
|
|
embed = [":migrator_lib"],
|
|
tags = [TAG_INFRA_RELEASE],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# This rule builds a tarball of the database schema descriptions that only contains the current database schema
|
|
# description. If the build is not stamped with a proper VERSION env var, this will end up as "dev-...".
|
|
genrule(
|
|
name = "tar_current_schema_descriptions",
|
|
srcs = [
|
|
"//internal/database:schema.json",
|
|
"//internal/database:schema.codeinsights.json",
|
|
"//internal/database:schema.codeintel.json",
|
|
],
|
|
outs = ["current_schema_description.tar"],
|
|
cmd = """\
|
|
if grep -q "STABLE_VERSION" bazel-out/stable-status.txt; then
|
|
# When we're stamping, we can find the current version in the stable-status.
|
|
# But we do stamp main builds with a specific format, which is irrelevant for migrator, so we override this to be dev.
|
|
stable_version="$$(cat bazel-out/stable-status.txt | grep STABLE_VERSION | cut -d' ' -f2)"
|
|
if ! [[ $$stable_version =~ ^[0-9]\\.[0-9]+\\.[0-9]+ ]]; then
|
|
echo "🟠 (//cmd/migrator:tar_current_schema_descriptions) Stamping with dev version, will use "dev" as current version"
|
|
echo $$stable_version
|
|
version="dev"
|
|
else
|
|
version="v$$stable_version"
|
|
fi
|
|
else
|
|
# When not, usually during local development, we just use dev instead.
|
|
version="dev"
|
|
fi
|
|
mkdir -p schema-descriptions/
|
|
cp $(location //internal/database:schema.json) schema-descriptions/$${version}-internal_database_schema.json
|
|
cp $(location //internal/database:schema.codeinsights.json) schema-descriptions/$${version}-internal_database_schema.codeinsights.json
|
|
cp $(location //internal/database:schema.codeintel.json) schema-descriptions/$${version}-internal_database_schema.codeintel.json
|
|
|
|
if tar --version | grep -q bsdtar; then
|
|
tar -cf $@ --uid=0 --gid=0 --numeric-owner schema-descriptions/
|
|
else
|
|
tar -cf $@ --owner=:0 --group=:0 --numeric-owner schema-descriptions/
|
|
fi
|
|
""",
|
|
stamp = -1,
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
pkg_tar(
|
|
name = "tar_migrator",
|
|
srcs = [":migrator"],
|
|
)
|
|
|
|
oci_image(
|
|
name = "image",
|
|
base = "//wolfi-images/sourcegraph-base:base_image",
|
|
entrypoint = [
|
|
"/sbin/tini",
|
|
"--",
|
|
"/migrator",
|
|
],
|
|
tars = [
|
|
":tar_migrator",
|
|
":tar_current_schema_descriptions",
|
|
"//cmd/migrator/airgappedgen:tar_schema_descriptions",
|
|
],
|
|
user = "sourcegraph",
|
|
)
|
|
|
|
oci_tarball(
|
|
name = "image_tarball",
|
|
image = ":image",
|
|
repo_tags = ["migrator:candidate"],
|
|
visibility = ["//testing/tools/upgradetest:__pkg__"],
|
|
)
|
|
|
|
container_structure_test(
|
|
name = "image_test",
|
|
timeout = "short",
|
|
configs = ["image_test.yaml"],
|
|
driver = "docker",
|
|
image = ":image",
|
|
tags = [
|
|
"exclusive",
|
|
"requires-network",
|
|
TAG_INFRA_RELEASE,
|
|
],
|
|
)
|
|
|
|
oci_push(
|
|
name = "candidate_push",
|
|
image = ":image",
|
|
repository = image_repository("migrator"),
|
|
)
|