Skip to content

Commit dc3c477

Browse files
author
Roland Groza
committed
Add option to override the registry and image name when pushing to a registry.
1 parent 40693e1 commit dc3c477

File tree

3 files changed

+54
-86
lines changed

3 files changed

+54
-86
lines changed

BUILD.bazel

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@gazelle//:def.bzl", "gazelle")
22
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
3-
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
3+
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
44
load("@rules_pkg//:pkg.bzl", "pkg_tar")
55

66
gazelle(
@@ -139,9 +139,9 @@ oci_image(
139139
)
140140

141141
oci_load(
142-
name = "bazel-remote-image-tarball",
142+
name = "bazel-remote-image-amd64-tarball",
143143
image = ":bazel-remote-image",
144-
repo_tags = ["buchgr/bazel-remote-cache:tmp-amd64"],
144+
repo_tags = ["bazel-remote-cache:tmp-amd64"],
145145
)
146146

147147
pkg_tar(
@@ -174,30 +174,5 @@ oci_image(
174174
oci_load(
175175
name = "bazel-remote-image-arm64-tarball",
176176
image = ":bazel-remote-image-arm64",
177-
repo_tags = ["buchgr/bazel-remote-cache:tmp-arm64"],
178-
)
179-
180-
# The following container_push targets push to "tmp-amd64" and "tmp-arm64"
181-
# tags, so they can be combined into a multiarch tag on dockerhub. This
182-
# isn't currently possible with rules_docker, so instead we rely on some
183-
# external commands to be run after the tmp-* tags are pushed. See the
184-
# docker/push_to_dockerhub script.
185-
#
186-
# Background:
187-
# https://github.com/bazelbuild/rules_docker/issues/1599
188-
189-
oci_push(
190-
name = "push_to_dockerhub_amd64",
191-
image = ":bazel-remote-image",
192-
remote_tags = ["tmp-amd64"],
193-
repository = "buchgr/bazel-remote-cache",
194-
visibility = ["//visibility:public"],
195-
)
196-
197-
oci_push(
198-
name = "push_to_dockerhub_arm64",
199-
image = ":bazel-remote-image-arm64",
200-
remote_tags = ["tmp-arm64"],
201-
repository = "buchgr/bazel-remote-cache",
202-
visibility = ["//visibility:public"],
177+
repo_tags = ["bazel-remote-cache:tmp-arm64"],
203178
)

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ commodity hardware and AWS servers. Outgoing bandwidth can exceed 15 Gbit/s on t
2424
## HTTP/1.1 REST API
2525

2626
Cache entries are set and retrieved by key, and there are two types of keys that can be used:
27+
2728
1. Content addressed storage (CAS), where the key is the lowercase SHA256 hash of the entry.
2829
The REST API for these entries is: `/cas/<key>` or with an optional but ignored instance name:
2930
`/<instance>/cas/<key>`.
@@ -60,6 +61,7 @@ for GET requests and `Content-type: application/json` for PUT requests.
6061
**/status**
6162

6263
Returns the cache status/info.
64+
6365
```
6466
$ curl http://localhost:8080/status
6567
{
@@ -78,6 +80,7 @@ $ curl http://localhost:8080/status
7880

7981
The empty CAS blob is always available, even if the cache is empty. This can be used to test that
8082
a bazel-remote instance is running and accepting requests.
83+
8184
```
8285
$ curl --head --fail http://localhost:8080/cas/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
8386
HTTP/1.1 200 OK
@@ -487,7 +490,6 @@ max_size: 100
487490
# use unix:///path/to/socket.sock, where /path/to/socket.sock can be
488491
# either an absolute or relative path to a socket path.
489492
http_address: 0.0.0.0:8080
490-
491493
# The server listener address for gRPC (unix sockets are also supported
492494
# as described above):
493495
#grpc_address: 0.0.0.0:9092
@@ -633,7 +635,7 @@ http_address: 0.0.0.0:8080
633635
# auth_method: environment_credential
634636
#
635637
# auth_method: default
636-
638+
637639
# If set to a valid port number, then serve /debug/pprof/* URLs here:
638640
#profile_port: 7070
639641
# IP address to use, if profiling is enabled:
@@ -689,16 +691,16 @@ See [examples/docker-compose.yml](examples/docker-compose.yml) for an example co
689691

690692
### Kubernetes notes
691693

692-
* See [examples/kubernetes.yml](examples/kubernetes.yml) for an example
694+
- See [examples/kubernetes.yml](examples/kubernetes.yml) for an example
693695
configuration.
694696

695-
* Don't name your deployment `bazel-remote`!
696-
697+
- Don't name your deployment `bazel-remote`!
698+
697699
Kubernetes sets some environment variables based on this name, which conflict
698700
with the `BAZEL_REMOTE_*` environment variables that bazel-remote tries to
699701
parse.
700702

701-
* bazel-remote supports the `/grpc.health.v1.Health/Check` service, which you can
703+
- bazel-remote supports the `/grpc.health.v1.Health/Check` service, which you can
702704
configure like so:
703705
```
704706
alb.ingress.kubernetes.io/backend-protocol: HTTP
@@ -715,9 +717,9 @@ See [examples/docker-compose.yml](examples/docker-compose.yml) for an example co
715717
The command below will build a docker image from source and install it into your local docker registry.
716718

717719
```bash
718-
$ bazel run :bazel-remote-image-tarball
720+
$ bazel run :bazel-remote-image-amd64-tarball
719721
# Ensure /your/path/to/data exists and is writable (e.g. by UID 65532)
720-
$ docker run -v /your/path/to/data:/data buchgr/bazel-remote-cache:tmp-amd64 --max_size 5 --dir /data
722+
$ docker run -v /your/path/to/data:/data bazel-remote-cache:tmp-amd64 --max_size 5 --dir /data
721723
```
722724

723725
### ARM64 docker image
@@ -729,7 +731,7 @@ To build a docker image for ARM64:
729731
```bash
730732
$ bazel run :bazel-remote-image-arm64-tarball
731733
# Ensure /your/path/to/data exists and is writable (e.g. by UID 65532)
732-
$ docker run -v /your/path/to/data:/data buchgr/bazel-remote-cache:tmp-arm64 --max_size 5 --dir /data
734+
$ docker run -v /your/path/to/data:/data bazel-remote-cache:tmp-arm64 --max_size 5 --dir /data
733735
```
734736

735737
## Build a standalone Linux binary
@@ -852,6 +854,7 @@ To avoid leaking your password in log files, you can place this flag in a
852854

853855
To use mutual TLS with bazel, use a `grpcs` URL for the `--remote_cache`
854856
argument, and add the following flags:
857+
855858
```bash
856859
--tls_certificate=path/to/ca.cert
857860
--tls_client_certificate=path/to/client/cert.cert

docker/push_to_dockerhub

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,49 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
script_dir=$(dirname "${BASH_SOURCE[0]}")
5-
cd "${script_dir}/.."
6-
7-
tag=latest
8-
if [ $# = 1 ]
9-
then
10-
case "$1" in
11-
v*)
12-
if [ "$(git rev-list -1 $1)" = "$(git rev-list -1 HEAD)" ]
13-
then
14-
tag="$1"
15-
else
16-
echo "Error: can only push \"latest\" or tagged commits"
17-
exit 1
18-
fi
19-
;;
20-
*)
21-
echo "Error: can only push \"latest\" or tagged commits"
22-
exit 1
23-
;;
24-
esac
25-
fi
4+
# Defaults
5+
REGISTRY="${REGISTRY:-docker.io}"
6+
IMAGE_NAME="${IMAGE_NAME:-buchgr/bazel-remote-cache}"
7+
TAG="${TAG:-latest}"
268

27-
# push test-amd64 and test-arm64 images.
28-
if [ "$(uname -p)" = aarch64 ]
29-
then
30-
bazel run //:push_to_dockerhub_arm64
9+
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}"
3110

32-
# Check that the image works, at least well enough to print help, and with cgo support.
33-
docker pull docker.io/buchgr/bazel-remote-cache:tmp-arm64
34-
docker run docker.io/buchgr/bazel-remote-cache:tmp-arm64 -h
35-
docker run docker.io/buchgr/bazel-remote-cache:tmp-arm64 -h | grep zstd_implementation | grep '"cgo"'
11+
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
12+
cd "$script_dir/.."
3613

37-
exit 0
14+
# Detect arch.
15+
img_arch=amd64
16+
if [[ "$(uname -m)" == "arm64" || "$(uname -m)" == "aarch64" ]]; then
17+
img_arch=arm64
3818
fi
39-
bazel run //:push_to_dockerhub_amd64
4019

41-
# Check that the image works, at least well enough to print help, and with cgo support.
42-
docker pull docker.io/buchgr/bazel-remote-cache:tmp-amd64
43-
docker run docker.io/buchgr/bazel-remote-cache:tmp-amd64 -h
44-
docker run docker.io/buchgr/bazel-remote-cache:tmp-amd64 -h | grep zstd_implementation | grep '"cgo"'
20+
echo "Building and pushing $img_arch image..."
21+
22+
# Build and load.
23+
bazel run //:bazel-remote-image-${img_arch}-tarball
24+
25+
# Tag and push.
26+
docker tag bazel-remote-cache:tmp-${img_arch} "$FULL_IMAGE:tmp-${img_arch}"
27+
docker push "$FULL_IMAGE:tmp-${img_arch}"
4528

46-
# Create the multiarch manifest.
47-
docker manifest rm buchgr/bazel-remote-cache:$tag || true
48-
docker manifest create buchgr/bazel-remote-cache:$tag \
49-
--amend buchgr/bazel-remote-cache:tmp-amd64 \
50-
--amend buchgr/bazel-remote-cache:tmp-arm64
29+
# Collect existing arch images.
30+
manifest_args=()
31+
32+
for arch in amd64 arm64; do
33+
if docker manifest inspect "$FULL_IMAGE:tmp-${arch}" >/dev/null 2>&1; then
34+
manifest_args+=( "$FULL_IMAGE:tmp-${arch}" )
35+
fi
36+
done
37+
38+
if [[ ${#manifest_args[@]} -eq 0 ]]; then
39+
echo "ERROR: no images found to create manifest"
40+
exit 1
41+
fi
5142

52-
# Push the multiarch manifest
53-
docker manifest push buchgr/bazel-remote-cache:$tag
43+
# Recreate manifest atomically
44+
docker manifest rm "$FULL_IMAGE:$TAG" >/dev/null 2>&1 || true
5445

55-
# Mirror to quay.io (using https://github.com/regclient/regclient):
56-
regctl image copy docker.io/buchgr/bazel-remote-cache:$tag \
57-
quay.io/bazel-remote/bazel-remote:$tag
46+
docker manifest create "$FULL_IMAGE:$TAG" "${manifest_args[@]}"
47+
docker manifest push "$FULL_IMAGE:$TAG"
5848

59-
echo "Go ahead and delete the tmp-amd64 and tmp-arm64 images from the web ui"
49+
echo "Updated multi-arch manifest: $FULL_IMAGE:$TAG"

0 commit comments

Comments
 (0)