π Redeploy DevTools - Production #20
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: π Redeploy DevTools - Production | |
| on: | |
| workflow_run: | |
| workflows: ['π³ Build Docker Image'] | |
| types: [completed] | |
| branches: [master] | |
| jobs: | |
| deployment: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| name: π½ Redeploy DevTools | |
| runs-on: devtools.01edu.ai | |
| environment: production | |
| permissions: { packages: read, contents: read } | |
| steps: | |
| - name: π Login to GitHub Container Registry | |
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| - name: π³ Pull latest Docker image | |
| run: docker pull ghcr.io/${{ github.repository }}:latest | |
| - name: π Stop existing container | |
| run: | | |
| if docker ps -q -f name=devtools-app; then | |
| echo "Stopping existing devtools-app container..." | |
| docker stop devtools-app | |
| docker rm devtools-app | |
| else | |
| echo "No existing devtools-app container found" | |
| fi | |
| - name: π§Ή Clean up old images | |
| run: | | |
| docker image prune -f | |
| - name: π Create network and volume if not exist | |
| run: | | |
| if ! docker network ls | grep -q devtools-network; then | |
| docker network create devtools-network | |
| fi | |
| if ! docker volume ls | grep -q devtools-pictures; then | |
| docker volume create devtools-pictures | |
| fi | |
| - name: π Deploy new container | |
| run: | | |
| echo "Deploying commit: ${{ github.sha }}" | |
| docker run -d \ | |
| --name devtools-app \ | |
| --network devtools-network \ | |
| --env-file /root/devtools/.env.prod \ | |
| -e CI_COMMIT_SHA=${{ github.sha }} \ | |
| -p 8877:3021 \ | |
| -v /root/devtools/db:/app/db \ | |
| -v devtools-pictures:/app/.picture \ | |
| --restart unless-stopped \ | |
| ghcr.io/${{ github.repository }}:latest | |
| - name: β Verify deployment | |
| run: | | |
| echo "Waiting for container to be ready..." | |
| sleep 10 | |
| # Check container status | |
| if docker ps | grep -q devtools-app; then | |
| echo "β Container is running" | |
| docker logs --tail=20 devtools-app | |
| else | |
| echo "β Container failed to start" | |
| docker logs devtools-app | |
| exit 1 | |
| fi |