How to use bazel with docker-compose?

Viewed 856

I have 15 microservices and I want to run them using bazel and docker-compose in my local environtment.

To store bazel output in my host I mount /mtp/output:/tmp/build_ouput in my docker-compose and on other hand use the --output_user_root=/tmp/build_output bazel flag in my Dockerfile command, so we keep bazel output in our host.

something like this:

version: "3.8"
services:
  senna-identity:
    image: app/identity:latest
    build:
      context: .
      dockerfile: Dockerfile
    command: ["--output_user_root=/tmp/build_output","run","//services/identity"]
    volumes:
      - .:/app
      - /tmp/senna_build_output:/tmp/build_output

# Other services are just same as above service

and my Dockerfile:

FROM l.gcr.io/google/bazel:3.5.0

WORKDIR /app

EXPOSE 9000
CMD ["--output_user_root=/tmp/build_output","run","//services/identity"]

But I have two problems:

  1. All microservices using bazel to run their target but we know that bazel don't let two commands run simultaneously, so we get following error when run docker-compose up:
Another command holds the client lock: 
pid=1
owner=client
cwd=/app
Waiting for it to complete...

and a second later my other microservice fail because of this error:

Server terminated abruptly (error code: 14, error message: 'Socket closed',
  1. My second problem is the time which docker-compose get to mount /etc/output path, it get about 80 second just for two microservice, I think we can not use this solution for all microservices. Do I'm doing something wrong? should I use another way to develop my microservices locally with bazel or should I use some other tool instead of docker-compose... ?
0 Answers
Related