diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index aaf2351..5fbaf7b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,8 +5,6 @@ "build": { "dockerfile": "Dockerfile" }, - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. @@ -23,7 +21,15 @@ ] } }, + // This is necessary to ensure that Docker Compose containers are available inside the devcontainer + "runArgs": [ + "--network=host" + ], + // Features to add to the dev container. More info: https://containers.dev/features. "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {} + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { + "version": "20.10", + "dockerDashComposeVersion": "v2" + } } } \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b833987 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# This is necessary so that environment variables from .env +# are visible when Makefile commands are executed +include .env +export + +# Generate a new Alembic migration with autogenerate +create-migration: up-db + @cd ./src/data && \ + alembic revision --autogenerate -m $(name) + +# Apply all pending Alembic migrations +apply-migrations: up-db + @cd ./src/data && \ + alembic upgrade head + +# Build the project, apply migrations and start the application +run: apply-migrations + @conan build . --build=missig && \ + ./build/Debug/to-dos-api + +# Run clang-tidy static analysis +run-tidy: + @run-clang-tidy -p build/Debug diff --git a/README.md b/README.md index f29eaa1..71bc614 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,9 @@ When dependencies are built, use the command `conan build . -pr:h profiles/to-do To launch the executable, click Launch in the CMake extension.

cmakeLaunch

+Alternatively, you can use make targets. +- To run the application, use the `make run` command. When the command is executed, the project's dependencies will be checked and, if necessary, installed and compiled. + ## Linters The project includes the `clang-tidy` code analyzer and the `clang-format` formatter. Configuration files are located in the project root: `.clang-tidy` and `.clang-format`, respectively. @@ -56,7 +59,7 @@ To use linters you need to install: Clang-format code formatting occurs automatically when saving a file using the CodeAnalysis C/C++ extension. -To start manually, you need to run the command `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run`, while in the root of the project. +To start manually, you need to run the command `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format`, while in the root of the project. To automatically fix errors, run `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-format -i` from the project root. @@ -66,6 +69,9 @@ Clang-tidy code checking occurs in the background using the CodeAnalysis C/C++ e To start manually, you need to run the command `find ./src -name "*.cpp" -o -name "*.h" | xargs clang-tidy -p ./build/Debug | grep "error:"`, while in the root of the project. +Alternatively, you can use make targets. +- To run the code analyzer, use the `make run-tidy` command. + ## Tests run The project presents an example of test implementation using GTest tools. Test files are located in the `test` directory at the root of the project. Inside the `test` directory there is a `CMakeLists.txt` file created specifically for building a separate executable file for tests. @@ -93,4 +99,8 @@ The alembic tool is used to work with migrations. To work with it, you need to m - Create/change python model according declared cpp model. - Change terminal workspace to `src/data`. - Use the alembic command `alembic revision --autogenerate -m ''` for create new migration to database. -- If its needed upgrade local database with latest migration with commnd `alembic upgrade head`. \ No newline at end of file +- If its needed upgrade local database with latest migration with commnd `alembic upgrade head`. + +Alternatively, you can use make targets. +- To create a migration, run the command `make create-migration name=`, where `name` is the name of the migration. You can also use `make create-migration`, in which case the migration will be named after the current date and time. +- To apply the migrations, run the `make apply-migrations` command. \ No newline at end of file