From b639a01b13a5ca1e473b34c7f1c969168a385fea Mon Sep 17 00:00:00 2001 From: pixeldev Date: Fri, 13 Mar 2026 09:56:41 +0000 Subject: [PATCH] Update deploy workflow: use registry instead of Harbor --- .gitea/workflows/deploy.yml | 99 ++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 1ed7588..6f43cef 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -11,53 +11,62 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Sync files to project directory + - name: Detect project type + id: detect run: | - PROJECT="${{ github.event.repository.name }}" - DEPLOY_DIR="/opt/harbor-projects/${PROJECT}" - - mkdir -p "$DEPLOY_DIR" - rsync -av --delete \ - --exclude='.git' \ - --exclude='node_modules' \ - "$GITHUB_WORKSPACE/" "$DEPLOY_DIR/" - - echo "Synced to $DEPLOY_DIR" - - - name: Install dependencies (Node.js projects) - run: | - PROJECT="${{ github.event.repository.name }}" - DEPLOY_DIR="/opt/harbor-projects/${PROJECT}" - - if [ -f "$DEPLOY_DIR/package.json" ]; then - cd "$DEPLOY_DIR" - npm install --production - echo "npm install done" - fi - - - name: Register with Harbor (if new) - run: | - PROJECT="${{ github.event.repository.name }}" - DEPLOY_DIR="/opt/harbor-projects/${PROJECT}" - - # Check if already registered - STATUS=$(curl -sk -u admin:blaetternd-helix-dribbble124 \ - https://dev.bl.pixeldev.eu/harbor/api/projects/${PROJECT} \ - -o /dev/null -w "%{http_code}") - - if [ "$STATUS" = "404" ]; then - echo "Registering new project with Harbor..." - curl -sk -u admin:blaetternd-helix-dribbble124 \ - -X POST https://dev.bl.pixeldev.eu/harbor/api/projects \ - -H "Content-Type: application/json" \ - -d "{\"path\":\"${DEPLOY_DIR}\",\"name\":\"${PROJECT}\"}" + if [ -f package.json ]; then + echo "type=node" >> $GITHUB_OUTPUT else - echo "Refreshing existing Harbor project..." - curl -sk -u admin:blaetternd-helix-dribbble124 \ - -X POST https://dev.bl.pixeldev.eu/harbor/api/projects/${PROJECT}/deploy + echo "type=static" >> $GITHUB_OUTPUT fi - - name: Done + - name: Sync files run: | - PROJECT="${{ github.event.repository.name }}" - echo "✅ Deployed $PROJECT to https://dev.bl.pixeldev.eu/harbor/preview/${PROJECT}/" + SLUG="${{ github.event.repository.name }}" + mkdir -p /opt/deployed/${SLUG} + rsync -av --delete --exclude='.git' --exclude='node_modules' \ + $GITHUB_WORKSPACE/ /opt/deployed/${SLUG}/ + + - name: Install dependencies + if: steps.detect.outputs.type == 'node' + run: | + cd /opt/deployed/${{ github.event.repository.name }} + npm install --production + + - name: Start / restart Node service + if: steps.detect.outputs.type == 'node' + id: node + run: | + SLUG="${{ github.event.repository.name }}" + DIR="/opt/deployed/${SLUG}" + + # Find entry point + ENTRY="" + for f in server.js index.js src/server.js src/index.js; do + [ -f "$DIR/$f" ] && ENTRY="$DIR/$f" && break + done + [ -z "$ENTRY" ] && ENTRY=$(node -e "const p=require('$DIR/package.json'); console.log('$DIR/'+p.main)" 2>/dev/null) + + # Allocate port (base 4000 + hash of slug) + PORT=$((4000 + $(echo -n "$SLUG" | cksum | cut -d' ' -f1) % 1000)) + + # Start or restart + pm2 describe "deploy-${SLUG}" > /dev/null 2>&1 \ + && pm2 restart "deploy-${SLUG}" \ + || PORT=$PORT pm2 start "$ENTRY" --name "deploy-${SLUG}" + + echo "port=$PORT" >> $GITHUB_OUTPUT + + - name: Register with dev registry + run: | + SLUG="${{ github.event.repository.name }}" + NAME="${{ github.event.repository.name }}" + TYPE="${{ steps.detect.outputs.type }}" + PORT="${{ steps.node.outputs.port }}" + + curl -s -X POST https://dev.bl.pixeldev.eu/api/register \ + -H "Content-Type: application/json" \ + -u admin:blaetternd-helix-dribbble124 \ + -d "{\"name\":\"${NAME}\",\"slug\":\"${SLUG}\",\"type\":\"${TYPE}\",\"port\":\"${PORT}\"}" + + echo "✅ Live at https://dev.bl.pixeldev.eu/${SLUG}/"