Day 13 · 1 Hour
Firebase Deployment
"It works on my machine" is a joke — today your app gets a real URL anyone can open.
🔥 Real-World Hook (0–5 min)
Your app works on localhost — but no one can use it. "It works on my machine" is the biggest joke in software.
Today you deploy your app so anyone in the world can open it from their phone. Frontend goes to Firebase Hosting (free, fast CDN). Backend goes to Google Cloud Run. By the end you'll have a real URL to share.
🌐 Deployment Architecture (5–20 min)
💡 Where Each Part Lives
Frontend HTML/CSS/JS → Firebase Hosting (free, global CDN)
Spring Boot API → Docker container → Google Cloud Run (pay per request)
MySQL Database → Google Cloud SQL or PlanetScale (managed database)
💻 Live Coding — Deploy Frontend to Firebase (20–40 min)
# Step 1: Install Firebase CLI npm install -g firebase-tools # Step 2: Login firebase login # Step 3: Initialize project firebase init hosting # Step 4: firebase.json config
{
"hosting": {
"public": "frontend",
"ignore": ["firebase.json", "**/.*"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
# Step 5: Build & Deploy firebase deploy --only hosting # Step 6: Dockerize Spring Boot backend
# Dockerfile FROM openjdk:17-jdk-slim WORKDIR /app COPY target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]
# Build and push to Google Container Registry mvn clean package -DskipTests docker build -t gcr.io/YOUR_PROJECT/student-api . docker push gcr.io/YOUR_PROJECT/student-api # Deploy to Cloud Run gcloud run deploy student-api --image gcr.io/YOUR_PROJECT/student-api --platform managed --region us-central1 --allow-unauthenticated
🎯 You Code It (40–55 min)
- Install Firebase CLI:
npm install -g firebase-tools - Run
firebase loginand authenticate with your Google account - In your frontend folder, run
firebase init hostingand select your project - Update your frontend's API_BASE URL to your Cloud Run URL (or keep localhost for now)
- Run
firebase deploy --only hosting - Open the Firebase URL — your app is live!
- Show: Share the Firebase URL with the instructor
📄 Day 13 Cheat Sheet — Deployment
Firebase CLI
| npm install -g firebase-tools | Install |
| firebase login | Authenticate |
| firebase init hosting | Setup project |
| firebase deploy | Deploy all |
| firebase deploy --only hosting | Frontend only |
| firebase open hosting:site | Open deployed site |
Docker Commands
| docker build -t name . | Build image |
| docker run -p 8080:8080 name | Run container |
| docker images | List images |
| docker ps | Running containers |
| docker push gcr.io/project/name | Push to registry |
Cloud Run
| gcloud run deploy name | Deploy service |
| --image gcr.io/project/name | Container image |
| --allow-unauthenticated | Public access |
| --region asia-south1 | Mumbai region |
| gcloud run services list | View services |
application.properties (prod)
| spring.datasource.url=${DB_URL} | Env variable |
| spring.profiles.active=prod | Activate profile |
| server.port=${PORT:8080} | Cloud Run port |
| logging.level.root=WARN | Reduce log noise |