From 8fd83350d48b999fe73ec334ee5855a33af740ad Mon Sep 17 00:00:00 2001 From: mortinger91 Date: Mon, 20 Feb 2023 12:16:55 +0100 Subject: [PATCH] added Docker container to run tests --- .dockerignore | 1 + Dockerfile | 23 ++++++++++------------- README.md | 4 ++++ docker-compose.yml | 4 +--- 4 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..121db5b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +ProjectFolder/build diff --git a/Dockerfile b/Dockerfile index b6ab584..385a8f7 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Development / Testing image for C++ template cmake project +# Development / Testing image for C++ CMake template project # base image used as the starting point for this image FROM debian:latest @@ -9,20 +9,14 @@ FROM debian:latest RUN apt-get update \ && apt-get install -y \ apt-utils \ - wget \ - curl \ git \ - vim \ build-essential \ libtool autoconf pkg-config \ - ninja-build \ clang \ llvm \ libc++-dev libc++abi-dev \ cmake \ - # libboost1.74-dev \ libboost-all-dev \ - # compiler cash ccache \ && apt-get clean && rm -rf /var/lib/apt/lists/* @@ -40,14 +34,17 @@ ARG TEST_VAR_DOCKERFILE=test COPY ProjectFolder /ProjectFolder # Setting the working directory inside the project folder -WORKDIR /ProjectFolder/ +WORKDIR / # Running Cmake build script, all cmake files are generated -RUN scripts/cmake_build.sh +RUN ProjectFolder/scripts/cmake_build.sh # Building the project using the build files generated by Cmake -RUN scripts/make_debug.sh +RUN ProjectFolder/scripts/make_debug.sh -# The command that is run by default by the container when "docker run ..."/"docker start ..." is used -# CMD ["/bin/bash"] -CMD ["./build/debug/bin/cpp-cmake-template"] +WORKDIR /ProjectFolder/build/debug + +# The command that is run by default when the container starts +CMD ["ctest", "--output-on-failure"] +# Run this to launch the project binary instead +# CMD ["./ProjectFolder/build/debug/bin/cpp-cmake-template"] diff --git a/README.md b/README.md index a08bd93..9461244 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ Execute script: ```./ProjectFolder/scripts/run_tests.sh```
or execute task "run_tests" in VSCode. + +To run tests in a Docker container:
+```docker compose down --volumes --rmi all```
+```docker compose up```

Add a new file:

- Create the new file in the desired folder.
- Add file.cpp in the CMakeLists.txt file (the one in the same folder as the file).
diff --git a/docker-compose.yml b/docker-compose.yml index 16c3873..ac94c9a 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,6 @@ version: "3.7" services: dev-container: - volumes: - - template-volume:/template-folder build: context: . @@ -12,7 +10,7 @@ services: tty: true environment: - - TEST_VAR_COMPOSE=asd + - TEST_VAR_COMPOSE=test ports: - 8080:5555