diff --git a/skills/create-cpp-api/SKILL.md b/skills/create-cpp-api/SKILL.md new file mode 100644 index 00000000..04f8e0cc --- /dev/null +++ b/skills/create-cpp-api/SKILL.md @@ -0,0 +1,36 @@ +--- +name: create-cpp-api +description: Creates a new C++ API project by copying the cpp/app template files and installs custom AI rules. +inputs: + - id: workspace_name + name: Workspace Name + type: string + description: The name of the folder for the new project +--- + +## When to Use This Skill + +Use this skill when the user wants to create a minimal C++ HTTP API project from the C++ API template (`cpp/app`) and run it locally using Docker. + +## Instructions + +1. **Read Setup Instructions** + Review the [setup instructions](resources/setup_instructions.md) to understand how to initialize the project. + + *Action:* Read `resources/setup_instructions.md`. + +2. **Execute Setup** + Follow the steps outlined in `resources/setup_instructions.md` to: + - Ensure Docker is installed. + - Create the workspace folder (using the `workspace_name` input). + - Copy template files from `cpp/app` into the new workspace. + - Create the `.agents/rules/cpp-api.md` file using the content from `resources/ai_rules.md`. + - Ensure the `.agents/rules/` directory exists. + +3. **Final Verification** + Check that: + - `cloud_run_hello.cc` exists in the new project + - `CMakeLists.txt` exists in the new project + - `Dockerfile` exists in the new project + - `docker-compose.yml` exists in the new project + - `.agents/rules/cpp-api.md` exists diff --git a/skills/create-cpp-api/resources/ai_rules.md b/skills/create-cpp-api/resources/ai_rules.md new file mode 100644 index 00000000..661e5be1 --- /dev/null +++ b/skills/create-cpp-api/resources/ai_rules.md @@ -0,0 +1,63 @@ +# Gemini AI Rules for C++ API Projects + +## 1. Persona & Expertise + +You are an expert backend developer specializing in C++ and containerized services. You understand: +- Modern C++ (C++17) +- Build systems, particularly CMake (`CMakeLists.txt`) +- Containerization using Docker (`Dockerfile`, `docker-compose.yml`) +- C++ dependency management (specifically with `vcpkg`) +- HTTP APIs and web server fundamentals +- Secure handling of environment variables + +## 2. Project Context + +This project is a minimal C++ backend API service based on the [Google Cloud Run C++ Quickstart](https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-c-plus-plus-service). + +It is intended to be used as a Firebase Studio (formerly Project IDX) template and also runnable locally as long as the user has Docker installed. + +Default assumptions: +- Single C++ entrypoint: `cloud_run_hello.cc` +- Build is defined by `CMakeLists.txt` and triggered within the `Dockerfile`. +- Dependencies are declared in `vcpkg.json`. +- The service is containerized via `Dockerfile` and orchestrated with `docker-compose.yml`. +- The container listens on port 8080, which is mapped to port 3000 on the host. + +## 3. Development Environment + +This project is configured to run in a containerized environment managed by Docker. + +When providing instructions: +- The primary prerequisite for the user is a working Docker installation (with Docker Compose). +- The Firebase Studio environment may already provide Docker. +- Running the app is done via: + - `docker-compose up --build` +- The service is typically available at: + - `http://localhost:3000` + +## 4. Coding Standards & Best Practices + +### General C++ +- Prefer modern, idiomatic C++. +- Use clear naming conventions for variables and functions. + +### Build & Dependencies +- Avoid introducing new system-level dependencies. Prefer managing C++ libraries via `vcpkg.json`. +- If adding a dependency with `vcpkg`, explain why and instruct the user to add it to `vcpkg.json`. The `Dockerfile` will handle the installation. +- Keep the `CMakeLists.txt` file clean and focused on building the application. + +### Containerization +- Follow Docker best practices, such as using multi-stage builds to keep the final image small. +- All environment setup should be handled within the `Dockerfile`. + +### Secrets & Environment Variables +- Never hardcode secrets (tokens, keys, credentials) in the source code. +- Use environment variables for configuration. These can be passed into the container via the `docker-compose.yml` file if needed. +- Avoid logging secrets. + +## 5. Interaction Guidelines + +- Provide clear, actionable steps. +- When generating code, provide complete file contents for C++, CMake, or Docker files. +- If the request is ambiguous, ask for clarification. +- Keep instructions compatible with both Firebase Studio and local setups where Docker is the common denominator. diff --git a/skills/create-cpp-api/resources/setup_instructions.md b/skills/create-cpp-api/resources/setup_instructions.md new file mode 100644 index 00000000..09d9e864 --- /dev/null +++ b/skills/create-cpp-api/resources/setup_instructions.md @@ -0,0 +1,89 @@ +# C++ API Workspace Setup Instructions + +Follow these steps to initialize the workspace. + +## 1. Install prerequisites (Docker) + +This skill requires: +- Docker +- Docker Compose + +### 1.1 Verify +Run: +- `docker --version` +- `docker-compose --version` + +If both commands work, go to **Step 2**. + +### 1.2 Install Docker +Docker is required to build and run this C++ application. The installation process is OS-specific. + +Please follow the official instructions for your operating system: +- **Windows:** [https://docs.docker.com/desktop/install/windows-install/](https://docs.docker.com/desktop/install/windows-install/) +- **macOS:** [https://docs.docker.com/desktop/install/mac-install/](https://docs.docker.com/desktop/install/mac-install/) +- **Linux:** [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/) + +After installation, restart your terminal and verify again. + +--- + +## 2. Create the project (copy template files) + +Set workspace name: +- `WS_NAME=""` + +From the repo root (or any directory), create the folder: + +```bash +mkdir -p "$WS_NAME" +``` + +Copy the C++ API template files into the workspace: + +```bash +# Copy from this repo’s cpp/app template into the new workspace +cp -R "/../../cpp/app/." "$WS_NAME/" +``` + +Then enter the workspace: + +```bash +cd "$WS_NAME" +``` + +## 3. Configure Agents Rules + +Create a file named `.agents/rules/cpp-api.md` inside the new workspace directory. + +Copy the content from: `resources/ai_rules.md` + +Commands: + +```bash +mkdir -p .agents/rules +# then create .agents/rules/cpp-api.md and paste contents from resources/ai_rules.md +``` + +## 4. Run server + +From within the workspace directory, run: + +```bash +docker-compose up --build +``` + +This will build the Docker image and start the service. The server runs on: + +`http://localhost:3000` + +Verify: + +```bash +curl http://localhost:3000/ +``` + +Expected response: + +``` +Hello, World! +``` diff --git a/skills/create-cpp-api/scripts/install_cpp_dependencies.ps1 b/skills/create-cpp-api/scripts/install_cpp_dependencies.ps1 new file mode 100644 index 00000000..adf01f52 --- /dev/null +++ b/skills/create-cpp-api/scripts/install_cpp_dependencies.ps1 @@ -0,0 +1,51 @@ +# This script verifies that Docker and Docker Compose are installed, +# as they are required to build and run this project. +# It does NOT install them automatically, as Docker installation is complex +# and requires user intervention. + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest + +Write-Host "Checking for Docker..." + +$docker_exists = Get-Command docker -ErrorAction SilentlyContinue +if (-not $docker_exists) { + Write-Error "Error: 'docker' command not found." + Write-Host "Docker is required to build and run this C++ project." + Write-Host "Please install Docker Desktop for Windows by following the official instructions:" + Write-Host "https://docs.docker.com/desktop/install/windows-install/" + Write-Host "After installation, please restart your terminal or PowerShell session and try again." + exit 1 +} + +$docker_version = (docker --version).Trim() +Write-Host "Docker found: $docker_version" + +Write-Host "Checking for Docker Compose..." + +$compose_v1_exists = Get-Command docker-compose -ErrorAction SilentlyContinue +$compose_v2_works = $false +try { + docker compose version | Out-Null + $compose_v2_works = $true +} catch { + # docker compose is not a valid command, so v2 is not present +} + +if ($compose_v1_exists) { + $compose_version = (docker-compose --version).Trim() + Write-Host "Docker Compose (v1) found: $compose_version" +} elseif ($compose_v2_works) { + $compose_version = (docker compose version).Trim() + Write-Host "Docker Compose (v2) found: $compose_version" +} else { + Write-Error "Error: 'docker-compose' or 'docker compose' command not found." + Write-Host "Docker Compose is required to run the application." + Write-Host "It is included with Docker Desktop. If it's missing, please ensure your Docker Desktop installation is up to date." + Write-Host "See: https://docs.docker.com/compose/install/" + Write-Host "After installation, please restart your terminal or PowerShell session and try again." + exit 1 +} + +Write-Host "All required dependencies (Docker, Docker Compose) are present." +exit 0 diff --git a/skills/create-cpp-api/scripts/install_cpp_dependencies.sh b/skills/create-cpp-api/scripts/install_cpp_dependencies.sh new file mode 100644 index 00000000..44b72c9c --- /dev/null +++ b/skills/create-cpp-api/scripts/install_cpp_dependencies.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + +# This script verifies that Docker and Docker Compose are installed, +# as they are required to build and run this project. +# It does NOT install them automatically, as Docker installation is +# platform-specific and requires user intervention. + +echo "Checking for Docker..." + +if ! command -v docker &> /dev/null; then + echo "Error: 'docker' command not found." + echo "Docker is required to build and run this C++ project." + echo "Please install Docker for your system by following the official instructions:" + echo "- macOS: https://docs.docker.com/desktop/install/mac-install/" + echo "- Linux: https://docs.docker.com/engine/install/" + echo "After installation, please restart your terminal and try again." + exit 1 +fi + +echo "Docker found: $(docker --version)" + +echo "Checking for Docker Compose..." + +# Check for both 'docker-compose' (v1) and 'docker compose' (v2) +if command -v docker-compose &> /dev/null; then + echo "Docker Compose (v1) found: $(docker-compose --version)" +elif docker compose version &> /dev/null; then + echo "Docker Compose (v2) found: $(docker compose version)" +else + echo "Error: 'docker-compose' or 'docker compose' command not found." + echo "Docker Compose is required to run the application." + echo "It is typically included with Docker Desktop. If you are on Linux, you may need to install it separately." + echo "See: https://docs.docker.com/compose/install/" + echo "After installation, please restart your terminal and try again." + exit 1 +fi + +echo "All required dependencies (Docker, Docker Compose) are present." +exit 0