Skip to content

Commit 2874d73

Browse files
Add Cloud Run + Firebase Hosting deploy config
1 parent c87638c commit 2874d73

File tree

7 files changed

+111
-6
lines changed

7 files changed

+111
-6
lines changed

.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "kinin-code"
4+
}
5+
}

Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ ENV PORT=8080
1818
ENV HOSTNAME=0.0.0.0
1919
WORKDIR /app
2020

21+
COPY package.json package-lock.json ./
22+
COPY --from=deps /app/node_modules ./node_modules
23+
RUN npm prune --omit=dev
24+
25+
COPY --from=builder /app/next.config.ts ./next.config.ts
26+
COPY --from=builder /app/.next ./.next
2127
COPY --from=builder /app/public ./public
22-
COPY --from=builder /app/.next/standalone ./
23-
COPY --from=builder /app/.next/static ./.next/static
28+
COPY --from=builder /app/src/content/pages ./src/content/pages
2429

2530
EXPOSE 8080
26-
CMD ["node", "server.js"]
31+
CMD ["npm", "run", "start"]

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,43 @@ The dev panel lists:
7575
help, ls, cd, pwd, show <file.md>, show -all, echo <text>, hello, mkdir <name>, touch <name>
7676
```
7777

78-
## Deploy (Cloud Run + Cloudflare)
78+
## Deploy (GCP)
79+
80+
Required APIs:
81+
- run.googleapis.com
82+
- cloudbuild.googleapis.com
83+
- artifactregistry.googleapis.com
84+
- cloudresourcemanager.googleapis.com
85+
- iam.googleapis.com
86+
- serviceusage.googleapis.com
87+
- firebase.googleapis.com
88+
- firebasehosting.googleapis.com
89+
90+
Configured names:
91+
- Artifact Registry repo: `kinin-code`
92+
- Cloud Run service: `kinin-code-dev`
93+
94+
Cloud Build Trigger:
95+
1) Cloud Build -> Triggers -> connect GitHub
96+
2) Select `main` and use `cloudbuild.yaml`
97+
98+
Configured values:
99+
- Region: `europe-west1`
100+
- Project ID: `kinin-code`
101+
102+
Firebase Hosting:
103+
```bash
104+
firebase deploy --only hosting
105+
```
106+
107+
Cloudflare DNS:
108+
- Add the Firebase-provided DNS records in Cloudflare (DNS only recommended at first).
109+
110+
Local test:
111+
```bash
112+
docker build -t kinin-code .
113+
docker run -e PORT=8080 -p 8080:8080 kinin-code
114+
firebase emulators:start
115+
```
79116

80-
See `docs/deploy.md` for setup steps and GitHub Actions secrets.
117+
Note: `max-instances` caps cost.

cloudbuild.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
steps:
2+
- name: "gcr.io/cloud-builders/npm"
3+
args: ["ci"]
4+
- name: "gcr.io/cloud-builders/npm"
5+
args: ["run", "build"]
6+
- name: "gcr.io/cloud-builders/docker"
7+
args:
8+
- "build"
9+
- "-t"
10+
- "europe-west1-docker.pkg.dev/$PROJECT_ID/kinin-code/kinin-code:$COMMIT_SHA"
11+
- "."
12+
- name: "gcr.io/cloud-builders/docker"
13+
args:
14+
- "push"
15+
- "europe-west1-docker.pkg.dev/$PROJECT_ID/kinin-code/kinin-code:$COMMIT_SHA"
16+
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
17+
entrypoint: "gcloud"
18+
args:
19+
- "run"
20+
- "deploy"
21+
- "kinin-code-dev"
22+
- "--image"
23+
- "europe-west1-docker.pkg.dev/$PROJECT_ID/kinin-code/kinin-code:$COMMIT_SHA"
24+
- "--region"
25+
- "europe-west1"
26+
- "--platform"
27+
- "managed"
28+
- "--allow-unauthenticated"
29+
- "--min-instances"
30+
- "0"
31+
- "--max-instances"
32+
- "2"
33+
- "--memory"
34+
- "512Mi"
35+
- "--cpu"
36+
- "1"

firebase.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"hosting": {
3+
"public": "public",
4+
"ignore": [
5+
"firebase.json",
6+
"**/.*",
7+
"**/node_modules/**"
8+
],
9+
"rewrites": [
10+
{
11+
"source": "**",
12+
"run": {
13+
"serviceId": "kinin-code-dev",
14+
"region": "europe-west1"
15+
}
16+
}
17+
]
18+
}
19+
}

next.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
44
output: "standalone",
5+
outputFileTracingIncludes: {
6+
"/": ["src/content/pages/**/*.md"],
7+
},
58
};
69

710
export default nextConfig;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "next dev",
77
"build": "next build",
8-
"start": "next start",
8+
"start": "next start -p $PORT -H 0.0.0.0",
99
"lint": "eslint",
1010
"test": "vitest run",
1111
"validate-content": "tsx scripts/validate-content.ts"

0 commit comments

Comments
 (0)