sourcegraph/cmd/server/macro.bzl
William Bezuidenhout 972ee32351
feat(frontend): do not embed frontend assets anymore (#63946)
* Frontend no longer embeds the assets intead it reads from the local
filesystem assets.
* Generally the frontend and server cmd targets will use the
`//client/web/dist:copy_bundle` target to create a tarball for the
oci_image. `copy_bundle` puts all the assets at `assets-dist`
* For integration tests, frontend and server have the `no_client_bundle`
target variants. For these oci_images, instead of the `tar_bundle` which
is just a tar'd `copy_bundle` we use the `tar_dummy_manifest` which is
just a tar that contains a dummy manifest.
* By default we expect assets to be at `/assets-dist`
* Renamed DevProvider to DirProvider

## Why
By 'breaking' the dependency of frontend requiring assets to be built we
essentially stop a common cache invalidation scenario that happens:
- someone makes a frontend change = assets need to be rebuilt

By decoupling assets from the frontend binary and moving the packing of
assets to the building of the frontend and server images we will have a
better cache hit rate (theoretically).

Thus with this change, when:
* client/web is change and nothing else ... only assets will have to
rebuilt and cached versions of the backend will be used
* if only backend code has changed ... cached assets will be used

Closes DINF-115

## Test plan
  sg start - web app opens and can search. Local dev assets get loaded
 sg test bazel-integration-test - server image gets built with **only**
dummy web manifest. Also verified by running `sg bazel run
//cmd/server:no_client_bundle.image` and then inspect container
 sg test bazel-e2e - server image gets built with bundle and all tests
pass
 [main dry
run](https://buildkite.com/sourcegraph/sourcegraph/builds/284042#0190e54c-14d9-419e-95ca-1198dc682048)

## Changelog
- frontend: assets are no longer bundled with binary through `go:embed`.
Instead assets are now added to the frontend container at `assets-dist`.
2024-07-31 15:17:52 +02:00

59 lines
1.6 KiB
Python

"""
Various helpers to help with server image building
"""
load("@rules_pkg//:pkg.bzl", "pkg_tar")
def get_last_segment(path):
"""
returns part of a bazel path - it will return binary in //something:binary
Args:
path: the path from which the last segment should be extract from
Returns:
Returns the last part found after `:`. If no `:` is found then the last part after the last '/' is returned
"""
segments = path.split("/")
last_segment = segments[-1]
s = last_segment.split(":")
if len(s) == 1:
return last_segment
else:
return s[-1]
def container_dependencies(targets):
"""
creates pkg_tar rules for all given targets
for all the given targets this will create a pkg_tar rule named 'tar_<name>` where
the target is added as well as the path of the target output is remapped to be at /usr/local/bin
Args:
targets: list of targets for which pkg_tar rules should be generated for
"""
for target in targets:
name = get_last_segment(target)
pkg_tar(
name = "tar_{}".format(name),
srcs = [target],
remap_paths = {"/{}".format(name): "/usr/local/bin/{}".format(name)},
)
def dependencies_tars(targets):
"""
for all the given targets it returns a list of the corresponding `:tar_<name>` targets
Args:
targets: list of targets
Returns:
list of ':tar_<name>' targets
"""
tars = []
for target in targets:
name = get_last_segment(target)
tars.append(":tar_{}".format(name))
return tars