Bazel provides various features to build and deply Go applications.
The WORKSPACE file provides the Bazel rules to be used and the BUILD.bazel file provides the different tasks to be executed
To run the Go application directly on your OS:
bazel run //:go-helloOnce the application is running, visit http://localhost:8080
To build and run the Go application within a container (making use of distroless):
bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //:image
docker run --rm -it -p8080:8080 bazel:imageOnce the container is running, visit http://localhost:8080
To push the container image to container registry:
bazel run //:push-imageTo be able to push containers to registry, you will need to do the approtiate container registry configuration, follow the instructions from here and indicate the appropiate repository name to configure authentication for Google Container Registry
You will need to indicate directory where the config.json is located in the WORKSPACE file
By using a bazel rules for kubernetes you are able to deploy your application to a local or kubernetes instance, by default bazel relies on your existing kubectl configuration/context (kubeconfig) for choosing where to deploy the application.
After kubectl configuration to deploy the application execute following:¨
bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 :deploy-pod.createYou will need to add the platforms parameter as every time we run this rule, we also rebuild the container image
To delete execute:
bazel run :deploy-pod.deleteI Have added another rule that will make the deployment of the pod, service and ingress, you can execute this by:
bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 :deploy-everything.createYou will need to add the platforms parameter as every time we run this rule, we also rebuild the container image
To delete execute:
bazel run :deploy-everything.delete