Skip to content

Commit

Permalink
Significant Refactor.
Browse files Browse the repository at this point in the history
- added numerous environment variable changes such as implied defaults that can be overriden.
- skipped out on using git modules and just pull repo into build/launch step.  Adherance to license requires no repackaging and this solves this.
- cleaned up now unnecessary .env file.
- recycled environment section using yaml features.
- writing a few strings to config path to persist data between container starts that focus on cryptography and secrets.
- writing installed commit to the config path in case the end user needs to change the upstream git commit ID to a newer version for detection and automagic upgrades.
- added docker-compose.override.yml pattern to .gitignore to allow users to customize their local dev environment if they use docker-compose.yml
- wrote a dockerfile/container image which allows for uploading the base container to a private or public docker container registry without breaking the license rules.
- left .env ignore in case users wish to continue to use the old method.
- updated README.md to include updated simplified instructions.
- added start.sh script and wait-for-it.sh into the shell $PATH to allow for a potential future of allowing the main executable (node JS app) to run under a limited privilege user while still allowing the init scripts to be executed securely.
- added some input sanitation for certain critical variables.
- by default disabled/commented out the studio service as its not to typically be run to enforce better default deployment practices.  I would like to figure out what specific query to execute via the CLI instead of running a whole container to establish the first user in the end.
- wrote relatively unopinionated docker-compose.yml file to avoid causing problems for people trying to deploy this behind a reverse proxy for potential features such as TLS/HTTPS termination.
- upgraded compose version to latest '3.9' to be sure to enable most modern feature set.

Fixes calcom#87 by providing a working baseline with sober defaults.
Fixes calcom#88 by ensuring consistency across all containers Environment vars.
Fixes calcom#93 by allowing users to mount the application files within their IDE workspace, however, this will never solve for any times you will need to run yarn build steps.
Fixes calcom#99 by no longer using git submodules and just pulling a single commit depth copy of the ORIGIN repository on app bootstrap/first boot.
Fixes calcom#113 by no longer requiring build locally if the community maintainer of the Cal docker repository on GitHub will push this image to the hub.
Fixes calcom#121 by removing dependency on BuildKit this is done by simply deploying the app if its detected to be the first execution of this container be it due to no container persistence or a commit version upgrade from ORIGIN.
Fixes calcom#128 by removing dep on BuildKit
Fixes calcom#123 not replicatable and confirmed to be working in repository shipped state.
Fixes calcom#136 by building app on first launch from user define-able envvars which can be defined in numerous ways.
  • Loading branch information
Colin committed Aug 1, 2022
1 parent 0e50cea commit 73b2e61
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 265 deletions.
55 changes: 0 additions & 55 deletions .env.example

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/update-submodules.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# .env file
.env
.env
docker-compose.override.yml
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

59 changes: 11 additions & 48 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
FROM node:16 as builder

WORKDIR /calcom
ARG NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
ARG NEXT_PUBLIC_APP_URL
ARG NEXT_PUBLIC_LICENSE_CONSENT
ARG CALCOM_TELEMETRY_DISABLED
ARG DATABASE_URL
ARG NEXTAUTH_SECRET=secret
ARG CALENDSO_ENCRYPTION_KEY=secret
ARG MAX_OLD_SPACE_SIZE=4096

ENV NEXT_PUBLIC_WEBAPP_URL=$NEXT_PUBLIC_WEBAPP_URL \
NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL \
NEXT_PUBLIC_LICENSE_CONSENT=$NEXT_PUBLIC_LICENSE_CONSENT \
CALCOM_TELEMETRY_DISABLED=$CALCOM_TELEMETRY_DISABLED \
DATABASE_URL=$DATABASE_URL \
NEXTAUTH_SECRET=${NEXTAUTH_SECRET} \
CALENDSO_ENCRYPTION_KEY=${CALENDSO_ENCRYPTION_KEY} \
NODE_OPTIONS=--max-old-space-size=${MAX_OLD_SPACE_SIZE}

COPY calcom/package.json calcom/yarn.lock calcom/turbo.json ./
COPY calcom/apps/web ./apps/web
COPY calcom/packages ./packages

RUN yarn install --frozen-lockfile

RUN yarn build

FROM node:16 as runner

WORKDIR /calcom
ENV NODE_ENV production

RUN apt-get update && \
apt-get -y install netcat && \
rm -rf /var/lib/apt/lists/* && \
npm install --global prisma

COPY calcom/package.json calcom/yarn.lock calcom/turbo.json ./
COPY --from=builder /calcom/node_modules ./node_modules
COPY --from=builder /calcom/packages ./packages
COPY --from=builder /calcom/apps/web ./apps/web
COPY --from=builder /calcom/packages/prisma/schema.prisma ./prisma/schema.prisma
COPY scripts scripts

EXPOSE 3000
CMD ["/calcom/scripts/start.sh"]
FROM node:16

COPY scripts /opt/scripts
RUN apt-get update && \
apt-get -y install netcat && \
rm -rf /var/lib/apt/lists/* && \
npm install --location=global prisma && \
ln -s /opt/scripts/start.sh /opt/scripts/wait-for-it.sh /usr/bin/

EXPOSE 3000
CMD ["start.sh"]
139 changes: 77 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,98 +26,125 @@ For Production, for the time being, please checkout the repository and build/pus

## Requirements

Make sure you have `docker` & `docker compose` installed on the server / system. Both are installed by most docker utilities, including Docker Desktop and Rancher Desktop.
Make sure you have `docker` & `docker-compose` installed on the server / system. Both are installed by most docker utilities, including Docker Desktop and Rancher Desktop.

Note: `docker compose` without the hyphen is now the primary method of using docker-compose, per the Docker documentation.
Note: `docker-compose` without the hyphen is now the primary method of using docker-compose, per the Docker documentation.

## Getting Started

1. Clone calcom-docker
1. wget docker-compose.yml to wherever you plan on running this.

```bash
git clone https://github.com/calcom/docker.git calcom-docker
wget https://raw.githubusercontent.com/calcom/docker/main/docker-compose.yml
```

2. Change into the directory
2. Modify the environment section at the top of the `docker-compose.yml` file.


```yaml
x-environment: &environment
environment:
# Set this value to 'agree' to accept our license:
# LICENSE: https://github.com/calendso/calendso/blob/main/LICENSE
#
# Summary of terms:
# - The codebase has to stay open source, whether it was modified or not
# - You can not repackage or sell the codebase
# - Acquire a commercial license to remove these terms by emailing: license@cal.com
## You must agree to these terms manually we can't agree to them for you.
# NEXT_PUBLIC_LICENSE_CONSENT:
# LICENSE:

## Deployment configuration section you may need to change this if you're using a reverse proxy such as nginx, haproxy or træfik.
NEXT_PUBLIC_WEBAPP_URL: http://localhost:3000

# E-mail settings
# Configures the global From: header whilst sending emails.
EMAIL_FROM: notifications@example.com

# Configure SMTP settings (@see https://nodemailer.com/smtp/).
EMAIL_SERVER_HOST: smtp.example.com
EMAIL_SERVER_PORT: 587
EMAIL_SERVER_USER: email_user
EMAIL_SERVER_PASSWORD: email_password

## Only change these if you know what you're doing. Changes are unlikely to be needed.
## However, you could change the password if you like before you start the first time. Also feel free to read about and implement Docker Secrets.
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
DATABASE_HOST: postgres:5432
DATABASE_URL: ${DATABASE_URL:='postgresql://postgres:postgres@postgres:5432/postgres'}
# GOOGLE_API_CREDENTIALS: {}

# Set this to '1' if you don't want Cal to collect anonymous usage. This is not necessary, however, its kind to give back metrics to the app developers if you trust them.
CALCOM_TELEMETRY_DISABLED: 0

# Used for the Office 365 / Outlook.com Calendar integration.
# MS_GRAPH_CLIENT_ID:
# MS_GRAPH_CLIENT_SECRET:

# Used for the Zoom integration.
# ZOOM_CLIENT_ID:
# ZOOM_CLIENT_SECRET:

## Probably only change this if you know what you're doing.
NODE_ENV: production
```

3. Start Cal.com via docker-compose

```bash
cd calcom-docker
```

3. Update the calcom submodule.
(Most basic users, and for First Run) To run the complete stack, which includes a local Postgres database, Cal.com web app, and Prisma Studio:

```bash
git submodule update --remote --init
docker-compose up -d
```

Note: DO NOT use recursive submodule update, otherwise you will receive a git authentication error.

4. Rename `.env.example` to `.env` and then update `.env`

5. Build the Cal.com docker image:

Note: Due to application configuration requirements, an available database is currently required during the build process.

a) If hosting elsewhere, configure the `DATABASE_URL` in the .env file, and skip the next step

b) If a local or temporary database is required, start a local database via docker compose.

...and if you wish to follow the logs you may run...
```bash
docker compose up -d database
docker-compose logs -f
```
and press `ctrl+c` to end following the console logging output.

6. Build Cal.com via docker compose (DOCKER_BUILDKIT=0 must be provided to allow a network bridge to be used at build time. This requirement will be removed in the future)

```bash
DOCKER_BUILDKIT=0 docker compose build calcom
```
8. (First Run) Open a browser to [http://localhost:5555](http://localhost:5555) to look at or modify the database content.

7. Start Cal.com via docker compose
a. Click on the `User` model to add a new user record.

(Most basic users, and for First Run) To run the complete stack, which includes a local Postgres database, Cal.com web app, and Prisma Studio:
b. Fill out the fields (remembering to encrypt your password with [BCrypt](https://bcrypt-generator.com/)) and click `Save 1 Record` to create your first user.

```bash
docker compose up -d
```
9. Open a browser to [http://localhost:3000](http://localhost:3000) (or your appropriately configured NEXT_PUBLIC_WEBAPP_URL) and login with your just created, first user.

### Bonus tips
To run Cal.com web app and Prisma Studio against a remote database, ensure that DATABASE_URL is configured for an available database and run:

```bash
docker compose up -d calcom studio
docker-compose up -d calcom studio
```

To run only the Cal.com web app, ensure that DATABASE_URL is configured for an available database and run:

```bash
docker compose up -d calcom
docker-compose up -d calcom
```

**Note: to run in attached mode for debugging, remove `-d` from your desired run command.**

8. (First Run) Open a browser to [http://localhost:5555](http://localhost:5555) to look at or modify the database content.

a. Click on the `User` model to add a new user record.

b. Fill out the fields (remembering to encrypt your password with [BCrypt](https://bcrypt-generator.com/)) and click `Save 1 Record` to create your first user.

9. Open a browser to [http://localhost:3000](http://localhost:3000) (or your appropriately configured NEXT_PUBLIC_WEBAPP_URL) and login with your just created, first user.

## Configuration

### Build-time variables

These variables must be provided at the time of the docker build, and can be provided by updating the .env file. Currently, if you require changes to these variables, you must follow the instructions to build and publish your own image.
These variables must be provided at the time of the docker build, and can be provided by updating the .env file. Currently, if you require changes to these variables, you must follow the instructions to build and publish your own image.

Updating these variables is not required for evaluation, but is required for running in production. Instructions for generating variables can be found in the [cal.com instructions](https://github.com/calcom/cal.com)
Updating these variables is not required for evaluation, but is required for running in production. Instructions for generating variables can be found in the [cal.com instructions](https://github.com/calcom/cal.com)

| Variable | Description | Required | Default |
| --- | --- | --- | --- |
| NEXT_PUBLIC_WEBAPP_URL | Base URL injected into static files | required | `http://localhost:3000` |
| NEXT_PUBLIC_LICENSE_CONSENT | license consent - true/false | | |
| CALCOM_TELEMETRY_DISABLED | Allow cal.com to collect anonymous usage data (set to `1` to disable) | | |
| DATABASE_URL | database url with credentials | required | `postgresql://unicorn_user:magical_password@database:5432/calendso` |
| NEXTAUTH_SECRET | Cookie encryption key | required | `secret` |
| CALENDSO_ENCRYPTION_KEY | Authentication encryption key | required | `secret` |
| NEXTAUTH_SECRET | Cookie encryption key | required | `randomly defined on first boot` |
| CALENDSO_ENCRYPTION_KEY | Authentication encryption key | required | `randomly defined on first boot` |

### Important Run-time variables

Expand All @@ -126,22 +153,10 @@ These variables must also be provided at runtime
| Variable | Description | Required | Default |
| --- | --- | --- | --- |
| CALCOM_LICENSE_KEY | Enterprise License Key | | |
| NEXTAUTH_SECRET | must match build variable | required | `secret` |
| CALENDSO_ENCRYPTION_KEY | must match build variable | required | `secret` |
| NEXTAUTH_SECRET | must match build variable | required | `randomly defined on first boot` |
| CALENDSO_ENCRYPTION_KEY | must match build variable | required | `randomly defined on first boot` |
| DATABASE_URL | database url with credentials | required | `postgresql://unicorn_user:magical_password@database:5432/calendso` |

## Git Submodules

This repository uses a git submodule.

To update the calcom submodule, use the following command:

```bash
git submodule update --remote --init
```

For more advanced usage, please refer to the git documentation: [https://git-scm.com/book/en/v2/Git-Tools-Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules)

## Troubleshooting

* SSL edge termination: If running behind a load balancer which handles SSL certificates, you will need to add the environmental variable `NODE_TLS_REJECT_UNAUTHORIZED=0` to prevent requests from being rejected. Only do this if you know what you are doing and trust the services/load-balancers directing traffic to your service.
Expand Down
1 change: 0 additions & 1 deletion calcom
Submodule calcom deleted from 6b0ac9
Loading

0 comments on commit 73b2e61

Please sign in to comment.