Ready to deploy your first app on Google Cloud Platform? In this tutorial, we’ll guide you through deploying a basic “Hello World” web app using two powerful GCP services: Cloud Run and App Engine. Both options are serverless and ideal for beginners.
1. Prerequisites
- A GCP project with billing enabled
gcloud
CLI installed and initialized- Docker installed (for Cloud Run)
- A simple app (we’ll use Python Flask as an example)
2. Hello World with Cloud Run
Step 1: Create Your App
# main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello from Cloud Run!"
# requirements.txt
flask
Step 2: Create a Dockerfile
# Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
Step 3: Build and Deploy
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/hello-app
gcloud run deploy hello-app \
--image gcr.io/YOUR_PROJECT_ID/hello-app \
--platform managed \
--region us-central1 \
--allow-unauthenticated
Once deployed, Cloud Run will return a public HTTPS URL where your app is live!
3. Hello World with App Engine
Step 1: Create Your App
You can reuse the same main.py
and requirements.txt
as above. Add:
# app.yaml (App Engine config)
runtime: python311
entrypoint: python main.py
handlers:
- url: /.*
script: auto
Step 2: Deploy to App Engine
gcloud app create --region=us-central
gcloud app deploy
After deployment, your app will be live at https://PROJECT_ID.REGION_ID.r.appspot.com
.
4. Summary
Both Cloud Run and App Engine make deploying a simple app incredibly fast and easy. Use Cloud Run if you prefer working with containers and want flexibility, or App Engine for a more opinionated, code-first PaaS approach.
Next Steps
- Add environment variables or configs
- Connect a custom domain
- Add authentication via Firebase or IAM
- Explore CI/CD with Cloud Build or GitHub Actions
0 Comments