Compare commits

..

3 Commits

Author SHA1 Message Date
Alex van Andel
a4cc40c75f Add prisma to build 2021-10-27 19:56:36 +01:00
Alex van Andel
03bb6b7019 Further changes to make Calendso packagable 2021-10-27 00:23:36 +01:00
Alex van Andel
78687b9836 WIP: Full revamp of Dockerfile
This is my go at a new Dockerfile for Cal
2021-10-26 00:37:13 +01:00
11 changed files with 68 additions and 442 deletions

29
.env Normal file
View File

@@ -0,0 +1,29 @@
DATABASE_URL=postgresql://unicorn_user:magical_password@db:5432/calendso
BASE_URL=http://localhost:3000
NEXTAUTH_URL=http://localhost:3000
# Remove this var if you don't want Calendso to collect anonymous usage
NEXT_PUBLIC_TELEMETRY_KEY=js.2pvs2bbpqq1zxna97wcml.oi2jzirnbj1ev4tc57c5r
# 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
# 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=
JWT_SECRET=ChangeMe

View File

@@ -1,48 +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=http://localhost:3000
NEXT_PUBLIC_APP_URL=http://localhost:3000
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={}
# Remove this var if you don't want Calendso to collect anonymous usage
NEXT_PUBLIC_TELEMETRY_KEY=js.2pvs2bbpqq1zxna97wcml.oi2jzirnbj1ev4tc57c5r
# 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
# 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=
# It is highly recommended that the JWT secret must be overridden and very unique
JWT_SECRET=secret
NODE_ENV=production

View File

@@ -1,70 +0,0 @@
# This is a basic workflow to help you get started with Actions
name: Build and push image to DockerHub
# Controls when the workflow will run
on:
push:
branches: [main]
# update on run of Update Calendso nightly submodule update
workflow_run:
workflows: ["Update Calendso"]
branches: [main]
types:
- completed
# Allow running workflow manually from the Actions tab
workflow_dispatch:
# Leaving in example for releases. Initially we simply push to 'latest'
# on:
# release:
# types: [ created ]
# # Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
submodules: true
- name: Docker Login
# You may pin to the exact commit or the version.
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v1.10.0
with:
# Username used to log against the Docker registry
username: ${{ secrets.DOCKER_HUB_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Log out from the Docker registry at the end of a job
logout: true # optional, default is true
- name: Set up Docker builder
id: buildx
uses: docker/setup-buildx-action@v1.6.0
- name: Build and push image
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
# The test image is /docker and is private. final image will be /calendso and public
tags: docker.io/${{ secrets.DOCKER_HUB_USERNAME }}/calendso:latest
build-args: |
BASE_URL=http://localhost:3000
NEXT_PUBLIC_APP_URL=http://localhost:3000
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

4
.gitignore vendored
View File

@@ -1,4 +0,0 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# .env file
.env

View File

@@ -1,40 +1,37 @@
FROM node:14 as deps FROM node:14-alpine AS base
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app WORKDIR /app
COPY calendso/package.json calendso/yarn.lock ./ COPY calendso .
COPY calendso/prisma prisma
RUN yarn install --frozen-lockfile RUN yarn install --frozen-lockfile
FROM node:14 as builder FROM node:14-alpine AS builder
WORKDIR /app WORKDIR /app
ARG BASE_URL COPY --from=base /app/ ./
ARG NEXT_PUBLIC_APP_URL
ARG NEXT_PUBLIC_LICENSE_CONSENT
ARG NEXT_PUBLIC_TELEMETRY_KEY
ENV BASE_URL=$BASE_URL \
NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL \
NEXT_PUBLIC_LICENSE_CONSENT=$NEXT_PUBLIC_LICENSE_CONSENT \
NEXT_PUBLIC_TELEMETRY_KEY=$NEXT_PUBLIC_TELEMETRY_KEY
COPY calendso .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
FROM node:14 as runner FROM node:14-alpine AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV production ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
COPY --from=builder /app/next*.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/scripts ./scripts
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/next-i18next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/package.json ./package.json
COPY scripts scripts
USER nextjs
EXPOSE 3000 EXPOSE 3000
CMD ["/app/scripts/start.sh"]
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
CMD ["yarn", "start"]

View File

@@ -8,22 +8,10 @@
<a href="https://github.com/calendso/calendso-docker/issues">Community Support</a> <a href="https://github.com/calendso/calendso-docker/issues">Community Support</a>
</div> </div>
# Docker # calendso-docker
This image can be found on DockerHub at [https://hub.docker.com/repository/docker/calendso/calendso](https://hub.docker.com/repository/docker/calendso/calendso)
The Docker configuration for Calendso is an effort powered by people within the community. Calendso does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk. The Docker configuration for Calendso is an effort powered by people within the community. Calendso does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk.
## Important Notes
This Docker Image is managed by the Calendso Community. Support for this image can be found via the repository, located at [https://github.com/calendso/docker](https://github.com/calendso/docker)
Currently, this image is intended for local development/evaluation use only, as there are specific requirements for providing environmental variables at build-time in order to specify a non-localhost BASE_URL. (this is due to the nature of the static site compilation, which embeds the variable values). The ability to update these variables at runtime is in-progress and will be available in the future.
For Production, for the time being, please checkout the repository and build/push your own image privately.
## Requirements ## Requirements
Make sure you have `docker` & `docker-compose` installed on the server / system. Make sure you have `docker` & `docker-compose` installed on the server / system.
## Getting Started ## Getting Started
@@ -33,55 +21,25 @@ Make sure you have `docker` & `docker-compose` installed on the server / system.
```bash ```bash
git clone --recursive https://github.com/calendso/docker.git calendso-docker git clone --recursive https://github.com/calendso/docker.git calendso-docker
``` ```
2. Change into the directory 2. Change into the directory
```bash ```bash
cd calendso-docker cd calendso-docker
``` ```
3. Update `.env` if needed
3. Rename `.env.example` to `.env` and update `.env` if needed.
4. Build and start calendso 4. Build and start calendso
```bash ```
docker-compose up --build docker-compose up --build
``` ```
5. Start prisma studio 5. Start prisma studio
```
```bash
docker-compose exec calendso npx prisma studio docker-compose exec calendso npx prisma studio
``` ```
6. Open a browser to [http://localhost:5555](http://localhost:5555) to look at or modify the database content. 6. Open a browser to [http://localhost:5555](http://localhost:5555) to look at or modify the database content.
7. Click on the `User` model to add a new user record. 7. Click on the `User` model to add a new user record.
8. 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.
8. 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) and login with your just created, first user. 9. Open a browser to [http://localhost:3000](http://localhost:3000) and login with your just created, first user.
## Git Submodules
This repository uses a git submodule.
If you cloned the repository without using `--recursive`, then you can initialize and clone the submodule with the following steps.
1. Init the submodule
```bash
git submodule init
```
2. Update the submodule
```bash
git submodule update --remote
```
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.

View File

@@ -1,63 +1,25 @@
# Use postgres/example user/password credentials # Use postgres/example user/password credentials
version: '3.1' version: '3.1'
volumes:
database-data:
networks:
stack:
external: false
services: services:
database: db:
image: postgres image: postgres
restart: always restart: always
volumes: volumes:
- database-data:/var/lib/postgresql/data/ - database-data:/var/lib/postgresql/data/
env_file: .env ports:
networks: - 5432:5432
- stack
calendso: calendso:
build: build:
context: . target: "base"
dockerfile: Dockerfile
args:
- BASE_URL=${BASE_URL}
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
- NEXT_PUBLIC_LICENSE_CONSENT=${NEXT_PUBLIC_LICENSE_CONSENT}
- NEXT_PUBLIC_TELEMETRY_KEY=${NEXT_PUBLIC_TELEMETRY_KEY}
image: calendso/calendso:latest
restart: always restart: always
networks:
- stack
ports: ports:
- 3000:3000 - 3000:3000
env_file: .env
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
- NODE_ENV=development
depends_on:
- database
volumes:
- "./calendso:/app/"
- "./scripts:/app/scripts"
# 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 - 5555:5555
env_file: .env env_file: .env
command: sh -c "npx prisma migrate reset --force && yarn db-seed && yarn dev"
environment: environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB} - NODE_ENV=development
depends_on: depends_on:
- database - db
command: volumes:
- npx database-data:
- prisma
- studio
# END SECTION: Optional use of Prisma Studio.

View File

View File

@@ -1,14 +0,0 @@
#!/bin/bash
set -x
# # Set environment variables
# echo NEXT_PUBLIC_APP_URL $NEXT_PUBLIC_APP_URL
# find \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#$NEXT_PUBLIC_APP_URL#$NEXT_PUBLIC_APP_URL_SUBSTITUTE#g"
/app/scripts/wait-for-it.sh ${DATABASE_HOST} -- echo "database is up"
npx prisma migrate deploy
if [[ $NODE_ENV == "development" ]]; then
yarn dev
else
yarn start
fi

View File

@@ -1,184 +0,0 @@
#!/bin/sh
# The MIT License (MIT)
#
# Copyright (c) 2017 Eficode Oy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
TIMEOUT=15
QUIET=0
# The protocol to make the request with, either "tcp" or "http"
PROTOCOL="tcp"
echoerr() {
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
}
usage() {
exitcode="$1"
cat << USAGE >&2
Usage:
$0 host:port|url [-t timeout] [-- command args]
-q | --quiet Do not output any status messages
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit "$exitcode"
}
wait_for() {
case "$PROTOCOL" in
tcp)
if ! command -v nc >/dev/null; then
echoerr 'nc command is missing!'
exit 1
fi
;;
wget)
if ! command -v wget >/dev/null; then
echoerr 'nc command is missing!'
exit 1
fi
;;
esac
while :; do
case "$PROTOCOL" in
tcp)
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
;;
http)
wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
;;
*)
echoerr "Unknown protocol '$PROTOCOL'"
exit 1
;;
esac
result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 7 ] ; then
for result in $(seq $(($# - 7))); do
result=$1
shift
set -- "$@" "$result"
done
TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
shift 7
exec "$@"
fi
exit 0
fi
if [ "$TIMEOUT" -le 0 ]; then
break
fi
TIMEOUT=$((TIMEOUT - 1))
sleep 1
done
echo "Operation timed out" >&2
exit 1
}
while :; do
case "$1" in
http://*|https://*)
HOST="$1"
PROTOCOL="http"
shift 1
;;
*:* )
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-q-*)
QUIET=0
echoerr "Unknown option: $1"
usage 1
;;
-q*)
QUIET=1
result=$1
shift 1
set -- -"${result#-q}" "$@"
;;
-t | --timeout)
TIMEOUT="$2"
shift 2
;;
-t*)
TIMEOUT="${1#-t}"
shift 1
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
break
;;
--help)
usage 0
;;
-*)
QUIET=0
echoerr "Unknown option: $1"
usage 1
;;
*)
QUIET=0
echoerr "Unknown argument: $1"
usage 1
;;
esac
done
if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
echoerr "Error: invalid timeout '$TIMEOUT'"
usage 3
fi
case "$PROTOCOL" in
tcp)
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
echoerr "Error: you need to provide a host and port to test."
usage 2
fi
;;
http)
if [ "$HOST" = "" ]; then
echoerr "Error: you need to provide a host to test."
usage 2
fi
;;
esac
wait_for "$@"