Sign inSign up

yiiman/api-cli

By yiiman

•Updated 3 days ago

A secure web service that executes CLI commands based on authenticated HTTP requests.

Image
Integration & delivery
0

814

yiiman/api-cli repository overview

⁠CI/CD CLI Controller

A secure web service that executes CLI commands based on authenticated HTTP requests.

⁠Features

  • Secure API endpoint with API key authentication
  • Rate limiting to prevent abuse
  • Nginx reverse proxy configuration
  • Environment-based command execution
  • Logging system
  • Health check endpoint
  • Systemd service integration for automatic startup
  • Docker support for containerized deployment
  • GitHub Actions for automated Docker builds

⁠Setup

  1. Install Docker and Docker Compose on your Ubuntu system:

    sudo apt-get update
    sudo apt-get install docker.io docker-compose
    
  2. get docker-compose.yaml⁠ file

  3. download .env.example⁠ file and Configure your environment variables in .env file

  4. Build and start the containers:

    docker-compose up -d
    

    The service will be available on port 80 (Nginx) and 3000 (direct access).

⁠Option 2: Traditional Installation⁠
  1. Install dependencies:

    npm install
    
  2. Configure your environment variables in .env:

    • Set your secure API_KEY
    • Configure your CLI_COMMAND
    • Set your CLI_WORKING_DIR
  3. Configure Nginx:

    • Copy the nginx.conf to your Nginx configuration directory
    • Restart Nginx
  4. Install as a service (Ubuntu):

    sudo chmod +x install-service.sh
    sudo ./install-service.sh
    

    This will:

    • Install Node.js if not present
    • Create a dedicated service user
    • Set up the project in /opt/cicd-cli-controller
    • Create and enable a systemd service
    • Start the service automatically
  5. Manual start (if not using service):

    npm start
    

⁠Usage

To trigger the CLI command, send a POST request to /api/trigger with your API key:

curl -X POST http://localhost/api/trigger \
  -H "X-API-Key: your-api-key-here"

⁠Security Features

  • Helmet.js for security headers
  • API key authentication
  • Rate limiting
  • CORS protection
  • Nginx reverse proxy
  • Request logging
  • Dedicated service user
  • Systemd service isolation
  • Docker container isolation

⁠Health Check

Access the health check endpoint:

curl http://localhost/health

⁠Service Management

⁠Docker
# Start services
docker-compose up -d

# Stop services
docker-compose down

# View logs
docker-compose logs -f

# Rebuild and restart
docker-compose up -d --build
⁠Traditional Installation

Once installed as a service, you can manage it using systemctl:

sudo systemctl start cicd-cli-controller    # Start the service
sudo systemctl stop cicd-cli-controller     # Stop the service
sudo systemctl restart cicd-cli-controller  # Restart the service
sudo systemctl status cicd-cli-controller   # Check service status

⁠GitHub Actions

The project includes GitHub Actions workflow that automatically:

  • Builds the Docker image
  • Pushes to Docker Hub on successful builds
  • Tags images based on git tags and commits
  • Uses caching to speed up builds

To set up GitHub Actions:

  1. Add these secrets to your GitHub repository:

    • DOCKERHUB_USERNAME: Your Docker Hub username
    • DOCKERHUB_TOKEN: Your Docker Hub access token (not password)
  2. Push to the main branch or create a tag to trigger the workflow

Tag summary

Content type

Image

Digest

sha256:20693768a…

Size

76.4 MB

Last updated

3 days ago

docker pull yiiman/api-cli:sha-53e03877c9e1ee015126567d557dbcf245d0cd8e