Sample app use for the Devoxx France 2019 conference "À la découverte de Bazel".
This "dummy" app is composed of multiple parts:
- gateway: a spring boot java app in the
demopackage - fetcher: a scala app in the
fetcherpackage - domain: a java domain model in the
domainpackage - cache-server: a cache-server package use to build our remote cache server image
For managing external dependencies, I have both used (to show different tools):
- Install bazel by following the instructions from http://bazel.build
- Retrieve and clone this repository
Build and test with the version 0.24.1
Build and run the gateway binary:
bazel build :gateway
bazel run :gateway # env set to dev by defaultor in a one shot:
bazel run :gateway # build and run itBuild and run the fetcher binary:
bazel run :fetchercurl "http://localhost:3000/greet?name=Devoxx"should return
{
"data": "Hello Devoxx !",
"from": "http://localhost:3000"
}To perform our remote caching, we'll use an nginx server with the WebDAV module. We will run a container, and mount the container cache directory to an host volume. The container will expose the port number 8888.
Our nginx server will start with the following configuration:
events {
worker_connections 1024;
}
http {
sendfile on;
server {
location /cache/ {
root /cache;
dav_methods PUT;
create_full_put_path on;
client_max_body_size 1G;
allow all;
}
}
}
We could pass option directly with bazel CLI, or use a .bazelrc configuration file (this is what we are going to do).
Look at the .bazelrc file at the root repository, we've had this one:
build --remote_http_cache=http://0.0.0.0:8888/cache
Here, we're specifying which remote cache we should hit.
bazel build :cache-serverbazel run :cache-serverNow, to test it, you can do:
bazel clean # clean our local cachethen build some stuff:
bazel build :gateway
bazel build :fetcherWe should see a lot of PUT request on our remote cache backend.
When all is built, clean the local cache by doing a bazel clean (simulate the fact that some other people populate our remote cache service).
then redo:
bazel build :gateway
bazel build :fetcherWe should see something like:
INFO: Elapsed time: 2.365s, Critical Path: 1.85s
INFO: 44 processes: 44 remote cache hit. # <- all actions are fetched from the remote cache \o/
INFO: Build completed successfully, 48 total actions