Skip to content

Commit

Permalink
Adjust docker
Browse files Browse the repository at this point in the history
  • Loading branch information
fbtom committed Oct 6, 2024
1 parent 228c2ef commit 70a598e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bin/
external_libraries/

# own libraries built by project
own_libraries/
libs/

# ctest temp files
Testing/Temporary/
25 changes: 3 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
FROM ubuntu:mantic as BUILD
FROM ubuntu:mantic AS build
ENV PROJECT_NAME=desktop-business-app

COPY database/ /application/database

WORKDIR /application
COPY . /application

RUN /application/dependencies.sh

RUN cmake -S . -B build && cmake --build build

RUN /application/bin/${PROJECT_NAME}-tests

FROM ubuntu:mantic as FINAL
ENV PROJECT_NAME=desktop-business-app

WORKDIR /application

COPY /dependencies.sh /application/
RUN /application/dependencies.sh

COPY --from=BUILD /application/database /application/database

COPY --from=BUILD /application/bin/${PROJECT_NAME} /application/bin/${PROJECT_NAME}
COPY --from=BUILD /application/bin/${PROJECT_NAME}-tests /application/bin/${PROJECT_NAME}-tests
RUN /application/dependencies.sh

ENTRYPOINT /application/bin/${PROJECT_NAME}
WORKDIR /application/build
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,10 @@ After building test targets, ctest running all the tests can be run in 2 ways:
./ctest_run.sh
```
I recommend using script. It is tailored to print main info and just failed tests




### docker container
We can mount a local directory (volume) to Docker container. This way any changes we make locally will immediately be reflected in the conatiner withoutt needint to rebuild the image every time.

1 change: 1 addition & 0 deletions dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ apt install -y nlohmann-json3-dev
apt install -y libgoogle-glog-dev
apt install -y protobuf-compiler
apt install -y libprotobuf-dev
apt install -y git
3 changes: 0 additions & 3 deletions modules/backend/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
add_library(protobuff ${PROTO_SRCS} ${PROTO_HDRS})
target_compile_options(protobuff PRIVATE -Werror -Wall -Wextra -pedantic)
target_link_libraries(protobuff PUBLIC ${PROTOBUF_LIBRARIES})
message(STATUS "PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES}")
target_include_directories(protobuff PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

set_target_properties(protobuff PROPERTIES
Expand All @@ -24,7 +23,5 @@ set_target_properties(protobuff PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${OWN_LIBRARIES_DIR}
)

message(STATUS "PROTOBUF_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIR}")
include_directories(${PROTOBUF_INCLUDE_DIR})
message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ add_executable(basic_construction-test basic_construction_test.cpp)

target_compile_options(basic_construction-test PRIVATE -Werror -Wall -Wextra -pedantic)

message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}")

set(PROTO_DIR ${PROJECT_SOURCE_DIR}/../../build/proto)
target_include_directories(basic_construction-test PRIVATE
${OWN_LIBS_INCLUDE_DIR}/common
Expand Down
7 changes: 7 additions & 0 deletions run_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Build the Docker image
docker build -t desktop-business-app .

# Run the container in the background (detached mode)
docker run -d --name my_running_container -v $(pwd):/application -w /application desktop-business-app tail -f /dev/null
31 changes: 2 additions & 29 deletions tests_and_backend_clean_build.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
#!/bin/bash

# Clean the build library
# This script is used to clean the build directory then build the backend and run tests
rm -rf build

# Exit script on first error
set -e

# Create the build directory and navigate into it
mkdir build && cd build

# Configure backend with CMake
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON ../modules/backend/

# Build the target and install backend libs and headers to own_libraries
cmake --build . --parallel --clean-first -- -j2

# go back to main app directory
# cd ..

# # Check if the build_tests directory does not exist
# if [ ! -d "build_tests" ]; then
# # If it does not exist, create it
# mkdir build_tests
# fi

# Change directory to build_tests
# cd build_tests

# # Cclean build_tests directory
# # Check if the current directory is build_tests before removing everything
# if [ $(basename "$PWD") == "build_tests" ]; then
# # Remove everything in the current directory
# rm -rf *
# fi

# # configure tests target with CMake
# cmake -DCMAKE_BUILD_TYPE=Debug ../modules/tests/

# # Build the tests target
# cmake --build . --parallel
ctest --output-on-failure

0 comments on commit 70a598e

Please sign in to comment.