Pipeline stuff
This commit is contained in:
122
.woodpecker.yml
122
.woodpecker.yml
@@ -60,111 +60,41 @@ steps:
|
||||
- build
|
||||
|
||||
# ============================================
|
||||
# Stage 3: Deploy to Linode VPS
|
||||
# Stage 3: Trigger Portainer stack redeploy (webhook)
|
||||
# ============================================
|
||||
- name: deploy
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host:
|
||||
from_secret: deploy_host
|
||||
username:
|
||||
from_secret: deploy_username
|
||||
key:
|
||||
from_secret: deploy_ssh_key
|
||||
port:
|
||||
from_secret: deploy_port
|
||||
command_timeout: 5m
|
||||
envs:
|
||||
- REGISTRY_URL
|
||||
- REGISTRY_REPO
|
||||
- REGISTRY_USERNAME
|
||||
- REGISTRY_PASSWORD
|
||||
- CONTAINER_NAME
|
||||
- APP_PORT
|
||||
script:
|
||||
- set -e
|
||||
- set -o pipefail
|
||||
- echo "=== Deploying to Linode VPS ==="
|
||||
- echo "Container: $CONTAINER_NAME"
|
||||
- echo "Port: $APP_PORT"
|
||||
- |
|
||||
# Login to registry
|
||||
echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_URL" \
|
||||
-u "$REGISTRY_USERNAME" \
|
||||
--password-stdin
|
||||
- |
|
||||
# Pull latest image
|
||||
echo "Pulling image: $REGISTRY_REPO:latest"
|
||||
docker pull $REGISTRY_REPO:latest
|
||||
- |
|
||||
# Stop and remove existing container
|
||||
echo "Stopping existing container..."
|
||||
docker stop $CONTAINER_NAME 2>/dev/null || echo "Container not running"
|
||||
docker rm $CONTAINER_NAME 2>/dev/null || echo "Container not found"
|
||||
- |
|
||||
# Start new container
|
||||
echo "Starting new container..."
|
||||
docker run -d \
|
||||
--name $CONTAINER_NAME \
|
||||
--restart unless-stopped \
|
||||
-p $APP_PORT:80 \
|
||||
--label "deployment.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
||||
--label "deployment.commit=${CI_COMMIT_SHA}" \
|
||||
$REGISTRY_REPO:latest
|
||||
- |
|
||||
# Wait for container to be healthy
|
||||
echo "Waiting for container health check..."
|
||||
sleep 5
|
||||
if ! docker ps | grep -q $CONTAINER_NAME; then
|
||||
echo "❌ Container failed to start!"
|
||||
docker logs $CONTAINER_NAME
|
||||
exit 1
|
||||
fi
|
||||
- |
|
||||
# Verify container is responding
|
||||
echo "Verifying container health..."
|
||||
if ! docker exec $CONTAINER_NAME wget -q --spider http://localhost/; then
|
||||
echo "❌ Container health check failed!"
|
||||
docker logs $CONTAINER_NAME
|
||||
exit 1
|
||||
fi
|
||||
- |
|
||||
# Cleanup old images
|
||||
echo "Cleaning up old images..."
|
||||
docker image prune -af --filter "until=72h" || true
|
||||
- echo "✓ Deployment complete!"
|
||||
image: curlimages/curl:latest
|
||||
environment:
|
||||
REGISTRY_URL: ${REGISTRY_URL}
|
||||
REGISTRY_REPO: ${REGISTRY_REPO}
|
||||
REGISTRY_USERNAME: ${REGISTRY_USERNAME}
|
||||
REGISTRY_PASSWORD:
|
||||
from_secret: registry_password
|
||||
CONTAINER_NAME: ${CONTAINER_NAME}
|
||||
APP_PORT: ${APP_PORT}
|
||||
PORTAINER_WEBHOOK_URL:
|
||||
from_secret: portainer_webhook_url
|
||||
commands:
|
||||
- set -e
|
||||
- echo "=== Triggering Portainer stack redeploy ==="
|
||||
- |
|
||||
resp=$(curl -s -w "\n%{http_code}" -X POST "$PORTAINER_WEBHOOK_URL")
|
||||
body=$(echo "$resp" | head -n -1)
|
||||
code=$(echo "$resp" | tail -n 1)
|
||||
if [ "$code" != "200" ] && [ "$code" != "204" ]; then
|
||||
echo "Webhook failed (HTTP $code): $body"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Portainer redeploy triggered (HTTP $code)"
|
||||
depends_on:
|
||||
- push
|
||||
|
||||
# ============================================
|
||||
# Configuration Reference
|
||||
# ============================================
|
||||
#
|
||||
#
|
||||
# Required Secrets (set in Woodpecker UI):
|
||||
# - registry_password: Docker registry password/token
|
||||
# - deploy_host: Linode VPS hostname or IP
|
||||
# - deploy_username: SSH username (e.g., root, deploy)
|
||||
# - deploy_ssh_key: Private SSH key (multi-line)
|
||||
# - deploy_port: SSH port (default: 22)
|
||||
# - registry_password: Gitea container registry password/token
|
||||
# - portainer_webhook_url: Portainer stack webhook URL (Redeploy trigger)
|
||||
#
|
||||
# Required Environment Variables:
|
||||
# - REGISTRY_URL: Docker registry URL (e.g., registry.example.com)
|
||||
# - REGISTRY_REPO: Full image path (e.g., registry.example.com/mifi-ventures-landing)
|
||||
# - REGISTRY_USERNAME: Registry username
|
||||
# - CONTAINER_NAME: Docker container name (e.g., mifi-ventures-landing)
|
||||
# - APP_PORT: Host port to expose (e.g., 8080)
|
||||
# Required Environment Variables (Gitea registry):
|
||||
# - REGISTRY_URL: git.mifi.dev
|
||||
# - REGISTRY_REPO: git.mifi.dev/mifi-ventures/landing
|
||||
# - REGISTRY_USERNAME: your Gitea username
|
||||
#
|
||||
# Example .env for local testing:
|
||||
# REGISTRY_URL=registry.example.com
|
||||
# REGISTRY_REPO=registry.example.com/mifi-ventures-landing
|
||||
# REGISTRY_USERNAME=myuser
|
||||
# CONTAINER_NAME=mifi-ventures-landing
|
||||
# APP_PORT=8080
|
||||
# Portainer: Add stack from "Git repository" with this repo, compose path
|
||||
# docker-compose.yml. Enable GitOps → Webhook and "Re-pull image".
|
||||
# Add Gitea registry in Portainer (Settings → Registries) so the host can pull.
|
||||
|
||||
Reference in New Issue
Block a user