Skip to content

Commit 0f4b938

Browse files
Simpler workflow w/ comments & clean icon names.
1 parent b878fcb commit 0f4b938

File tree

1 file changed

+29
-54
lines changed

1 file changed

+29
-54
lines changed

.github/workflows/deploy-docker.yml

+29-54
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,56 @@
1-
name: Deploy Next.js Docker App
1+
name: '🚀 Deploy Next.js Docker App (Single Job)'
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76

87
jobs:
98
build-and-deploy:
109
runs-on: self-hosted
11-
10+
name: '🐳 Build & Deploy'
1211
steps:
13-
- name: Check out repository
12+
- name: '🔍 Checkout Code'
1413
uses: actions/checkout@v3
1514

16-
# Debug: Verify secret exists
17-
- name: Check secret presence
15+
# ========================
16+
# 🔐 Secrets & Config Setup
17+
# ========================
18+
- name: '🔒 Verify Secrets Exist'
1819
run: |
1920
if [ -z "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" ]; then
20-
echo "❌ Critical error: GOOGLE_SERVICES_JSON_BASE64 secret is empty!"
21+
echo "❌ Critical error: GOOGLE_SERVICES_JSON_BASE64 secret missing!"
2122
exit 1
22-
else
23-
echo "✅ Secret exists (length: ${#GOOGLE_SERVICES_JSON_BASE64} chars)"
2423
fi
25-
env:
26-
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
24+
echo "✅ All secrets present"
2725
28-
# Decode with error handling
29-
- name: Create google-services.json
26+
- name: '📁 Create google-services.json'
3027
run: |
31-
set -e # Exit immediately on error
32-
echo "Decoding base64 secret..."
3328
echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > google-services.json
34-
35-
echo "Verifying file:"
36-
ls -lh google-services.json
37-
file google-services.json
38-
head -n 2 google-services.json
39-
40-
if [ ! -s google-services.json ]; then
41-
echo "❌ File is empty!"
42-
exit 1
43-
fi
29+
echo "🔄 Validating JSON..."
30+
jq empty google-services.json # Requires jq installed
4431
env:
4532
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
4633

47-
- name: Create .env file
34+
- name: '⚙️ Create .env File'
4835
run: |
4936
echo "${{ secrets.ENV_FILE_CONTENT }}" > .env
50-
echo "" >> .env # Ensure file ends with a newline
37+
echo "" >> .env # Ensure trailing newline
5138
52-
- name: Debug .env file
53-
run: |
54-
echo "=== .env file content ==="
55-
cat .env
56-
echo "=== End of .env file ==="
57-
58-
# Debug: Check file size of google-services.json
59-
- name: Check google-services.json file size
60-
run: wc -c google-services.json
61-
62-
# Validate JSON syntax
63-
- name: Validate google-services.json
64-
run: node -e "JSON.parse(require('fs').readFileSync('google-services.json','utf8'))"
65-
66-
- name: Build Docker image
39+
# ========================
40+
# 🐳 Docker Operations
41+
# ========================
42+
- name: '🛠 Build Docker Image'
6743
run: docker build -t codebuilder-webapp:latest .
6844

69-
- name: Stop and remove old container (if running)
45+
- name: '🗑 Cleanup Old Containers'
7046
run: |
71-
OLD_CONTAINER_ID=$(docker ps -aq --filter name=codebuilder-webapp)
72-
if [ -n "$OLD_CONTAINER_ID" ]; then
73-
echo "Stopping and removing container $OLD_CONTAINER_ID..."
74-
docker stop $OLD_CONTAINER_ID
75-
docker rm $OLD_CONTAINER_ID
76-
else
77-
echo "No old container found."
78-
fi
47+
docker ps -aq --filter name=codebuilder-webapp | xargs -r docker rm -f
7948
80-
- name: Start new container
81-
run: docker run -d --network host -p 3000:3000 --env-file .env --name codebuilder-webapp codebuilder-webapp:latest
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-webapp \
56+
codebuilder-webapp:latest

0 commit comments

Comments
 (0)