feat: native deploy workflow without SSH
This commit is contained in:
@@ -8,21 +8,69 @@ on:
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Deploy via SSH
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
host: ${{ secrets.DEPLOY_HOST }}
|
||||
username: ${{ secrets.DEPLOY_USERNAME }}
|
||||
key: ${{ secrets.DEPLOY_KEY }}
|
||||
port: ${{ secrets.DEPLOY_PORT || 22 }}
|
||||
script: |
|
||||
cd /opt/configucci
|
||||
git pull origin main
|
||||
docker-compose pull
|
||||
docker-compose up -d
|
||||
docker system prune -f
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build application
|
||||
run: npm run build
|
||||
|
||||
- name: Build Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: false
|
||||
load: true
|
||||
tags: configucci:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Create docker-compose.yml
|
||||
run: |
|
||||
cat > docker-compose.yml << 'EOF'
|
||||
version: '3.8'
|
||||
services:
|
||||
configucci:
|
||||
image: configucci:latest
|
||||
container_name: configucci
|
||||
ports:
|
||||
- "11088:80"
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:80"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
EOF
|
||||
|
||||
- name: Stop existing containers
|
||||
run: docker-compose down || true
|
||||
|
||||
- name: Start new container
|
||||
run: docker-compose up -d
|
||||
|
||||
- name: Wait for application health
|
||||
run: |
|
||||
echo "Waiting for application to be healthy..."
|
||||
for i in {1..30}; do
|
||||
if curl -s http://localhost:11088 > /dev/null 2>&1; then
|
||||
echo "Application is ready!"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "Application failed to start"
|
||||
exit 1
|
||||
|
||||
- name: Cleanup old images
|
||||
run: docker system prune -f
|
||||
|
||||
Reference in New Issue
Block a user