Skip to content
This repository was archived by the owner on Nov 8, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Dependencies
node_modules

# Next.js build output
.next

# Docker
Dockerfile
.dockerignore

# Git
.git
.gitignore

# Other
README.md
.github
docs
tests
65 changes: 65 additions & 0 deletions DEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Deploying to Google Cloud

This guide will walk you through deploying the application to Google Cloud using Google Cloud Build and Google Cloud Run.

## Prerequisites

1. **Google Cloud Project:** You need a Google Cloud project with billing enabled.
2. **gcloud CLI:** You need to have the `gcloud` command-line tool installed and configured for your project.
3. **Enable APIs:** Enable the Cloud Build, Cloud Run, and Container Registry APIs for your project. You can do this with the following commands:

```bash
gcloud services enable cloudbuild.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable containerregistry.googleapis.com
```

## Deployment Steps

1. **Clone the repository:**

```bash
git clone https://github.com/zzfadi/toico.git
cd toico
```

2. **Set your Project ID:**

Replace `[YOUR_PROJECT_ID]` with your Google Cloud project ID.

```bash
export PROJECT_ID=[YOUR_PROJECT_ID]
```

3. **Run Cloud Build:**

This command will use the `cloudbuild.yaml` file to build the Docker image, push it to Google Container Registry, and deploy it to Google Cloud Run.

```bash
gcloud builds submit --config cloudbuild.yaml .
```

4. **Access your application:**

Once the deployment is complete, you will see the URL of your deployed application in the output. You can also find the URL in the Google Cloud Console under Cloud Run.

## Mapping a Custom Domain

To map a custom domain like `tools.definedbyjenna.com` to your Cloud Run service, follow these steps:

1. **Go to the Cloud Run section** in the Google Cloud Console.
2. **Click on your service** (e.g., `toico`).
3. **Click on "Manage custom domains"**.
4. **Click "Add mapping"**.
5. **Select your verified domain** from the dropdown list. If you haven't verified your domain with Google Cloud yet, you will be prompted to do so.
6. **Enter the subdomain** you want to use (e.g., `tools`).
7. **Click "Continue"** and follow the instructions to update your DNS records. This will typically involve adding a `CNAME` or `A` record to your DNS provider's configuration (e.g., Squarespace).
8. **Wait for the DNS changes to propagate**. This can take up to 24 hours. Once the propagation is complete, your application will be available at your custom domain.

## Continuous Deployment (Optional)

You can set up a trigger in Google Cloud Build to automatically deploy the application whenever you push changes to your Git repository.

1. Go to the Cloud Build section in the Google Cloud Console.
2. Go to the "Triggers" tab and click "Create trigger".
3. Connect your repository and configure the trigger to use the `cloudbuild.yaml` file for the build configuration.
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Stage 1: Build the Next.js application
FROM node:20-alpine AS builder

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package.json package-lock.json ./

# Install dependencies
RUN npm ci

# Copy the rest of the application files
COPY . .

# Build the Next.js application
RUN npm run build

# Stage 2: Create the production image
FROM node:20-alpine AS runner

# Set working directory
WORKDIR /app

# Copy the built application from the builder stage
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/next.config.ts ./next.config.ts
Comment on lines +29 to +30
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the entire node_modules directory from the builder stage defeats the purpose of a multi-stage build. For a production Next.js app, you should install only production dependencies in the runner stage with 'RUN npm ci --only=production' after copying package.json.

Suggested change
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/next.config.ts ./next.config.ts
COPY --from=builder /app/package-lock.json ./package-lock.json
COPY --from=builder /app/next.config.ts ./next.config.ts
RUN npm ci --only=production

Copilot uses AI. Check for mistakes.

# Expose the port the app runs on
EXPOSE 3000

# Start the Next.js application
CMD ["npm", "start"]
25 changes: 25 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA', '.']

# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA']
Comment on lines +4 to +8
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substitution variable $_SERVICE_NAME is used but not defined anywhere in the build configuration. This will cause the build to fail. Either define it as a substitution variable or replace it with a hardcoded service name like 'toico' to match line 16.

Suggested change
args: ['build', '-t', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA']
args: ['build', '-t', 'gcr.io/$PROJECT_ID/toico:$COMMIT_SHA', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/toico:$COMMIT_SHA']

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +8
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as line 4 - $_SERVICE_NAME is undefined. This should be consistent with the hardcoded 'toico' service name used in the deployment step.

Suggested change
args: ['build', '-t', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA']
args: ['build', '-t', 'gcr.io/$PROJECT_ID/toico:$COMMIT_SHA', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/toico:$COMMIT_SHA']

Copilot uses AI. Check for mistakes.

# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'toico'
- '--image'
- 'gcr.io/$PROJECT_ID/toico:$COMMIT_SHA'
- '--region'
- 'us-central1'
- '--platform'
- 'managed'
# 23: - '--allow-unauthenticated'
images:
- 'gcr.io/$PROJECT_ID/toico:$COMMIT_SHA'