A simple web server built using the Drogon framework. This server provides two endpoints:
/: Returns a basic "Hello from Drogon!" message./api/cityinfo/{city}: Provides information about a city (e.g., New York, London, Tokyo).
- Built with Drogon, a high-performance C++17/20 web framework and ORM.
- Unit tests written with Google Test.
- Dockerized for easy deployment.
- Kubernetes deployment configuration for scalability.
- Git hooks and CI/CD integration via GitHub Actions.
Before running the project, ensure you have the following installed:
- CMake (
3.5+) - C++17 compiler
- Git
- Docker (optional but recommended)
- Kubernetes cluster (for deployment)
git clone <repository-url>
cd task6If not already set up:
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install drogonSet the environment variable:
export VCPKG_ROOT=/path/to/vcpkgmkdir build && cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake ..
make./hello-serverThe server will start and listen on port 8848.
To run unit tests:
make main_test
./main_testEnsure all tests pass before deploying or pushing changes to the repository.
docker build -t drogon-hello-server .docker run -p 8848:8848 drogon-hello-serverThis project includes a deployment.yaml file that defines a Kubernetes Deployment, Service, and HorizontalPodAutoscaler. To deploy it in a Kubernetes cluster:
- Apply the configuration:
kubectl apply -f deployment.yaml- Verify the deployment:
kubectl get deployments,pods,services- Access the service via LoadBalancer or expose it as needed.
task6/
βββ .clang-tidy # Clang-Tidy configuration for code quality checks
βββ .dockerignore # Files to ignore when building Docker image
βββ .git/ # Git repository files (commits, branches, etc.)
β βββ COMMIT_EDITMSG # Last commit message
β βββ FETCH_HEAD # Latest fetched commits
β βββ HEAD # Current branch pointer
β βββ config # Git configuration
β βββ logs/ # Commit history logs
βββ .github/ # GitHub Actions CI/CD workflows
β βββ workflows/
β βββ github-actions.yml # GitHub Actions workflow file
βββ .gitignore # Files to ignore in version control
βββ CMakeLists.txt # CMake build configuration
βββ Dockerfile # Docker image setup
βββ README.md # This file
βββ config.json # Server configuration (port, threads, etc.)
βββ deployment.yaml # Kubernetes deployment configuration
βββ main.cpp # Entry point of the application
βββ src/ # Source code directory
β βββ CityInfoController.cpp/h
β βββ HelloController.cpp/h
βββ test/ # Unit tests
β βββ test_cityinfo/
β β βββ getcity_test.cpp
β βββ test_hello/
β βββ hello_test.cpp
βββ uploads/ # Upload directories (not used in this example)
βββ vcpkg.json # vcpkg dependency configuration
| Endpoint | Method | Description |
|---|---|---|
GET / |
GET | Returns "Hello from Drogon!" |
GET /api/cityinfo/{city} |
GET | Returns info about the specified city |
The project includes a GitHub Actions workflow defined in .github/workflows/github-actions.yml. This workflow performs the following tasks:
- Build and Test: Compiles the project and runs unit tests on every push to the repository.
- Deploy to GitHub Container Registry (GHCR): If the build is successful, the Docker image is pushed to GHCR.
- Trigger: The workflow is triggered by any
pushevent to the repository. - Jobs:
- Explore-GitHub-Actions: Prints information about the current Git event, runner OS, and repository.
- Build-and-Test: Builds the project and runs unit tests.
- Deploy-To-Github-Registry: Builds the Docker image and pushes it to GHCR.
Here's a simplified view of the workflow file:
name: CI/CD for cpp-endpoint
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "π The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "π§ This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "π The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
Build-and-Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and run tests
run: |
mkdir build && cd build
cmake ..
make
./main_test
Deploy-To-Github-Registry:
runs-on: ubuntu-latest
needs: Build-and-Test
steps:
- uses: actions/checkout@v4
- name: Build and push the image
run: |
docker login --username <your login> --password ${{ secrets.GH }} ghcr.io
docker build . --tag ghcr.io/z0tedd/cpp-endpoint-example:latest
docker push ghcr.io/z0tedd/cpp-endpoint-example:latestThis project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a feature branch.
- Make your changes and write tests if applicable.
- Submit a pull request.
For questions or suggestions, feel free to reach out via email or open an issue in the GitHub repository.
mkdir build && cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake ..
ln -s ../build/compile_commands.json ..