diff --git a/.env.testing.example b/.env.testing.example new file mode 100644 index 0000000..8df2c2e --- /dev/null +++ b/.env.testing.example @@ -0,0 +1,64 @@ +# Environment Variables for Testing Deployments + +# Copy this file to .env in your deployment directory + +# ================================ +# APPLICATION SETTINGS +# ================================ +NODE_ENV=testing +APP_PORT=3123 # Will be dynamically set to 3000 + PR_NUMBER + +# ================================ +# DATABASE CONFIGURATION +# ================================ +DB_HOST=mariadb +DB_PORT=3306 +DB_DATABASE=low_code_engine_pr_123 # Will be dynamically set +DB_USERNAME=app_user +DB_PASSWORD=your_strong_password_here +DB_ROOT_PASSWORD=your_strong_root_password_here + +# ================================ +# REDIS CONFIGURATION +# ================================ +REDIS_HOST=redis +REDIS_PORT=6379 + +# ================================ +# API TOKENS (if needed) +# ================================ +# API_TOKEN_SECRET=your_api_token_secret +# ADMIN_TOKEN=your_admin_token + +# ================================ +# EXTERNAL SERVICES (if any) +# ================================ +# EXTERNAL_API_URL=https://api.example.com +# EXTERNAL_API_KEY=your_external_api_key + +# ================================ +# LOGGING & MONITORING +# ================================ +LOG_LEVEL=debug +# SENTRY_DSN=https://your-sentry-dsn@sentry.io/project-id + +# ================================ +# PERFORMANCE SETTINGS +# ================================ +# MAX_CONNECTIONS=100 +# TIMEOUT=30000 + +# ================================ +# FEATURE FLAGS (if any) +# ================================ +# ENABLE_FEATURE_X=true +# ENABLE_DEBUG_MODE=true + +# ================================ +# NOTES FOR DEPLOYMENT +# ================================ +# - This file is automatically generated by GitHub Actions +# - PR_NUMBER will be substituted with actual PR number +# - Ports will be calculated as BASE_PORT + PR_NUMBER +# - Database name will include PR number for isolation +# - Do not commit this file with real secrets! \ No newline at end of file diff --git a/.gitea/workflows/deploy-testing.yml b/.gitea/workflows/deploy-testing.yml new file mode 100644 index 0000000..d8fa6c3 --- /dev/null +++ b/.gitea/workflows/deploy-testing.yml @@ -0,0 +1,53 @@ +name: Deploy to Testing Server + +on: + push: + branches: + - develop + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + name: Deploy to Testing Environment + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Deploy via SSH + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT || 22 }} + script: | + # Navigate to project directory + cd ${{ secrets.PROJECT_PATH }} + + # Pull latest code + echo "πŸ”„ Pulling latest code from repository..." + git pull origin develop + + # Install dependencies + echo "πŸ“¦ Installing dependencies with yarn..." + yarn install --frozen-lockfile + + # Run database migrations + echo "πŸ—„οΈ Running database migrations..." + yarn migration:run + + # Build the project + echo "πŸ—οΈ Building the project..." + yarn build + + # Restart PM2 process + echo "πŸ”„ Restarting PM2 application..." + pm2 restart ${{ secrets.PM2_APP_NAME || 'low-code-engine' }} + + # Show PM2 status + echo "βœ… Deployment completed! PM2 status:" + pm2 status + + echo "πŸš€ Application deployed successfully!" diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml deleted file mode 100644 index a0008fe..0000000 --- a/.gitea/workflows/test.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Test Runner - -on: - push: - branches: - - main - - develop - -jobs: - hello-world: - runs-on: [ubuntu-latest] - steps: - - name: Test multiple commands - run: | - echo "Step 1 complete βœ…" - echo "Step 2 complete βœ…" - echo "All good!" - echo "Tests passed! πŸŽ‰" diff --git a/docker-compose.yml b/docker-compose.yml index ed74915..e5755dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,36 +34,28 @@ services: retries: 10 interval: 10s - # NestJS Application - app: - build: - context: . - dockerfile: Dockerfile - target: development - container_name: low-code-engine-app + # Redis Cache + redis: + image: redis:7-alpine + container_name: low-code-engine-redis restart: unless-stopped - environment: - NODE_ENV: ${NODE_ENV:-development} - DB_HOST: mariadb - DB_PORT: 3306 - DB_USERNAME: ${DB_USERNAME:-app_user} - DB_PASSWORD: ${DB_PASSWORD:-app_password} - DB_DATABASE: ${DB_DATABASE:-low_code_engine} ports: - - "${APP_PORT:-3000}:3000" + - "${REDIS_PORT:-6379}:6379" volumes: - - .:/usr/src/app - - /usr/src/app/node_modules + - redis_data:/data networks: - app-network - depends_on: - mariadb: - condition: service_healthy - command: yarn start:dev + healthcheck: + test: ["CMD", "redis-cli", "ping"] + timeout: 5s + retries: 10 + interval: 10s volumes: mariadb_data: driver: local + redis_data: + driver: local networks: app-network: diff --git a/scripts/setup-docker.sh b/scripts/setup-docker.sh new file mode 100644 index 0000000..60f7d3e --- /dev/null +++ b/scripts/setup-docker.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -e + +echo "πŸ“¦ Updating system packages..." +apt update -y +apt upgrade -y + +echo "πŸ”§ Installing dependencies..." +apt install -y apt-transport-https ca-certificates curl gnupg lsb-release + +echo "πŸ”‘ Adding Docker’s official GPG key..." +curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg + +echo "πŸ“‚ Adding Docker repository..." +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \ + https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \ + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + +echo "πŸ“¦ Installing Docker Engine and Compose..." +apt update -y +apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin + +echo "βš™οΈ Enabling and starting Docker service..." +systemctl enable docker +systemctl start docker + +echo "πŸ‘€ Adding current user to docker group..." +usermod -aG docker $USER + +echo "βœ… Docker and Docker Compose installation complete!" +echo "➑️ Log out and log back in (or run 'newgrp docker') to use Docker without sudo." +echo +echo "πŸ’‘ Docker version:" +docker --version || echo "Docker not yet available in current shell" +echo "πŸ’‘ Docker Compose version:" +docker compose version || echo "Docker Compose not yet available in current shell"