diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..04af81a --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/devcontainers/base:ubuntu + +ENV PNPM_HOME="/usr/local/share/pnpm" +ENV PATH="$PNPM_HOME:$PATH" + +RUN export DEBIAN_FRONTEND=noninteractive && \ + rm -f /bin/sh && \ + ln -s /bin/bash /bin/sh && \ + apt update && \ + apt upgrade -y && \ + apt install -y software-properties-common && \ + add-apt-repository -y ppa:git-core/ppa && \ + apt update && \ + apt install -y git bash-completion htop jq lsof less curl zip unzip tree python3 build-essential && \ + apt autoremove -y && \ + rm -f /usr/bin/python && \ + ln -s /usr/bin/python3 /usr/bin/python + +RUN curl -fsSL https://get.pnpm.io/install.sh | sh - && \ + pnpm env use -g lts && \ + sudo rm -rf /tmp/* && \ + sudo chmod -R 777 /usr/local/share/pnpm + +RUN pnpm i -g pnpm taze tsx prisma diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5acde6f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,15 @@ +{ + "name": "unicourse-workspace", + "dockerComposeFile": "docker-compose.yml", + "service": "workspace", + "workspaceFolder": "/workspace", + "settings": {}, + "extensions": [ + "dbaeumer.vscode-eslint", + "GitHub.copilot", + "GitHub.copilot-labs" + ], + "onCreateCommand": "pnpm config -g set store-dir /workspace/node_modules/.pnpm-store", + "postCreateCommand": "pnpm i && pnpm build:all", + "postStartCommand": "pnpm i" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..5afb93c --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,41 @@ +version: "3.9" +name: unicourse-workspace + +services: + db: + image: postgres:15-alpine + container_name: unicourse-backend-db + restart: unless-stopped + env_file: + - ../.env + expose: + - 5432:5432 + volumes: + - postgres-data:/var/lib/postgresql/data + + adminer: + image: adminer:4-standalone + container_name: unicourse-backend-adminer + restart: unless-stopped + env_file: + - ../.env + ports: + - ${ADMINER_PORT}:8080 + depends_on: + - db + + workspace: + build: + context: . + dockerfile: Dockerfile + env_file: + - ../.env + volumes: + - ..:/workspace + depends_on: + - db + - adminer + command: sleep infinity + +volumes: + postgres-data: {} diff --git a/.env.example b/.env.example index 1405cae..b699860 100644 --- a/.env.example +++ b/.env.example @@ -10,3 +10,6 @@ DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTG UNICORSE_ROOT_USER=unicourse UNICORSE_ROOT_PASSWORD=unicourse + +SMTP_USER= +SMTP_PASS= diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 18175e3..5b26722 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,65 +21,11 @@ If you need to any help from maintainers and the community, you can join our [Di ## Setting Up the Environment -Please make sure you have installed [`Docker`](https://docs.docker.com/get-docker/) on your machine. - -We will create a docker container as the development environment: - -```sh -┌───────────────────────────────────┐ -│ │ -│ Your Machine (Host) │ -│ │ -│ `docker compose exec dev bash` │ -│ ↓ │ -│ ┌───┤ ├────────────────┐ │ -│ │ │ │ -│ │ Container (Dev Env) │ │ -│ │ │ │ -│ └──────────────────────┘ │ -│ │ -└───────────────────────────────────┘ -``` - -In the Dev Env, all the tools you need are already installed, such as `pnpm`, `prisma`, `tsx`, `unicourse`, etc. - -### First Time Setup - -Clone the repository: - -```sh -# at Host -git clone https://github.com/UniCourse-TW/Backend.git -cd Backend -``` - -Run Setup Script: +Before you start, you should copy the `.env.example` file to `.env` and fill in the environment variables. -```sh -# at Host -./scripts/fast-setup.sh -``` - -> This should take a few minutes and only needs to be done once. -> After the script finishes, you will be inside the Dev Env. - -### Start the Development Environment - -You may need to start the Dev Env if you have exited it: - -```sh -# at Host -docker compose up -d dev -``` - -### Enter the Development Environment - -Please ensure that you have started the Dev Env. +Please make sure you have installed [`Docker`](https://docs.docker.com/get-docker/) on your machine. -```sh -# at Host -docker compose exec dev bash -``` +We use **devcontainer** to provide a consistent development environment. You can use **VSCode** to open this repository and it will automatically build the devcontainer for you. (You should see a popup in the bottom right corner of your VSCode window.) ## Coding Style diff --git a/package.json b/package.json index 78b73bf..cb8b4b0 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@koa/router": "^12.0.0", "@prisma/client": "^4.5.0", "@unicourse-tw/arborist": "workspace:*", + "@unicourse-tw/cli": "workspace:*", "@unicourse-tw/course-search": "workspace:*", "@unicourse-tw/prisma": "workspace:*", "@unicourse-tw/token": "workspace:*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a616e79..eb6cfbc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,7 @@ importers: '@typescript-eslint/eslint-plugin': ^5.42.0 '@typescript-eslint/parser': ^5.42.0 '@unicourse-tw/arborist': workspace:* + '@unicourse-tw/cli': workspace:* '@unicourse-tw/course-search': workspace:* '@unicourse-tw/notify': workspace:* '@unicourse-tw/prisma': workspace:* @@ -47,6 +48,7 @@ importers: '@koa/router': 12.0.0 '@prisma/client': 4.5.0_prisma@4.5.0 '@unicourse-tw/arborist': link:packages/arborist + '@unicourse-tw/cli': link:packages/cli '@unicourse-tw/course-search': link:packages/search '@unicourse-tw/notify': link:packages/notify '@unicourse-tw/prisma': link:packages/prisma