diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d8b7643d..b44145a2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,7 @@ { "name": "Zeppelin Development", - "dockerComposeFile": "../docker/development/docker-compose.yml", - "runArgs": ["--env-file", "../.env"], + "dockerComposeFile": "../docker-compose.yml", "service": "devenv", "remoteUser": "ubuntu", diff --git a/.env.example b/.env.example index 88f8f5b5..d98f2662 100644 --- a/.env.example +++ b/.env.example @@ -34,6 +34,9 @@ DOCKER_DEV_MYSQL_ROOT_PASSWORD= DOCKER_DEV_SSH_PORT=3002 DOCKER_DEV_SSH_PASSWORD=password +# If your user has a different UID than 1000, you might have to fill that in here to avoid permission issues +#DOCKER_DEV_UID=1000 + # # PRODUCTION # diff --git a/docker/development/README.md b/DEVELOPMENT.md similarity index 91% rename from docker/development/README.md rename to DEVELOPMENT.md index 5ffc3a0e..0edbbc88 100644 --- a/docker/development/README.md +++ b/DEVELOPMENT.md @@ -2,6 +2,8 @@ Zeppelin's development environment runs entirely within a Docker container. Below you can find instructions for setting up the environment and getting started with development! +👉 **No support is offered for self-hosting the bot!** 👈 + ## Starting the development environment ### Using VSCode devcontainers @@ -15,7 +17,7 @@ Below you can find instructions for setting up the environment and getting start 1. Install Docker 2. Make a copy of `.env.example` called `.env` 3. Fill in the missing values in `.env` -4. Run `./docker-compose-dev.sh up` to start the development environment +4. Run `docker-compose up` to start the development environment 5. In VSCode: Install the `Remote - SSH` plugin 6. In VSCode: Run `Remote-SSH: Connect to Host...` * As the address, use `ubuntu@127.0.0.1:3002` (where `3002` matches `DOCKER_DEV_SSH_PORT` in `.env`) @@ -26,7 +28,7 @@ Below you can find instructions for setting up the environment and getting start 1. Install Docker 2. Make a copy of `.env.example` called `.env` 3. Fill in the missing values in `.env` -4. Run `./docker-compose-dev.sh up` to start the development environment +4. Run `docker-compose up` to start the development environment 5. Choose `Connect via SSH` and create a new connection: * Username: `ubuntu` * Host: `127.0.0.1` @@ -41,7 +43,7 @@ Below you can find instructions for setting up the environment and getting start 1. Install Docker 2. Make a copy of `.env.example` called `.env` 3. Fill in the missing values in `.env` -4. Run `./docker-compose-dev.sh up` to start the development environment +4. Run `docker-compose up` to start the development environment 5. Use the following credentials for connecting with your IDE: * Host: `127.0.0.1` * Port: `3002` (matching the `DOCKER_DEV_SSH_PORT` value in `.env`) diff --git a/README.md b/README.md index 02eae9ee..4d11bbe5 100644 --- a/README.md +++ b/README.md @@ -20,46 +20,9 @@ Zeppelin is a moderation bot for Discord, designed with large servers and reliab See https://zeppelin.gg/ for more details. ## Development -These instructions are intended for bot development only. - 👉 **No support is offered for self-hosting the bot!** 👈 -### Running the bot -1. `cd backend` -2. `npm ci` -3. Make a copy of `bot.env.example` called `bot.env`, fill in the values -4. Run the desired start script: - * `npm run build` followed by `npm run start-bot-dev` to run the bot in a **development** environment - * `npm run build` followed by `npm run start-bot-prod` to run the bot in a **production** environment - * `npm run watch` to watch files and run the **bot and api both** in a **development** environment - with automatic restart on file changes -5. When testing, make sure you have your test server in the `allowed_guilds` table or the guild's config won't be loaded at all - -### Running the API server -1. `cd backend` -2. `npm ci` -3. Make a copy of `api.env.example` called `api.env`, fill in the values -4. Run the desired start script: - * `npm run build` followed by `npm run start-api-dev` to run the api in a **development** environment - * `npm run build` followed by `npm run start-api-prod` to run the api in a **production** environment - * `npm run watch` to watch files and run the **bot and api both** in a **development** environment - with automatic restart on file changes - -### Running the dashboard -1. `cd dashboard` -2. `npm ci` -3. Make a copy of `.env.example` called `.env`, fill in the values -4. Run the desired start script: - * `npm run build` compiles the dashboard's static files to `dist/` which can then be served with any web server - * `npm run watch` runs webpack's dev server that automatically reloads on changes - -### Notes -* Since we now use shared paths in `tsconfig.json`, the compiled files in `backend/dist/` have longer paths, e.g. - `backend/dist/backend/src/index.js` instead of `backend/dist/index.js`. This is because the compiled shared files - are placed in `backend/dist/shared`. -* The `backend/register-tsconfig-paths.js` module takes care of registering shared paths from `tsconfig.json` for - `ava` and compiled `.js` files -* To run the tests for the files in the `shared/` directory, you also need to run `npm ci` there +See [DEVELOPMENT.md](./DEVELOPMENT.md) for instructions on running the development environment! ### Config format example Configuration is stored in the database in the `configs` table diff --git a/docker-compose-dev.sh b/docker-compose-dev.sh deleted file mode 100755 index cd039f74..00000000 --- a/docker-compose-dev.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -DOCKER_UID="$(id -u)" DOCKER_STAY_RUNNING=1 docker-compose --env-file ./.env -f ./docker/development/docker-compose.yml "$@" diff --git a/docker/development/docker-compose.yml b/docker-compose.yml similarity index 85% rename from docker/development/docker-compose.yml rename to docker-compose.yml index 7fcdd28a..1c836bd2 100644 --- a/docker/development/docker-compose.yml +++ b/docker-compose.yml @@ -7,14 +7,14 @@ volumes: services: nginx: build: - context: ./nginx + context: ./docker/development/nginx args: DOCKER_DEV_WEB_PORT: ${DOCKER_DEV_WEB_PORT:?Missing DOCKER_DEV_WEB_PORT} API_PORT: ${API_PORT:?Missing API_PORT} ports: - "${DOCKER_DEV_WEB_PORT:?Missing DOCKER_DEV_WEB_PORT}:443" volumes: - - ../../:/zeppelin + - ./:/zeppelin mysql: image: mysql:8.0 @@ -31,15 +31,14 @@ services: devenv: build: - context: ./devenv + context: ./docker/development/devenv args: DOCKER_DEV_SSH_PASSWORD: ${DOCKER_DEV_SSH_PASSWORD:?Missing DOCKER_DEV_SSH_PASSWORD} - DOCKER_UID: ${DOCKER_UID:?Missing DOCKER_UID} - DOCKER_STAY_RUNNING: ${DOCKER_STAY_RUNNING} + DOCKER_DEV_UID: ${DOCKER_DEV_UID:-1000} ports: - "${DOCKER_DEV_SSH_PORT:?Missing DOCKER_DEV_SSH_PORT}:22" volumes: - - ../../:/home/ubuntu/zeppelin + - ./:/home/ubuntu/zeppelin - ~/.ssh:/home/ubuntu/.ssh - vscode-remote:/home/ubuntu/.vscode-remote - vscode-server:/home/ubuntu/.vscode-server diff --git a/docker/development/devenv/Dockerfile b/docker/development/devenv/Dockerfile index 30963fee..3b9d6276 100644 --- a/docker/development/devenv/Dockerfile +++ b/docker/development/devenv/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:20.04 -ARG DOCKER_UID=1000 +ARG DOCKER_DEV_UID ARG DOCKER_DEV_SSH_PASSWORD ENV DEBIAN_FRONTEND=noninteractive @@ -13,7 +13,7 @@ RUN apt-get install -y sudo git curl # Set up SSH access RUN apt-get install -y openssh-server iptables RUN mkdir /var/run/sshd -RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u $DOCKER_UID ubuntu +RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u $DOCKER_DEV_UID ubuntu RUN echo "ubuntu:${DOCKER_DEV_SSH_PASSWORD}" | chpasswd # Set up proper permissions for volumes