# MCP-OPENAPI-DOCX Deployment Workflow
# Deploy the application to production
name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'production'
type: choice
options:
- production
- staging
env:
PYTHON_VERSION: "3.11"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# Test before deployment
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libmagic1
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
env:
DATABASE_URL: sqlite+aiosqlite:///./test_db.sqlite
SECRET_KEY: test-secret-key
ENVIRONMENT: test
run: |
pytest tests/ -v --tb=short
# Build Docker image
build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Deploy to production
deploy:
name: Deploy to Production
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ github.event.inputs.environment || 'production' }}
url: ${{ vars.DEPLOYMENT_URL }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Option 1: Deploy using SSH to remote server
- name: Deploy to Server (SSH)
if: vars.DEPLOY_METHOD == 'ssh'
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd ${{ vars.DEPLOY_PATH }}
git pull origin main
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart mcp-openapi-docx
# Option 2: Deploy using Docker
- name: Deploy Docker Container
if: vars.DEPLOY_METHOD == 'docker' || vars.DEPLOY_METHOD == ''
run: |
echo "Deploying Docker image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
# Add your docker deployment commands here
# Example: ssh to server and run docker pull && docker-compose up -d
# Option 3: Deploy to Kubernetes
- name: Deploy to Kubernetes
if: vars.DEPLOY_METHOD == 'kubernetes'
run: |
echo "Deploying to Kubernetes..."
# kubectl apply -f kubernetes/
- name: Health Check
run: |
echo "Performing health check..."
# curl -f ${{ vars.DEPLOYMENT_URL }}/health || exit 1
- name: Deployment Summary
run: |
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Environment**: ${{ github.event.inputs.environment || 'production' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Image**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Deployed at**: $(date -u)" >> $GITHUB_STEP_SUMMARY
# Notify on deployment
notify:
name: Send Notifications
runs-on: ubuntu-latest
needs: deploy
if: always()
steps:
- name: Notify Success
if: needs.deploy.result == 'success'
run: |
echo "Deployment successful!"
# Add notification logic here (Slack, Discord, Email, etc.)
- name: Notify Failure
if: needs.deploy.result == 'failure'
run: |
echo "Deployment failed!"
# Add failure notification logic here