Skip to content

Self-Host Cal.com With Coherence

This guide demonstrates how to use Coherence and Google Cloud Platform (GCP) to host an instance of Cal.com, a scheduling application that helps users plan and track meetings with integrations for various calendars and communication tools.

What you'll learn

This guide will show you how to:

  1. Set up a Coherence environment and services
  2. Connect Coherence to GCP
  3. Provision new infrastructure
  4. Configure environment variables
  5. Integrate Google Calendar
  6. Permit Cal.com to send emails on your behalf
  7. Build and push a Cal.com Docker image
  8. Deploy the self-hosted Cal.com instance

By the end of this guide, you will have a self-hosted version of Cal.com running:

image of Cal.com running

Coherence will create and manage the required infrastructure in your cloud environment to streamline building and deploying your app while simplifying resource management.

Prerequisites

To follow along, you'll need:

1. Set up a Coherence environment and services

Start by setting up a Coherence and services for your application.

Create a new application

  1. On the Coherence dashboard, click New application.
  2. Name the application a name.
  3. Select your cloud provider and architecture.
  4. Click Create application.

Create a collection

  1. On the application's landing page, click Create collection.
  2. Name the collection.
  3. Click Create collection.

Configure an environment

  1. On the collection dashboard, click New environment.
  2. Name the environment.
  3. Select the appropriate environment type (Staging is recommended for initial testing) from the dropdown.
  4. Click Create.

For more information on creating applications, collections, and environments, refer to our quick start guide.

Add a Cal.com service to the environment

  1. Navigate to the environment homepage and select the Services tab.

    Creating a new service in Coherence

  2. Click the New service button. In the Containers section, select Other. Complete the popup form as follows:

    • Name: Calcom (Any meaningful name will work)
    • Start command: Clear any entries and leave the field blank
    • URL Path: /
    • Health Check Path: Clear and leave blank
    • Container source: Select the Existing Image option
    • Image: <registry>/calcom – the Cal.com registry and image that you will push your image to
    • Tag source: Static
    • Tag: latest to pull the newest version of the image
    • CPU: Leave unchanged at 1
    • Memory: Leave unchanged at 2G

    image of the new container service form with the fields filled in

  3. Click the Create service button.

    New container service form with the fields filled in

Note: Depending on your needs, you may need to increase the CPU and Memory resource limits. If you change these values after the infrastructure has been provisioned and the application has been deployed, you'll need to provision the infrastructure again and redeploy the application.

Create a service for the database

  1. Click New service.
  2. In the Database section, select Postgres.
  3. Give the database a name, like db, and click Create service.

Database service creation form

2. Connect Coherence to GCP

  1. In the Ready to deploy? banner at the top of the page, click Connect.

    Connect to cloud provider banner

  2. Follow the prompts to connect to your GCP instance and add the relevant user role.

  3. When you are prompted to import variables, you can click Skip this.

3. Provision new infrastructure

  1. In the Provision task needed notice at the top of the page, click Go.

    Provision cloud notice

  2. Click Submit new task to queue a task to create the required infrastructure. Provisioning may take a few minutes to complete.

4. Configure environment variables

  1. After the infrastructure has been provisioned, navigate to the Variables tab of your Coherence environment hompepage.
  2. Create two secrets by clicking New variable, selecting Secret from the dropdown, filling in the form as follows, and clicking Create.

    • Enter CALENDSO_ENCRYPTION_KEY as the Name and openssl rand -base64 24 as the Value.
    • Enter NEXTAUTH_SECRET as the Name and openssl rand -base64 32 as the Value.
  3. Add aliases for existing environment variables by expanding the System section, selecting the three-dot menu for each variable, and clicking Create Alias. Use the following aliases for these database variables:

    Add alias UI

    • DB_HOST: DATABASE_HOST
    • DB_NAME: POSTGRES_DB
    • DB_USER: POSTGRES_USER
    • < name >_DB_PASSWORD: POSTGRES_PASSWORD

At this point, you can decide whether to enable integrations with Google Calendar and set up emails from Cal.com.

5. Integrate Google Calendar

To enable integration with Google Calendar, add a new environment variable for GOOGLE_API_CREDENTIALS in Coherence, and follow these steps to get the Value for the key:

  1. Open the GCP API Console.
  2. Click the + Enable APIs and Services button.
  3. Type calendar in the search box, select the Google Calendar API result to view the Product Details page, and click Enable.
  4. Use the APIs and Services side panel to navigate to the OAuth consent screen.
  5. Select your application User Type, fill out the form on the first page to register your app, and click Save and Continue.
  6. On the Scopes page, select Add or Remove Scopes.
  7. Search for Calendar.event, select the scopes with the scope values .../auth/calendar.events and .../auth/calendar.readonly, then click Update.
  8. Select Credentials from the APIs and Services side panel and click + Create Credentials.
  9. Select OAuth client ID from the dropdown.
  10. Select Web Application as the Application Type.
  11. Under Authorized redirect URIs, select + Add URI, and add the URIs, <URL>/api/integrations/googlecalendar/callback and <URL>/api/auth/callback/google, replacing URL with the URI where the application will be hosted.
  12. The key will be created and you will be redirected to the Credentials page.
  13. Select the newly generated client ID under OAuth 2.0 Client IDs.
  14. Select Download JSON.
  15. Under OAuth consent screen, click Publish App.

When you've completed these steps, copy the entire contents of the downloaded JSON file and paste it in the Value field for the GOOGLE_API_CREDENTIALS key you created.

6. Permit Cal.com to send emails on your behalf

Add the following environment variables with the appropriate settings:

EMAIL_FROM=notifications@example.com

EMAIL_SERVER_HOST=smtp.example.com
EMAIL_SERVER_PORT=587
EMAIL_SERVER_USER=email_user
EMAIL_SERVER_PASSWORD=email_password

Note: The EMAIL_FROM address must have the necessary permissions enabled for sending emails via your SMTP server.

7. Build and push a Cal.com Docker image

Clone the repository

  1. Clone the Cal.com docker repository:

    git clone --recursive https://github.com/calcom/docker.git calcom-docker
    
  2. Navigate into the cloned directory:

    cd calcom-docker
    
  3. Update the Cal.com repository submodule:

    git submodule update --remote --init
    

Build image

Ensure you have an artifact registry ready to push your image to. If you are new to Docker containers, we recommend using Docker Hub as a starting point. Consult the Docker reference documentation to learn more about using docker compose push to push images to Docker Hub.

Platform-specific configuration

If you use macOS with Apple Silicon or another ARM-based system that may encounter compatibility issues with the x86-based Docker image, add a platform tag to all services in your docker-compose.yml file to ensure the correct image architecture is used for the build:

services:
  database:
    container_name: database
    image: postgres
    platform: linux/amd64 # Add this line

    # ... other configurations ...

  calcom:
    image: <registry>/calcom:latest
    platform: linux/amd64 # Add this line

    # ... other configurations ...

  studio:
    image: calcom.docker.scarf.sh/calcom/cal.com
    platform: linux/amd64 # Add this line

    # ... other configurations ...

Set up the environment

The Cal.com Docker repository uses docker compose to build and publish Docker images. One of these images is Prisma Studio, which is responsible for applying database migrations and other database management operations.

  1. In the root folder of the calcom-docker repository, rename the .env.example file to .env:

    mv .env.example .env
    
  2. Open the .env file with any text editor and find the following two variables:

    NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
    NEXT_PUBLIC_API_V2_URL=http://localhost:5555/api/v2
    
  3. Replace the localhost URL with the domain found in your Coherence environment.

    Domains list in Coherence

    The values should look similar to this once you are done:

    NEXT_PUBLIC_WEBAPP_URL=https://<env>.<hash>.<org>.cncsites.com
    NEXT_PUBLIC_API_V2_URL=https://<env>.<hash>.<org>.cncsites.com/api/v2
    
  4. Now find the following variables in the .env file:

    POSTGRES_USER=unicorn_user
    POSTGRES_PASSWORD=magical_password
    POSTGRES_DB=calendso
    DATABASE_HOST=database:5432
    

    POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB can all be found under the DB_USER, <name>_DB_PASSWORD, and DB_NAME variables respectively in your Coherence environment.

    Because the database connection occurs via a local machine when you run the container, you will need to set up remote database connections and find the public IP address for the DATABASE_HOST key.

Enable remote connections to the Postgres database

  1. In the GCP project connected to Coherence, navigate to the SQL menu option, select the database, open Connections from the menu, and select the Networking tab.

  2. Under the Authorized networks section, click the Add a network button.

  3. Name the network remote connection and enter 0.0.0.0/0 in the Network field.

Add the database public IP

  1. In the Overview of your SQL database, find the Connect to this instance section and note the Public IP address.

  2. Add the public IP for the database to the DATABASE_HOST key. If you are unsure which port to use, find the DB_PORT in your Coherence environment variables.

  3. Run the image:

    docker compose up
    

    You will notice migrations being run in the log, wait for these to complete before moving on.

    NOTE: Once all the migrations have been completed, you can remove the authorized network you added to GCP SQL to help prevent unwanted access to your database.

  4. Close the session with ctrl + c when done.

Edit docker-compose.yaml

  1. Open the docker-compose.yaml and make the following changes:

    • Under services -> calcom, replace the value for the image key with the registry you want to push to.
    • Change the ports to 8080:3000

    Your docker-compose.yaml should now look something like this:

    # Use postgres/example user/password credentials
    version: '3.8'
    
    volumes:
      database-data:
    
    networks:
      stack:
        name: stack
        external: false
    
    services:
      database:
        container_name: database
        image: postgres
        restart: always
        volumes:
          - database-data:/var/lib/postgresql/data/
        env_file: .env
        networks:
          - stack
    
      calcom:
        image: <registry>/calcom:latest
        build:
          context: .
          dockerfile: Dockerfile
          args:
            NEXT_PUBLIC_WEBAPP_URL: ${NEXT_PUBLIC_WEBAPP_URL}
            NEXT_PUBLIC_API_V2_URL: ${NEXT_PUBLIC_API_V2_URL}
            NEXT_PUBLIC_LICENSE_CONSENT: ${NEXT_PUBLIC_LICENSE_CONSENT}
            CALCOM_TELEMETRY_DISABLED: ${CALCOM_TELEMETRY_DISABLED}
            NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
            CALENDSO_ENCRYPTION_KEY: ${CALENDSO_ENCRYPTION_KEY}
            DATABASE_URL: ${DATABASE_URL}
            DATABASE_DIRECT_URL: ${DATABASE_URL}
          network: stack
        restart: always
        networks:
          - stack
        ports:
          - 8080:3000
        env_file: .env
        environment:
          - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
          - DATABASE_DIRECT_URL=${DATABASE_URL}
        depends_on:
          - database
    
    # Optional use of Prisma Studio. In production, comment out or remove the section below to prevent unwanted access to your database.
      studio:
        image: calcom.docker.scarf.sh/calcom/cal.com
        restart: always
        networks:
          - stack
        ports:
          - 5555:5555
        env_file: .env
        environment:
          - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
          - DATABASE_DIRECT_URL=${DATABASE_URL}
        depends_on:
          - database
        command:
          - npx
          - prisma
          - studio
    # END SECTION: Optional use of Prisma Studio.
    
  2. Tag the image:

    docker tag calcom.docker.scarf.sh/calcom/cal.com <your-registry>/<your-image-name>:<tag>
    
  3. Push the image to a registry:

    docker push <your-registry>/<your-image-name>:<tag>
    

7. Deploy the self-hosted Cal.com instance

  1. To deploy the Cal.com application, navigate to the Deployments tab of your environment homepage, then click New Deployment and Submit deployment.

    submit deployment UI

  2. Monitor the status of the queued Build and Deploy pipelines.

    image queued pipelines

    When the pipelines have run, you should see a Success notification in the Latest deployments list indicating that Cal.com has been deployed.

    Image of the UI when deployment was successful

  3. Navigate to the URL under Domains to fill out the form to create an administrator account.

    Image of the UI when deployment was successful

  4. On the next page, choose the type of license you would like to use. Select AGPLv3 License if you are unsure.

    Image of the Calc.com license UI

  5. Next, you'll see a list of apps you can connect to. Scroll down to select the Google Calendar option. Click the pen icon to ensure the credentials you added as environment variables are reflected.

    image of Cal.com running

  6. Upon completion, you will be redirected to the Cal.com landing page. Follow the prompts to set up a Cal.com profile by creating a URL for your meetings, adding integrations, linking existing calendars, and customizing your availability schedule.

    image of Cal.com running

  7. Click + New on the top right of the page to add a new event.

  8. After creating an event, select the link button as shown:

    Cal.com event details

  9. Paste that link in another browser tab, then schedule a time and confirm the booking.

    Cal.com event details

    If you have added email integration, an email will be sent to all parties involved.

For more information on using Cal.com, refer to the Cal.com documentation.