Skip to content

Commit

Permalink
Add release logic for ghcr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Jun 14, 2023
1 parent 2e8d7e7 commit dbafb5a
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 28 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ build:freebsd --host_cxxopt='-std=c++14'
build --incompatible_enable_cc_toolchain_resolution
build --protocopt=--experimental_allow_proto3_optional
build --client_env=CC=clang

10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ jobs:
path: "~/.cache/bazel-repo"
key: bazel-repo

- name: bazel test
- name: bazel build
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: >-
bazel
--bazelrc=.github/workflows/ci.bazelrc
--bazelrc=.bazelrc
test
build
...
- name: bazel run
- name: bazel test
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: >-
bazel
--bazelrc=.github/workflows/ci.bazelrc
--bazelrc=.bazelrc
run
//example/routeguide:server
test
...
26 changes: 13 additions & 13 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
--bazelrc=.bazelrc
build
//cmd/grpcstar:all
//cmd/grpcstar/container:image
- name: Prepare release assets
env:
Expand Down Expand Up @@ -79,16 +80,15 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Push Docker image
env:
env:
XDG_CACHE_HOME: ~/.cache/bazel-repo
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: >-
echo "${RELEASE_VERSION}" > cmd/grpcstar/container/RELEASE_TAG &&
bazel
--bazelrc=.github/workflows/ci.bazelrc
--bazelrc=.bazelrc
run
//cmd/grpcstar/container:push
18 changes: 18 additions & 0 deletions cmd/grpcstar/container/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@io_bazel_rules_docker//container:push.bzl", "container_push")
load("@io_bazel_rules_docker//container:image.bzl", "container_image")

container_image(
name = "image",
base = "@go_image_base//image",
entrypoint = ["/grpcstar"],
files = ["//cmd/grpcstar"],
)

container_push(
name = "push",
format = "Docker",
image = ":image",
registry = "ghcr.io/stackb",
repository = "grpc-starlark/grpcstar",
tag_file = "RELEASE_TAG",
)
1 change: 1 addition & 0 deletions cmd/grpcstar/container/RELEASE_TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
latest
69 changes: 69 additions & 0 deletions rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,40 @@ build_stack_grpc_starlark_repositories()

> Not required if you already have a workspace using rules_go.
A note about c++ toolchains. If you are running more recent versions of rules_go and bazel and are seeing:

```
external/io_bazel_rules_go/BUILD.bazel:86:17: While resolving toolchains for target @io_bazel_rules_go//:cgo_context_data: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type.
```

This is discussed more in https://github.com/bazelbuild/rules_go/issues/3470.

As a workaround, you might be able provide a set of C++ toolchains using zig:

```py
# ----------------------------------------------------
# @hermetic_cc_toolchain (zig)
# ----------------------------------------------------

load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")

# Plain zig_toolchains() will pick reasonable defaults. See
# toolchain/defs.bzl:toolchains on how to change the Zig SDK version and
# download URL.
zig_toolchains()

register_toolchains(
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
"@zig_sdk//toolchain:windows_amd64",
"@zig_sdk//toolchain:windows_arm64",
)
```

> @hermetic_cc_toolchain is declared in `repositories.bzl`. Additional flags in `.bazelrc` will be needed.
## `grpcstar_binary`

The `grpcstar_binary` generates a standalone binary with the descriptor and
Expand Down Expand Up @@ -89,3 +123,38 @@ generated file //example/routeguide:server_main.go # generated file: inp
go_library rule //example/routeguide:server_lib # generates: archive for go_binary.embed
go_binary rule //example/routeguide:server # generates: the executable, for running!
```

## `grpcstar_image`

The `grpcstar_image` rule generates a container image. It has usage similar to `grpcstar_binary`, although it does not use that rule directly.

Example:

```py
load("@build_stack_grpc_starlark//rules:grpcstar_image.bzl", "grpcstar_image")

grpcstar_image(
name = "image",
descriptor = ":routeguide_proto",
main = "routeguide.main.star",
)
```

### Attributes

| name | type | required | desciption |
| ------------ | ----- | -------- | --------------------------------------------------------------------------- |
| `main` | label | yes | The starlark source file having a `main(ctx)` func |
| `descriptor` | label | yes | The proto_descriptor_set file |
| `executable` | label | no | The grpcstar binary, defaults to `@build_stack_grpc_starlark//cmd/grpcstar` |
| `base` | label | no | The base image to use, defaults to `@go_image_base//image` |

The container layers will be:

1. the base layer
2. the executable
3. the descriptor
4. entrypoint script

You are most likely to update only theqentrypoint script during development,
making container pushes and pulls fast.
9 changes: 0 additions & 9 deletions rules/grpcstar_image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,3 @@ def grpcstar_image(**kwargs):
],
**kwargs
)

# container_push(
# name = "push",
# format = "Docker",
# image = ":image",
# registry = "us.gcr.io/bzlio-260121",
# repository = "bezel/robinhood",
# tag = "latest",
# )

0 comments on commit dbafb5a

Please sign in to comment.