ci/cd #12

Merged
lborv merged 4 commits from ci/cd into develop 2025-10-14 11:13:44 +00:00
5 changed files with 167 additions and 39 deletions

64
.env.testing.example Normal file
View File

@ -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!

View File

@ -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!"

View File

@ -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! 🎉"

View File

@ -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:

37
scripts/setup-docker.sh Normal file
View File

@ -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 Dockers 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"