|
| 1 | +name: '🚀 Deploy Next.js Docker App (Single Job)' |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [disabled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build-and-deploy: |
| 9 | + runs-on: self-hosted |
| 10 | + name: '🐳 Build & Deploy' |
| 11 | + steps: |
| 12 | + - name: '🔍 Checkout Code' |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + # ======================== |
| 16 | + # 🔐 Secrets & Config Setup |
| 17 | + # ======================== |
| 18 | + - name: '🔒 Verify Secrets Exist' |
| 19 | + run: | |
| 20 | + if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then |
| 21 | + echo "❌ Critical error: GOOGLE_SERVICES_JSON_BASE64 secret missing!" |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + echo "✅ All secrets present" |
| 25 | +
|
| 26 | + - name: '📁 Create google-services.json' |
| 27 | + run: | |
| 28 | + echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > google-services.json |
| 29 | + echo "🔄 Validating JSON..." |
| 30 | + jq empty google-services.json # Requires jq installed |
| 31 | + env: |
| 32 | + GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} |
| 33 | + |
| 34 | + - name: '⚙️ Create .env File' |
| 35 | + run: | |
| 36 | + echo "${{ secrets.ENV_FILE_CONTENT }}" > .env |
| 37 | + echo "" >> .env # Ensure trailing newline |
| 38 | +
|
| 39 | + # ======================== |
| 40 | + # 🐳 Docker Operations |
| 41 | + # ======================== |
| 42 | + - name: '🛠 Build Docker Image' |
| 43 | + run: docker build -t codebuilder-frontend:latest . |
| 44 | + |
| 45 | + - name: '🗑 Cleanup Old Containers' |
| 46 | + run: | |
| 47 | + docker ps -aq --filter name=codebuilder-frontend | xargs -r docker rm -f |
| 48 | +
|
| 49 | + - name: '🚀 Launch New Container' |
| 50 | + run: | |
| 51 | + docker run -d \ |
| 52 | + --network host \ |
| 53 | + -p 3000:3000 \ |
| 54 | + --env-file .env \ |
| 55 | + --name codebuilder-frontend \ |
| 56 | + codebuilder-frontend:latest |
0 commit comments