fix repo cloning [2] #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Deploy | |
| on: | |
| push: | |
| branches: ["main"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Log in to GHCR | |
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| - name: Build and Push Image | |
| run: | | |
| OWNER_LC=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
| IMAGE=ghcr.io/$OWNER_LC/stmorg:latest | |
| docker build -t $IMAGE . | |
| docker push $IMAGE | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy to VPS | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| script: | | |
| # --- Configuration --- | |
| PROJECT_DIR="/home/weberqbot/apps/stmorg" | |
| REPO_URL="git@github.com:${{ github.repository }}.git" | |
| # --------------------- | |
| # Ensure apps directory exists | |
| mkdir -p /home/weberqbot/apps | |
| echo "🔐 Login to GHCR..." | |
| echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
| echo "📂 Deploying Application..." | |
| if [ -d "$PROJECT_DIR" ]; then | |
| echo " Pulling latest changes..." | |
| cd "$PROJECT_DIR" | |
| git pull origin main | |
| else | |
| echo " Cloning repository..." | |
| git clone "$REPO_URL" "$PROJECT_DIR" | |
| cd "$PROJECT_DIR" | |
| fi | |
| echo "📥 Pull latest image..." | |
| docker compose pull | |
| echo "🔄 Restart containers..." | |
| docker compose up -d --force-recreate --remove-orphans | |
| echo "🧹 Cleanup old images..." | |
| docker image prune -f | |
| echo "✅ Deployment Complete!" | |