diff --git a/.env.example b/.env.example deleted file mode 100644 index 26ce814e1..000000000 --- a/.env.example +++ /dev/null @@ -1,55 +0,0 @@ -# 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 -NEXT_PUBLIC_LICENSE_CONSENT= -LICENSE= - -# BASE_URL and NEXT_PUBLIC_APP_URL are both deprecated. Both are replaced with one variable, NEXT_PUBLIC_WEBAPP_URL -# BASE_URL=http://localhost:3000 -# NEXT_PUBLIC_APP_URL=http://localhost:3000 - -NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000 - -# It is highly recommended that the NEXTAUTH_SECRET must be overridden and very unique -# Use `openssl rand -base64 32` to generate a key -NEXTAUTH_SECRET=secret - -# Encryption key that will be used to encrypt CalDAV credentials, choose a random string, for example with `dd if=/dev/urandom bs=1K count=1 | md5sum` -CALENDSO_ENCRYPTION_KEY=secret - -# Deprecation note: JWT_SECRET is no longer used -# JWT_SECRET=secret - -POSTGRES_USER=unicorn_user -POSTGRES_PASSWORD=magical_password -POSTGRES_DB=calendso -DATABASE_HOST=database:5432 -DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB} -GOOGLE_API_CREDENTIALS={} - -# Set this to '1' if you don't want Cal to collect anonymous usage -CALCOM_TELEMETRY_DISABLED= - -# 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= - -# 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 - -NODE_ENV=production diff --git a/.github/workflows/update-submodules.yml b/.github/workflows/update-submodules.yml deleted file mode 100644 index 6a8a92a61..000000000 --- a/.github/workflows/update-submodules.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Update Calendso -on: - schedule: - - cron: "0 4 * * *" - workflow_dispatch: ~ - -jobs: - sync: - name: 'Submodules Sync' - runs-on: ubuntu-latest - defaults: - run: - shell: bash - steps: - - name: checkout - uses: actions/checkout@v2 - - - name: Git submodule update - run: | - git submodule update --remote --init - - - name: Commit - run: | - git config user.email "actions@github.com" - git config user.name "actions-user" - git commit -am "Auto updated submodule references" && git push || echo "No changes to commit" diff --git a/.gitignore b/.gitignore index d0c241807..586a4c49c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # .env file -.env \ No newline at end of file +.env +docker-compose.override.yml diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index d2e4d9aa6..000000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "calcom"] - path = calcom - url = https://github.com/calcom/cal.com.git - branch = main diff --git a/Dockerfile b/Dockerfile index 30a51ae84..47c1eec36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 351b935eb..175c09d78 100644 --- a/README.md +++ b/README.md @@ -26,89 +26,116 @@ 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. ## 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. - 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: +### 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, uncomment the studio segment of the included `docker-compose.yml` 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 | | --- | --- | --- | --- | @@ -116,8 +143,8 @@ Updating these variables is not required for evaluation, but is required for run | 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 @@ -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. diff --git a/calcom b/calcom deleted file mode 160000 index 6b0ac96b3..000000000 --- a/calcom +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6b0ac96b38b0dbd78809a73e19010192f31cc769 diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index ce3bf2a9a..000000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,62 +0,0 @@ -# Use postgres/example user/password credentials -version: '3.1' - -volumes: - database-data: - -networks: - stack: - name: stack - external: false - -services: - database: - image: postgres - restart: always - volumes: - - database-data:/var/lib/postgresql/data/ - env_file: .env - networks: - - stack - - calcom: - build: - context: . - dockerfile: Dockerfile - args: - - NEXT_PUBLIC_WEBAPP_URL=${NEXT_PUBLIC_WEBAPP_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} - network: stack - restart: always - networks: - - stack - ports: - - 3000:3000 - env_file: .env - environment: - - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB} - 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: calendso/calendso:latest - restart: always - networks: - - stack - ports: - - 5555:5555 - env_file: .env - environment: - - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB} - depends_on: - - database - command: - - npx - - prisma - - studio -# END SECTION: Optional use of Prisma Studio. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..81952ad72 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,103 @@ +# Use postgres/example user/password credentials +version: '3.9' + +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 + POSTGRES_PORT: 5432 + + # 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 + + +volumes: + postgres-data: + calcom-app: + calcom-config: + +networks: + default: + external: false + +services: + postgres: + image: postgres + restart: always + volumes: + - postgres-data:/var/lib/postgresql/data/ + <<: *environment + networks: + - default + + calcom: + image: calendso/calcom + build: . + restart: always + volumes: + - calcom-app:/calendso/ + - calcom-config:/config/ + networks: + - default + ports: + - 3000:3000 + <<: *environment + depends_on: + - postgres + +# # Optional use of Prisma Studio. +# # You may delete the leading comments(hashtags) from the segment below from studio: onward to the command: section. +# # IMPORTANT NOTICE: In production, comment out or remove the section below to prevent unwanted access to your database. + +# studio: +# image: calendso/calendso:latest +# restart: always +# networks: +# - default +# ports: +# - 5555:5555 +# <<: *environment +# depends_on: +# - postgres +# command: ["npx", "prisma", "studio"] +# # END SECTION: Optional use of Prisma Studio. diff --git a/scripts/start.sh b/scripts/start.sh index a70f1f23d..3bf73df81 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,7 +1,212 @@ -#!/bin/sh -set -x +#!/usr/bin/env bash +# set -x ## uncomment for debug -scripts/wait-for-it.sh ${DATABASE_HOST} -- echo "database is up" -npx prisma migrate deploy --schema /calcom/packages/prisma/schema.prisma -npx ts-node --transpile-only /calcom/packages/prisma/seed-app-store.ts -yarn start +## Environment Config +function ifndef () { + ## Test for null variable and set default, echo result to stdout. + export ${1}="${!1:=$2}" + echo "$1 is ${!1}" +} + +ifndef NEXT_PUBLIC_WEBAPP_URL "http://localhost:3000" +ifndef NEXT_PUBLIC_APP_URL "http://localhost:3000" +## Must be manually overridden to "true" by end user. +ifndef NEXT_PUBLIC_LICENSE_CONSENT "false" + +## If you want to keep your secrets set this to 1 +ifndef CALCOM_TELEMETRY_DISABLED "0" + +## Database Config, usually good to be set as default. +ifndef POSTGRES_USER "postgres" +ifndef POSTGRES_PASSWORD "postgres" +ifndef POSTGRES_DB "postgres" +ifndef POSTGRES_PORT "5432" + +## Use this in a case where you have an external DB. +ifndef POSTGRES_ADDRESS "postgres" +## More database environment strings required for launch. +ifndef DATABASE_HOST "$POSTGRES_ADDRESS:$POSTGRES_PORT" +ifndef DATABASE_URL "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}" +## Cryptography and secrets. +ifndef NEXTAUTH_SECRET $([ -f /config/NEXTAUTH_SECRET ] && cat /config/NEXTAUTH_SECRET) +ifndef CALENDSO_ENCRYPTION_KEY $([ -f /config/CALENDSO_ENCRYPTION_KEY ] && cat /config/CALENDSO_ENCRYPTION_KEY) + +## Other settings that are mostly for container internal operations but are available for customization if desired. +ifndef MAX_OLD_SPACE_SIZE 4096 +ifndef NODE_OPTIONS "--max-old-space-size=$MAX_OLD_SPACE_SIZE" +ifndef RELEASE_COMMIT_ID "6b0ac96b38b0dbd78809a73e19010192f31cc769" +ifndef REPOSITORY_URL "https://github.com/calcom/cal.com.git" +ifndef APP_PATH "/calendso" + +function basic_start() { + cd $APP_PATH + echo "Waiting for a healthy Postgres server connection prior to booting." + wait-for-it.sh $DATABASE_HOST -- echo "database is up" + npx prisma migrate deploy --schema $APP_PATH/packages/prisma/schema.prisma + npx ts-node --transpile-only $APP_PATH/packages/prisma/seed-app-store.ts + echo "Final systems checks cleared and are go for launch." + yarn start +} + +function bootstrap_copyandcleanup() { + cp -Rfv /tmp/calendso/node_modules $APP_PATH/node_modules + cp -Rfv /tmp/calendso/packages $APP_PATH/packages + cp -Rfv /tmp/calendso/apps/web $APP_PATH/apps/web + cp -Rfv /tmp/calendso/packages/prisma/schema.prisma $APP_PATH/prisma/schema.prisma + cp -Rfv /tmp/calendso/.git $APP_PATH/ + cp -v package.json $APP_PATH/ + cp -v yarn.lock $APP_PATH/ + cp -v turbo.json $APP_PATH/ + cd $APP_PATH + rm -Rf /tmp/calendso +} + +function bootstrap_start() { + mkdir -p /tmp/calendso + cd /tmp/calendso + ## Essentially running "git clone https://github.com/calcom/cal.com.git" with a depth of 1 and to the specific release commit SHA. + git init . + git remote add origin https://github.com/calcom/cal.com.git + git fetch --depth 1 origin $RELEASE_COMMIT_ID + git checkout FETCH_HEAD + yarn install --frozen-lockfile + yarn build + bootstrap_copyandcleanup + echo "$RELEASE_COMMIT_ID" > /config/RELEASE_COMMIT_ID && echo "/config/RELEASE_COMMIT_ID is now set to $(cat /config/RELEASE_COMMIT_ID)" + basic_start +} + +## Test for file +function test_for_file() { + if [[ -f "$1" ]]; then + echo "$1 exists" + else + touch $1 + fi +} + +function test_for_dir() { + if [[ -d $1 ]]; then + echo "directory $1 exists." + else + echo "directory $1 doesn't exist prior to container startup, creating $1" + mkdir -pv $1 + echo "$1 is not not mounted and will be reset every boot." + echo "Please mount $1 in your Docker deployment to avoid this message in the future" + echo "and to persist your environments state beyond the life of this container." + fi +} + +## Will I persist? +function test_for_volume() { + if grep -qs "$1" /proc/mounts; then + echo "$1 is a docker volume." + $2 + else + test_for_dir $1 + $2 + fi +} + +## Preboot Check NEXTAUTH_SECRET +function autoconfigure_nextauth_secret() { + echo "Rudimentary NEXTAUTH_SECRET test: $NEXTAUTH_SECRET --------- $(cat /config/NEXTAUTH_SECRET)" + echo "Check if encryption key is set and if not generating a random one and placing it in a /config/NEXTAUTH_SECRET file." + test_for_volume /config + test_for_file /config/NEXTAUTH_SECRET + if [ $(echo $(cat /config/NEXTAUTH_SECRET)|wc -c) != 65 ]; + then + echo "NEXTAUTH_SECRET seems unset, attempting to set a new secret now." + RAND32STR=$(tr -dc '[:alnum:]' < /dev/urandom | dd bs=4 count=16 2>/dev/null) + echo "${NEXTAUTH_SECRET:=$RAND32STR}" > /config/NEXTAUTH_SECRET + echo "Set the /config/NEXTAUTH_SECRET to the following:" + cat /config/NEXTAUTH_SECRET + echo "Secret set and recorded to filesystem, now checking to see if its recorded correctly to the environment." + autoconfigure_nextauth_secret + else + echo "/config/NEXTAUTH_SECRET seems to be correctly installed." + export NEXTAUTH_SECRET=$(cat /config/NEXTAUTH_SECRET) + if [[ $NEXTAUTH_SECRET == $(cat /config/NEXTAUTH_SECRET) ]]; then + echo "NEXTAUTH_SECRET is set correctly in the environment and on disk." + echo "Rudimentary NEXTAUTH_SECRET postconfigure proof: $NEXTAUTH_SECRET --------- $(cat /config/NEXTAUTH_SECRET)" + else + echo "There is something wrong here someone has configured the environment variable NEXTAUTH_SECRET strangely please fix this and start over." + exit + fi + fi +} + +## Preboot Check CALENDSO_ENCRYPTION_KEY +function autoconfigure_calendso_encryption_key() { + echo "Rudimentary CALENDSO_ENCRYPTION_KEY test: $CALENDSO_ENCRYPTION_KEY --------- $(cat /config/CALENDSO_ENCRYPTION_KEY)" + echo "Check if encryption key is set and if not generating a random one and placing it in a /config/NEXTAUTH_SECRET file." + test_for_volume /config + test_for_file /config/CALENDSO_ENCRYPTION_KEY + if [ $(echo $(cat /config/CALENDSO_ENCRYPTION_KEY)|wc -c) != 65 ]; + then + echo "CALENDSO_ENCRYPTION_KEY seems unset, attempting to set a new secret now." + RAND32STR=$(tr -dc '[:alnum:]' < /dev/urandom | dd bs=4 count=16 2>/dev/null) + echo "${CALENDSO_ENCRYPTION_KEY:=$RAND32STR}" > /config/CALENDSO_ENCRYPTION_KEY + echo "Set the /config/CALENDSO_ENCRYPTION_KEY to the following:" + cat /config/CALENDSO_ENCRYPTION_KEY + echo "Secret set and recorded to filesystem, now checking to see if its recorded correctly to the environment." + autoconfigure_calendso_encryption_key + else + export CALENDSO_ENCRYPTION_KEY=$(cat /config/CALENDSO_ENCRYPTION_KEY) + echo "/config/CALENDSO_ENCRYPTION_KEY seems to be correctly installed." + if [[ $CALENDSO_ENCRYPTION_KEY == $(cat /config/CALENDSO_ENCRYPTION_KEY) ]]; then + echo "CALENDSO_ENCRYPTION_KEY is set correctly in the environment and on disk." + echo "Rudimentary CALENDSO_ENCRYPTION_KEY postconfigure proof: $CALENDSO_ENCRYPTION_KEY --------- $(cat /config/CALENDSO_ENCRYPTION_KEY)" + else + echo "There is something wrong here someone has configured the environment variable CALENDSO_ENCRYPTION_KEY strangely please fix this and start over." + exit + fi + fi +} + +## Preboot Check RELEASE_COMMIT_ID +function bootmode_check() { + echo "Rudimentary RELEASE_COMMIT_ID test: $RELEASE_COMMIT_ID --------- $(cat /config/RELEASE_COMMIT_ID)" + echo "Check if commit ID is present and is identical to deployed RELEASE_COMMIT_ID." + test_for_volume /config + test_for_file /config/RELEASE_COMMIT_ID + if [ $(echo $(cat /config/RELEASE_COMMIT_ID)|wc -c) == 41 ]; then + # export RELEASE_COMMIT_ID=$(cat /config/RELEASE_COMMIT_ID) + # echo "$APP_PATH/RELEASE_COMMIT_ID seems to be correctly installed." + if [[ $RELEASE_COMMIT_ID == $(cat /config/RELEASE_COMMIT_ID) ]]; then + # echo "RELEASE_COMMIT_ID is set correctly in the environment and on disk." + # echo "Rudimentary RELEASE_COMMIT_ID postconfigure proof: $RELEASE_COMMIT_ID --------- $(cat /config/RELEASE_COMMIT_ID)" + export BOOTMODE="basic_start" + else + echo "RELEASE_COMMIT_ID is different from previously installed RELEASE_COMMIT_ID assuming an upgrade is required and setting bootstrap_start." + export BOOTMODE="bootstrap_start" + fi + else + echo "RELEASE_COMMIT_ID seems incorrect or unset triggering further checks." + if [[ -z $(cat /config/RELEASE_COMMIT_ID) ]]; then + echo "Cal is not yet installed setting boot flag for first time installation." + export BOOTMODE="bootstrap_start" + fi + fi +} + +## Preflight Checks +autoconfigure_nextauth_secret +autoconfigure_calendso_encryption_key +bootmode_check + +## Start app. +case $BOOTMODE in + basic_start ) + echo "Systems go for basic start." + basic_start + ;; + bootstrap_start ) + echo "Systems go for bootstrap start." + bootstrap_start + ;; + * ) + echo "Invalid BOOTMODE selected. Valid options are basic_start and bootstrap_start." + echo "BOOTMODE selected was instead: $BOOTMODE" + ;; +esac