# This is executable Markdown that's tested on CI.
set -o errexit -o nounset -o xtrace
alias ~~~=":<<'~~~sh'";:<<'~~~sh'
This repo includes:
- 🧱 Latest version of Bazel and dependencies
- 📦 Curated bazelrc flags via [bazelrc-preset.bzl]
- 🧰 Developer environment setup with [bazel_env.bzl]
- ✅ Pre-commit hooks for automatic linting and formatting
- 📚 go.mod package integration
Before following these instructions, setup the developer environment by running
direnv allowand follow any prompts. This ensures that tools we call in the following steps will be on the PATH.
First, run scaffold which is on the PATH thanks to direnv. This creates a new command in the repo.
scaffold new https://github.com/alexeagle/cowsay-go-scaffold Project=cowsayNext, create or update the go.mod file, including the nmyk.io/cowsay dependency pinning. This uses the Bazel-managed go SDK.
go mod tidyNow we generate BUILD files:
bazel run gazelle || trueWe can see that the app builds now:
bazel build cowsay/cmd/helloLet's run the application, starting a server in the background.
bazel run cowsay/cmd/hello &
# Wait for the server
while ! nc -z localhost 8080; do
sleep 0.5
doneFinally we can hit that server to verify the application output matches expectation:
output=$(curl localhost:8080)
echo "${output}" | grep -q "Hello, world" || {
echo >&2 "Wanted output containing 'Hello, world' but got '${output}'"
exit 1
}TODO: Build an OCI container for the target platform with bazel build //cmd/hello:image.load