Update deploy-docker.yml #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: Deploy Next.js Docker App | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: self-hosted | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
# Debug: Verify secret exists | |
- name: Check secret presence | |
run: | | |
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then | |
echo "❌ Critical error: GOOGLE_SERVICES_JSON_BASE64 secret is empty!" | |
exit 1 | |
else | |
echo "✅ Secret exists (length: ${#GOOGLE_SERVICES_JSON_BASE64} chars)" | |
fi | |
env: | |
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} | |
# Decode with error handling | |
- name: Create google-services.json | |
run: | | |
set -e # Exit immediately on error | |
echo "Decoding base64 secret..." | |
echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > google-services.json | |
echo "Verifying file:" | |
ls -lh google-services.json | |
file google-services.json | |
head -n 2 google-services.json | |
if [ ! -s google-services.json ]; then | |
echo "❌ File is empty!" | |
exit 1 | |
fi | |
env: | |
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} | |
# Create the .env file from a secret | |
- name: Create .env file | |
run: | | |
echo -n "${{ secrets.ENV_FILE_CONTENT }}" > .env | |
# Debug: Check file size of google-services.json | |
- name: Check google-services.json file size | |
run: wc -c google-services.json | |
# Validate JSON syntax | |
- name: Validate google-services.json | |
run: node -e "JSON.parse(require('fs').readFileSync('google-services.json','utf8'))" | |
- name: Build Docker image | |
run: docker build -t codebuilder-webapp:latest . | |
- name: Stop and remove old container (if running) | |
run: | | |
OLD_CONTAINER_ID=$(docker ps -aq --filter name=codebuilder-webapp) | |
if [ -n "$OLD_CONTAINER_ID" ]; then | |
echo "Stopping and removing container $OLD_CONTAINER_ID..." | |
docker stop $OLD_CONTAINER_ID | |
docker rm $OLD_CONTAINER_ID | |
else | |
echo "No old container found." | |
fi | |
- name: Start new container | |
run: docker run -d --network host -p 3000:3000 --name codebuilder-webapp codebuilder-webapp:latest |