diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..d5e3ee56c8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +RUN su node -c "npm install --global pnpm@8" \ + && su node -c "SHELL=bash pnpm setup" \ + && su node -c "pnpm config set store-dir /home/node/.local/share/pnpm/store" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..3f89fc0d91 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-postgres +{ + "name": "KlickerUZH Dev Container", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/itsmechlark/features/doppler:2": {} + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or with the host. + // "forwardPorts": [3000, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "pnpm install", + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" + + // see https://github.com/DopplerUniversity/mandalorian-gifs-node/blob/main/.devcontainer/devcontainer.json + // start vscode from the terminal using doppler run -- code . + "containerEnv": { + "DOPPLER_PROJECT": "klicker-uzh", + "DOPPLER_CONFIG": "dev", + "DOPPLER_TOKEN": "${localEnv:DOPPLER_TOKEN}" // Don't hard-code this! + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..4c1c585366 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,63 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:postgres + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + reverse_proxy_docker: + image: docker.io/library/traefik:v2.10 + command: + - --api.insecure=true + - --providers.file=true + - --providers.file.filename=/etc/traefik/rules.yaml + - --providers.file.watch=true + - --entrypoints.web.address=:80 + ports: + - 8088:80 + - 8080:8080 + volumes: + - '../util/traefik/rules_devcontainer.yaml:/etc/traefik/rules.yaml' + + # main database + postgres: + image: docker.io/library/postgres:15 + environment: + POSTGRES_USER: klicker + POSTGRES_PASSWORD: klicker + POSTGRES_DB: klicker + ports: + - 5432:5432 + volumes: + - postgres_data:/var/lib/postgresql/data + + # redis instance to support session execution + redis_exec: + image: docker.io/library/redis:7 + ports: + - 6379:6379 + volumes: + - redis_data:/data + + # redis instance for page caching and rate limiting + redis_cache: + image: docker.io/library/redis:7 + ports: + - 6380:6379 + +volumes: + postgres_data: + redis_data: diff --git a/util/traefik/rules_devcontainer.yaml b/util/traefik/rules_devcontainer.yaml new file mode 100644 index 0000000000..8cc2590013 --- /dev/null +++ b/util/traefik/rules_devcontainer.yaml @@ -0,0 +1,79 @@ +http: + routers: + api: + rule: "Host(`api.klicker.com`)" + entrypoints: + - "web" + service: "api" + + pwa: + rule: "Host(`pwa.klicker.com`)" + entrypoints: + - "web" + service: "pwa" + + manage: + rule: "Host(`manage.klicker.com`)" + entrypoints: + - "web" + service: "manage" + + control: + rule: "Host(`control.klicker.com`)" + entrypoints: + - "web" + service: "control" + + auth: + rule: "Host(`auth.klicker.com`)" + entrypoints: + - "web" + service: "auth" + + func-responses: + rule: "Host(`func-responses.klicker.com`)" + entrypoints: + - "web" + service: "func-responses" + + func-response-processor: + rule: "Host(`func-response-processor.klicker.com`)" + entrypoints: + - "web" + service: "func-response-processor" + + services: + api: + loadBalancer: + servers: + - url: "http://localhost:3000" + + pwa: + loadBalancer: + servers: + - url: "http://localhost:3001" + + manage: + loadBalancer: + servers: + - url: "http://localhost:3002" + + control: + loadBalancer: + servers: + - url: "http://localhost:3003" + + auth: + loadBalancer: + servers: + - url: "http://localhost:3010" + + func-responses: + loadBalancer: + servers: + - url: "http://localhost:7072" + + func-response-processor: + loadBalancer: + servers: + - url: "http://localhost:7073"