-
Notifications
You must be signed in to change notification settings - Fork 0
Deploy gcp #9
base: main
Are you sure you want to change the base?
Deploy gcp #9
Changes from all commits
c5d20a4
15bb9cf
82b788e
ea61e22
13497db
f8240ce
5d1f39a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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. |
| 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 --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 |
| 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
|
||||||||||||||||||||||||||||||||||||||||||
| 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
AI
Jul 25, 2025
There was a problem hiding this comment.
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.
| 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'] |
Uh oh!
There was an error while loading. Please reload this page.