1. Answers
  2. Deploy The Bitnami/mongodb:latest Docker Image On Google CloudRun With TypeScript.

Deploy the Bitnami/Mongodb:latest Docker Image on Google CloudRun With TypeScript.

Introduction

In this guide, we will deploy the bitnami/mongodb:latest Docker image on Google CloudRun using Pulumi with TypeScript. Google CloudRun is a fully managed compute platform that automatically scales your stateless containers. Pulumi allows you to define, deploy, and manage cloud infrastructure using familiar programming languages.

Step-by-Step Explanation

Step 1: Set Up Pulumi and Google Cloud Provider

  1. Install Pulumi CLI from Pulumi Installation Guide.
  2. Set up your Pulumi project by running pulumi new and selecting a TypeScript template.
  3. Install the Pulumi Google Cloud provider by running npm install @pulumi/google-native.
  4. Authenticate with Google Cloud by running gcloud auth login and gcloud auth application-default login.

Step 2: Define the Docker Image and CloudRun Service

  1. Create a new file index.ts in your Pulumi project directory.
  2. Import the necessary Pulumi and Google Cloud libraries.
  3. Define the Docker image to be used (bitnami/mongodb:latest).
  4. Create a CloudRun service and configure it to use the Docker image.
  5. Set the necessary environment variables and permissions for the CloudRun service.

Step 3: Deploy the CloudRun Service

  1. Run pulumi up to deploy the CloudRun service.
  2. Verify the deployment by accessing the CloudRun service URL provided by Pulumi.

Conclusion

By following these steps, you have successfully deployed the bitnami/mongodb:latest Docker image on Google CloudRun using Pulumi with TypeScript. This setup leverages the scalability and manageability of Google CloudRun along with the infrastructure as code capabilities of Pulumi.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
import * as docker from "@pulumi/docker";

// Define the Docker image
const mongoImage = new docker.RemoteImage("mongoImage", {
    name: "bitnami/mongodb:latest",
});

// Create the CloudRun service
const cloudRunService = new gcp.cloudrun.Service("mongoService", {
    location: "us-central1",
    template: {
        spec: {
            containers: [{
                image: mongoImage.name,
                ports: [{
                    containerPort: 27017,
                }],
                envs: [{
                    name: "MONGO_INITDB_ROOT_USERNAME",
                    value: "root",
                }, {
                    name: "MONGO_INITDB_ROOT_PASSWORD",
                    value: "example",
                }],
            }],
        },
    },
});

// Allow public access to the CloudRun service
const iamMember = new gcp.cloudrun.IamMember("publicAccess", {
    service: cloudRunService.name,
    location: cloudRunService.location,
    role: "roles/run.invoker",
    member: "allUsers",
});

// Export the URL of the CloudRun service
export const cloudRunServiceUrl = cloudRunService.statuses[0].url;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up