2do App with Automatic Deploy to Google Cloud and FTP
Building a 2do app (for daily tasks) with automatic deploy to Google Cloud and FTP
2do App with Automatic Deploy to Google Cloud and FTP
How it works
git push origin main
↓
backend/** changed? → GitHub Actions → Docker Build → Cloud Run (Google Cloud)
frontend/** changed? → GitHub Actions → FTP Upload → razvan-traian.ro
The whole deploy happens automatically from a single git push. Nothing needs to be configured in Cloud Build.
Repo structure
/
├── .github/workflows/
│ ├── deploy-backend.yml ← automatic backend deploy to Cloud Run
│ └── deploy-frontend.yml ← automatic frontend deploy to razvan-traian.ro
├── backend/
│ ├── index.php
│ ├── .htaccess
│ ├── Dockerfile
│ ├── docker-compose.yml ← local testing
│ ├── .env ← NOT committed to git
│ └── .env.example
├── frontend/
│ ├── index.php
│ ├── sw.js
│ ├── manifest.json
│ ├── icons/
│ ├── .htaccess
│ └── .env ← NOT committed to git
└── storage/ ← SQLite, local only
GitHub Secrets
Repo → Settings → Secrets and variables → Actions → New repository secret
Add the following secrets:
| Secret | Where to get it | Example |
|---|---|---|
GCP_PROJECT_ID |
Google Cloud → project name | 2do-app-123456 |
GCP_SA_KEY |
Google Cloud → Service Account → JSON key (see step 3) | {"type":"service_account",...} |
BEARER_TOKEN |
generated by you with openssl rand -hex 32 |
a3f9... |
BACKEND_URL |
the Cloud Run URL received after the first deploy | https://backend-xxxx-ew.a.run.app |
APP_PASSWORD |
password for the app's lock screen | password |
FTP_HOST |
cPanel → FTP Accounts | ftp.server.ro |
FTP_USER |
cPanel → FTP Accounts | user@server.ro |
FTP_PASS |
cPanel → FTP Accounts | ftp_password |
FTP_PATH |
path on the server where the frontend lives | /home/razvantr/2do.razvan-traian.ro/ |
Google Cloud setup (one time)
Step 1 — Create a project
- Go to https://console.cloud.google.com
- Click the project selector (top) → New Project
- Project name:
2do-app→ Create - Note the Project ID (e.g.
2do-app-123456) — you'll put it inGCP_PROJECT_ID
Step 2 — Enable the required APIs
gcloud services enable \
run.googleapis.com \
artifactregistry.googleapis.com \
iam.googleapis.com \
iamcredentials.googleapis.com \
--project=do-app-razvan-traian
Step 3 — Create a Repository in Artifact Registry
- Cloud Console → Artifact Registry → Repositories → Create Repository
- Name:
2do - Format:
Docker - Region:
europe-west1 - Click Create
Step 4 — Create a Service Account (for GitHub Actions)
- Cloud Console → IAM & Admin → Service Accounts → Create Service Account
- Name:
github-deploy→ Done - Click on the created service account → Keys → Add Key → JSON
- A
.jsonfile is downloaded — copy its entire content into the GitHub secretGCP_SA_KEY
Now grant it the required permissions from the terminal:
SA_EMAIL="github-deploy@do-app-razvan-traian.iam.gserviceaccount.com"
PROJECT_ID="do-app-razvan-traian"
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SA_EMAIL" --role="roles/artifactregistry.writer"
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SA_EMAIL" --role="roles/run.admin"
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SA_EMAIL" --role="roles/iam.serviceAccountUser"
gcloud projects add-iam-policy-binding $PROJECT_ID --member="serviceAccount:$SA_EMAIL" --role="roles/storage.admin"
Step 5 — First run (only the first time)
After you've put all the secrets in GitHub, push something to backend/:
# change any file in backend/ to trigger the workflow
git add backend/
git commit -m "initial backend deploy"
git push origin main
GitHub Actions will build + deploy automatically. At the end you'll get the backend URL:
https://backend-xxxx-ew.a.run.app
cPanel setup — razvan-traian.ro (one time)
Step 1 — Get FTP credentials
- Log in to cPanel
- FTP Accounts → create a new FTP account or use an existing one
- Note: host, username, password
- Put them in the GitHub secrets:
FTP_HOST,FTP_USER,FTP_PASS
Step 2 — Set the deploy path
In FTP_PATH put the exact server path where you want the frontend to live.
E.g. if you want https://razvan-traian.ro/2do/ → FTP_PATH = /public_html/2do/
Step 3 — The .env file on the server
The frontend's .env file is created automatically by GitHub Actions on every deploy, using the GitHub secrets (BACKEND_URL, BEARER_TOKEN, APP_PASSWORD). You don't need to create it manually.
Make sure you've added all the secrets from the table above in GitHub → Settings → Secrets.
Local testing
# 1. Start the backend
cd backend
docker compose up --build
# 2. In a separate terminal, start the frontend
cd frontend
php -S localhost:8000
Open http://localhost:8000 in your browser.
backend/.env for local:
BEARER_TOKEN=any_local_token
SQLITE_PATH=/tmp/tasks.db
frontend/.env for local:
BEARER_TOKEN=any_local_token
BACKEND_URL=http://localhost:8080
APP_PASSWORD=ro10bibu
After setup — how to deploy
# Change code, then:
git add .
git commit -m "change description"
git push origin main
- If you changed something in
backend/→ it deploys automatically to Cloud Run - If you changed something in
frontend/→ it uploads automatically to razvan-traian.ro via FTP - If you changed both → both deploy in parallel
GitHub repository: https://github.com/BrTDevil/2do-cloud