diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e48fb8b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# Dependencies +node_modules + +# Next.js build output +.next + +# Docker +Dockerfile +.dockerignore + +# Git +.git +.gitignore + +# Other +README.md +.github +docs +tests diff --git a/DEPLOY.md b/DEPLOY.md new file mode 100644 index 0000000..27ed3d3 --- /dev/null +++ b/DEPLOY.md @@ -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. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..77dfb5f --- /dev/null +++ b/Dockerfile @@ -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 + +# Expose the port the app runs on +EXPOSE 3000 + +# Start the Next.js application +CMD ["npm", "start"] diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 0000000..87a586c --- /dev/null +++ b/cloudbuild.yaml @@ -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'] + + # 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'