forked from Yara724/api
143 lines
4.3 KiB
YAML
143 lines
4.3 KiB
YAML
# yara724/api — development deployment (Deploy-Develop)
|
|
# Manual tasks: see ci-cd/TASK.md
|
|
# Requires: repo marked Trusted in Woodpecker (host volume mounts)
|
|
|
|
when:
|
|
- event: push
|
|
branch: main
|
|
- event: manual
|
|
|
|
skip_clone: true
|
|
|
|
variables:
|
|
- &host_workspace /data/1-deploy/gitea/yara724/api
|
|
- &workspace_volume /data/1-deploy/gitea/yara724/api:/workspace
|
|
- &host_ssh /home/talieh/.ssh:/root/.ssh:ro
|
|
- &pipeline_env
|
|
WORKSPACE: *host_workspace
|
|
PROJECT_NAME: Yara724 API
|
|
ENVIRONMENT: Development
|
|
APPLICATION_URL: https://y724-user.ittalie.ir/api
|
|
GIT_COMMIT_URL: https://git.ittalie.com/Yara724/api/commit/
|
|
GIT_BRANCH: main
|
|
COMPOSE_FILE: docker-compose.yml
|
|
SUCCESS_COLOR: "#36a64f"
|
|
FAILURE_COLOR: "#dc3545"
|
|
|
|
steps:
|
|
pull:
|
|
image: docker.arvancloud.ir/alpine/git:latest
|
|
environment:
|
|
<<: *pipeline_env
|
|
GIT_SSH_COMMAND: ssh -o UserKnownHostsFile=/tmp/known_hosts -o StrictHostKeyChecking=yes
|
|
volumes:
|
|
- *workspace_volume
|
|
- *host_ssh
|
|
commands:
|
|
- git config --global --add safe.directory /workspace
|
|
- mkdir -p /tmp && ssh-keyscan -H git.ittalie.com >> /tmp/known_hosts
|
|
- cd /workspace
|
|
- git pull origin main
|
|
- date +%s > /workspace/.wp-deploy-start
|
|
|
|
deploy:
|
|
image: docker.arvancloud.ir/docker:24-cli
|
|
environment:
|
|
<<: *pipeline_env
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
- *workspace_volume
|
|
commands:
|
|
- cd /workspace
|
|
- docker compose -f docker-compose.yml up -d --build
|
|
|
|
notify-success:
|
|
image: docker.arvancloud.ir/alpine:3.20
|
|
environment:
|
|
<<: *pipeline_env
|
|
ROCKETCHAT_WEBHOOK:
|
|
from_secret: rocketchat_webhook
|
|
volumes:
|
|
- *workspace_volume
|
|
when:
|
|
- status: success
|
|
commands:
|
|
- apk add --no-cache curl jq git > /dev/null
|
|
- |
|
|
set -euo pipefail
|
|
git config --global --add safe.directory /workspace
|
|
cd /workspace
|
|
|
|
COMMIT_HASH="$(git rev-parse --short HEAD)"
|
|
DEPLOY_START="$(cat /workspace/.wp-deploy-start)"
|
|
DEPLOY_END="$(date +%s)"
|
|
DEPLOY_DURATION="$((DEPLOY_END - DEPLOY_START))"
|
|
|
|
COMMIT_1="$(git log -1 --pretty=format:'%s')"
|
|
COMMIT_2="$(git log -2 --pretty=format:'%s' | tail -n1)"
|
|
COMMIT_3="$(git log -3 --pretty=format:'%s' | tail -n1)"
|
|
|
|
TITLE="✅ ${PROJECT_NAME} - ${ENVIRONMENT} ✅"
|
|
TEXT="🌐 **URL**: ${APPLICATION_URL}
|
|
|
|
🔖 **Commit Hash**: [${COMMIT_HASH}](${GIT_COMMIT_URL}${COMMIT_HASH})
|
|
|
|
📝 **Recent Changes**:
|
|
|
|
• ${COMMIT_1}
|
|
|
|
• ${COMMIT_2}
|
|
|
|
• ${COMMIT_3}
|
|
|
|
⏱️ **Deployment Duration**: ${DEPLOY_DURATION}s"
|
|
|
|
payload="$(jq -n \
|
|
--arg title "$TITLE" \
|
|
--arg text "$TEXT" \
|
|
--arg color "$SUCCESS_COLOR" \
|
|
'{text: $title, attachments: [{text: $text, color: $color}]}')"
|
|
|
|
curl -fsS -H "Content-Type: application/json" -d "$payload" "$ROCKETCHAT_WEBHOOK" >/dev/null
|
|
rm -f /workspace/.wp-deploy-start
|
|
|
|
notify-failure:
|
|
image: docker.arvancloud.ir/alpine:3.20
|
|
environment:
|
|
<<: *pipeline_env
|
|
ROCKETCHAT_WEBHOOK:
|
|
from_secret: rocketchat_webhook
|
|
volumes:
|
|
- *workspace_volume
|
|
when:
|
|
- status: failure
|
|
commands:
|
|
- apk add --no-cache curl jq git > /dev/null
|
|
- |
|
|
set -euo pipefail
|
|
git config --global --add safe.directory /workspace
|
|
cd /workspace
|
|
|
|
COMMIT_HASH="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)"
|
|
TITLE="💥 ${PROJECT_NAME} - ${ENVIRONMENT} 💥"
|
|
TEXT="━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
🌐 **Application URL**
|
|
|
|
${APPLICATION_URL}
|
|
|
|
🔖 **Commit**
|
|
|
|
\`${COMMIT_HASH}\`
|
|
|
|
⚠️ **Pipeline failed** — check Woodpecker for the failing step.
|
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
payload="$(jq -n \
|
|
--arg title "$TITLE" \
|
|
--arg text "$TEXT" \
|
|
--arg color "$FAILURE_COLOR" \
|
|
'{text: $title, attachments: [{text: $text, color: $color}]}')"
|
|
|
|
curl -fsS -H "Content-Type: application/json" -d "$payload" "$ROCKETCHAT_WEBHOOK" >/dev/null || true
|
|
rm -f /workspace/.wp-deploy-start
|