I have a rest api. I want to have a docker-compose setup that:
- starts the api server
- "waits" until it's up and running
- runs some api tests against the endpoints
- stops everything once the test job finished.
Now,
- The first part I can do.
- As for waiting for the backend to be up and runnning, as I understand it,
depends_on
does not quite cut it. the rest api does have a/ping
endpoint tho in case we need it. - struggling to find a minimal example online that:
- uses volumes and does not explicitly copy tests files over.
- runs the tests through a command in the docker file (as opposed to in the DockerFile)
- again not sure if there is an idiomatic way of stopping everything after tests are done, but I did come across a somewhat related solution that suggests using
docker-compose up --abort-on-container-exit
. is that the best way of achieving this?
currently my docker-compose file looks like this:
docker-compose.yml
version: '3.8'
networks:
development:
driver: bridge
services:
app:
build:
context: ../
dockerfile: ../Dockerfile
command: sbt run
image: sbt
ports:
- "8080:8080"
volumes:
- "../:/root/build"
networks:
- development
tests:
build:
dockerfile: ./Dockerfile
command: npm run test
volumes:
- .:/usr/tests/
- /usr/tests/node_modules
networks:
- development
depends_on:
- app
and the node Dockerfile
looking this:
FROM node:16
ADD package*.json /usr/tests/
ADD test.js /usr/tests/
WORKDIR /usr/tests/
RUN npm install
Full repo is here: https://github.com/ShahOdin/dockerise-everything/pull/1