102 lines
3.5 KiB
YAML
102 lines
3.5 KiB
YAML
# Woodpecker CI/CD Pipeline for mifi Ventures Landing Site
|
|
# Deploys static site to Linode VPS via Docker
|
|
# Documentation: https://woodpecker-ci.org/docs
|
|
|
|
# Trigger: Push to main branch or tag creation
|
|
when:
|
|
branch: main
|
|
event: [push, tag]
|
|
|
|
steps:
|
|
# ============================================
|
|
# Stage 1: Build Docker Image
|
|
# ============================================
|
|
- name: build
|
|
image: docker:latest
|
|
environment:
|
|
REGISTRY_REPO: git.mifi.dev/mifi-ventures/landing
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
commands:
|
|
- set -e # Exit on error
|
|
- echo "=== Building Docker image ==="
|
|
- 'echo "Commit SHA: ${CI_COMMIT_SHA:0:8}"'
|
|
- 'echo "Registry repo: $REGISTRY_REPO"'
|
|
- |
|
|
docker build \
|
|
--tag $REGISTRY_REPO:${CI_COMMIT_SHA} \
|
|
--tag $REGISTRY_REPO:latest \
|
|
--label "git.commit=${CI_COMMIT_SHA}" \
|
|
--label "git.branch=${CI_COMMIT_BRANCH}" \
|
|
.
|
|
- echo "✓ Docker image built successfully"
|
|
|
|
# ============================================
|
|
# Stage 2: Push to Registry
|
|
# ============================================
|
|
- name: push
|
|
image: docker:latest
|
|
environment:
|
|
REGISTRY_URL: git.mifi.dev
|
|
REGISTRY_REPO: git.mifi.dev/mifi-ventures/landing
|
|
REGISTRY_USERNAME:
|
|
from_secret: registry_username
|
|
REGISTRY_PASSWORD:
|
|
from_secret: registry_password
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
commands:
|
|
- set -e # Exit on error
|
|
- echo "=== Pushing to registry ==="
|
|
- 'echo "Registry: $REGISTRY_URL"'
|
|
- 'echo "Repository: $REGISTRY_REPO"'
|
|
- |
|
|
echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_URL" \
|
|
-u "$REGISTRY_USERNAME" \
|
|
--password-stdin
|
|
- docker push $REGISTRY_REPO:${CI_COMMIT_SHA}
|
|
- docker push $REGISTRY_REPO:latest
|
|
- echo "✓ Images pushed successfully"
|
|
depends_on:
|
|
- build
|
|
|
|
# ============================================
|
|
# Stage 3: Trigger Portainer stack redeploy (webhook)
|
|
# ============================================
|
|
- name: deploy
|
|
image: curlimages/curl:latest
|
|
environment:
|
|
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
|
|
# ============================================
|
|
#
|
|
# Woodpecker has no separate "Variables" UI — use Secrets for everything.
|
|
#
|
|
# Required Secrets (Repo → Settings → Secrets):
|
|
# - registry_username: Your Gitea username (used for docker login)
|
|
# - registry_password: Gitea container registry password or token
|
|
# - portainer_webhook_url: Portainer stack webhook URL (Redeploy trigger)
|
|
#
|
|
# REGISTRY_URL and REGISTRY_REPO are set in this file (above).
|
|
#
|
|
# 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.
|