ci: expose web frontend on port 80 #2
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: Deploy SyncDesk Web | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/syncdesk-web | |
| jobs: | |
| build-and-deploy: | |
| name: Build and deploy web | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Normalize image name | |
| run: | | |
| echo "IMAGE_NAME_LOWER=$(echo '${{ env.IMAGE_NAME }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_NAME_LOWER }}:latest | |
| ${{ env.IMAGE_NAME_LOWER }}:${{ github.sha }} | |
| build-args: | | |
| VITE_API_URL=${{ secrets.VITE_API_URL }} | |
| VITE_WS_URL=${{ secrets.VITE_WS_URL }} | |
| VITE_APP_NAME=${{ secrets.VITE_APP_NAME }} | |
| - name: Prepare SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.VM_SSH_KEY }}" > ~/.ssh/syncdesk_vm_key | |
| chmod 600 ~/.ssh/syncdesk_vm_key | |
| ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts | |
| - name: Deploy on VM | |
| run: | | |
| ssh -i ~/.ssh/syncdesk_vm_key ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }} << EOF | |
| set -e | |
| mkdir -p /opt/syncdesk/syncdesk-web | |
| cd /opt/syncdesk/syncdesk-web | |
| cat > docker-compose.prod.yml << 'COMPOSE' | |
| services: | |
| syncdesk-web: | |
| image: ${IMAGE_NAME_LOWER}:latest | |
| container_name: syncdesk_web | |
| restart: unless-stopped | |
| ports: | |
| - "80:80" | |
| environment: | |
| TZ: America/Sao_Paulo | |
| COMPOSE | |
| if [ -n "${{ secrets.GHCR_TOKEN }}" ]; then | |
| echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin | |
| fi | |
| docker compose -f docker-compose.prod.yml pull | |
| docker compose -f docker-compose.prod.yml up -d | |
| docker image prune -f | |
| EOF |