Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
41 changes: 41 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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: {}
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTG

UNICORSE_ROOT_USER=unicourse
UNICORSE_ROOT_PASSWORD=unicourse

SMTP_USER=<your smtp user>
SMTP_PASS=<your smtp password>
60 changes: 3 additions & 57 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.