diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..38eea01a --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,62 @@ +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster +ARG VARIANT=16-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT} + +# [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}" + +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " + +EXPOSE 3000 + +ENV DEBIAN_FRONTEND=noninteractive + +# Add Docker Source +RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Install the packages we need +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get install -qy \ + bash \ + build-essential \ + curl \ + docker-ce-cli \ + jq \ + less \ + git \ + gnupg \ + gnupg2 \ + nano \ + pandoc \ + unzip \ + wget + +# avoid million NPM install messages +ENV npm_config_loglevel warn +# allow installing when the main user is root +ENV npm_config_unsafe_perm true +# disable NPM funding messages +ENV npm_config_fund false + +# Colorize the bash shell +RUN sed -i 's/#force_color_prompt=/force_color_prompt=/' /root/.bashrc + +# Fetch wait-for utility +ADD https://raw.githubusercontent.com/eficode/wait-for/v2.1.3/wait-for /usr/local/bin/ +RUN chmod +rx /usr/local/bin/wait-for + +# Copy the startup file +COPY init.sh /docker-init.sh +RUN sed -i 's/\r$//' /docker-init.sh && \ + chmod +x /docker-init.sh + +# Create workspace +RUN mkdir -p /workspace +WORKDIR /workspace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 997523d6..277f8387 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,33 +1,77 @@ -// How to get remote container development working with VSCode: -// 1. Install "Remote Development" extension pack (ms-vscode-remote.vscode-remote-extensionpack) -// 2. Select "Remote Containers - Reopen in container" - +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/javascript-node-postgres +// Update the VARIANT arg in docker-compose.yml to pick a Node.js version { - "name": "Wiki.js", - "dockerComposeFile": [ - "../dev/containers/docker-compose.yml" - ], - "forwardPorts": [3000, 3001], - "service": "wiki", - "workspaceFolder": "/wiki", - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" + "name": "Wiki.js Dev", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + "shutdownAction": "stopCompose", + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", + "sqltools.connections": [ + // Default connection to dev DB container + { + "name": "Local Dev", + "server": "db", + "port": 5432, + "database": "postgres", + "username": "postgres", + "password": "postgres", + "driver": "PostgreSQL", + "askForPassword": false, + "connectionTimeout": 60 + } + ] + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "dbaeumer.vscode-eslint", + "eamodio.gitlens", + "johnsoncodehk.volar", + "oderwat.indent-rainbow", + "redhat.vscode-yaml", + "visualstudioexptteam.vscodeintellicode", + "editorconfig.editorconfig", + "mrmlnc.vscode-duplicate", + "mtxr.sqltools-driver-pg", + "mutantdino.resourcemonitor", + "wayou.vscode-todo-highlight" + ], + + // 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, 8000], + + "portsAttributes": { + "3000": { + "label": "Wiki.js", + "onAutoForward": "notify" + }, + "5432": { + "label": "PostgreSQL", + "onAutoForward": "silent" + }, + "8000": { + "label": "PGAdmin", + "onAutoForward": "silent" + } }, - "extensions": [ - "EditorConfig.editorconfig", - "dbaeumer.vscode-eslint", - "christian-kohler.path-intellisense", - "mrmlnc.vscode-puglint", - "octref.vetur", - "dzannotti.vscode-babel-coloring", - "wayou.vscode-todo-highlight", - "visualstudioexptteam.vscodeintellicode", - "lukas-tr.materialdesignicons-intellisense", - "codezombiech.gitignore", - "kumar-harsh.graphql-for-vscode", - "mrmlnc.vscode-duplicate", - "oderwat.indent-rainbow", - "christian-kohler.npm-intellisense" -], - "postCreateCommand": ["yarn", "install"] + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "/docker-init.sh", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "node", + "features": { + "common": { + "installZsh": true, + "installOhMyZsh": true, + "upgradePackages": true + }, + "github-cli": "latest" + } } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..e507e722 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,54 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + args: + # Update 'VARIANT' to pick an LTS version of Node.js: 16, 14, 12. + # Append -bullseye or -buster to pin to an OS version. + # Use -bullseye variants on local arm64/Apple Silicon. + VARIANT: 16-bullseye + + volumes: + - ..:/workspace:cached + - wiki-vscode-ext:/root/.vscode-server/extensions + + # 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:db + + # Uncomment the next line to use a non-root user for all processes. + # user: node + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + POSTGRES_DB: postgres + + pgadmin: + image: dpage/pgadmin4:latest + environment: + - PGADMIN_DEFAULT_EMAIL=dev@js.wiki + - PGADMIN_DEFAULT_PASSWORD=123123 + - PGADMIN_DISABLE_POSTFIX=True + - PGADMIN_LISTEN_PORT=8000 + - PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED=False + network_mode: service:db + volumes: + - ./pgadmin-servers.json:/pgadmin4/servers.json + +volumes: + postgres-data: + wiki-vscode-ext: diff --git a/.devcontainer/init.sh b/.devcontainer/init.sh new file mode 100644 index 00000000..dc61d525 --- /dev/null +++ b/.devcontainer/init.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd /workspace + +git config codespaces-theme.hide-status 1 +git config oh-my-zsh.hide-info 1 + +echo "Ready!" diff --git a/.devcontainer/pgadmin-servers.json b/.devcontainer/pgadmin-servers.json new file mode 100644 index 00000000..e0658406 --- /dev/null +++ b/.devcontainer/pgadmin-servers.json @@ -0,0 +1,13 @@ +{ + "Servers": { + "1": { + "Name": "Dev", + "Group": "Servers", + "Port": 5432, + "Username": "postgres", + "Host": "db", + "SSLMode": "prefer", + "MaintenanceDB": "postgres" + } + } +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index adb5f8c6..2144bfac 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,8 +2,6 @@ "recommendations": [ "EditorConfig.editorconfig", "dbaeumer.vscode-eslint", - "christian-kohler.path-intellisense", "mrmlnc.vscode-puglint", - "octref.vetur" ] } diff --git a/dev/containers/docker-compose.yml b/dev/containers/docker-compose.yml index f5b3ac81..0175c845 100644 --- a/dev/containers/docker-compose.yml +++ b/dev/containers/docker-compose.yml @@ -1,59 +1,44 @@ # -- DEV DOCKER-COMPOSE -- # -- DO NOT USE IN PRODUCTION! -- -version: "3" +version: "3.8" services: db: - container_name: wiki-db - image: postgres:9-alpine + image: postgres:11-alpine environment: POSTGRES_DB: wiki POSTGRES_PASSWORD: wikijsrocks POSTGRES_USER: wikijs logging: driver: "none" + restart: unless-stopped volumes: - db-data:/var/lib/postgresql/data - ports: - - "15432:5432" - adminer: - container_name: wiki-adminer - image: adminer:latest + pgadmin: + image: dpage/pgadmin4:latest + environment: + PGADMIN_DEFAULT_EMAIL: dev@js.wiki + PGADMIN_DEFAULT_PASSWORD: "123123" + PGADMIN_DISABLE_POSTFIX: true + PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: False + network_mode: service:db logging: driver: "none" - ports: - - "3001:8080" - - # solr: - # container_name: wiki-solr - # image: solr:7-alpine - # logging: - # driver: "none" - # ports: - # - "8983:8983" - # volumes: - # - solr-data:/opt/solr/server/solr/mycores - # entrypoint: - # - docker-entrypoint.sh - # - solr-precreate - # - wiki wiki: - container_name: wiki-app build: context: ../.. dockerfile: dev/containers/Dockerfile + command: sleep infinity depends_on: - db - ports: - - "3000:3000" volumes: - - ../..:/wiki - - /wiki/node_modules - - /wiki/.git + - ../..:/workspace + network_mode: service:db + ipc: host + init: true volumes: db-data: - # solr-data: