diff --git a/Service%EF%BC%9ACoder.md b/Service%EF%BC%9ACoder.md index 5aa0111..1b5db96 100644 --- a/Service%EF%BC%9ACoder.md +++ b/Service%EF%BC%9ACoder.md @@ -1,56 +1,62 @@ -# 簡介 - -Coder 是自架的雲端開發環境平台,可在伺服器上建立並管理遠端開發工作區。本文記錄在 Ubuntu 上安裝 Coder,並使用 PostgreSQL 作為資料庫的步驟。 - -# 安裝 Coder - -透過官方安裝腳本安裝。 - -```bash -curl -L https://coder.com/install.sh | sh -``` - -# 修改 Coder 綁定的位址 - -預設僅綁定本機,改為 `0.0.0.0:3000` 以開放外部連線。 - -```bash -echo 'export CODER_HTTP_ADDRESS=0.0.0.0:3000' >> ~/.bashrc && source ~/.bashrc -``` - -# 啟動服務 - -設為開機自動啟動並立即啟動服務。 - -```bash -systemctl enable --now coder -``` - -# 設定資料庫 - -以 postgres 系統帳號進入 PostgreSQL 互動介面。 - -```bash -sudo -u postgres psql -``` - -新建專屬使用者與資料庫。 - -```sql -CREATE USER coder WITH PASSWORD 'coder'; - -CREATE DATABASE coder; -``` - -設定資料庫權限(Postgres 15 以後,schema 權限需另外授予,否則應用程式無法建立資料表)。 - -```sql --- 1. Give ownership of the database to the app user -ALTER DATABASE coder OWNER TO coder; - --- 2. Give ownership of the public schema to the app user -ALTER SCHEMA public OWNER TO coder; - --- 3. Ensure the user has create permissions (Crucial for Postgres 15+) -GRANT USAGE, CREATE ON SCHEMA public TO coder; -``` +# 簡介 + +Coder 是自架的雲端開發環境平台,可在伺服器上建立並管理遠端開發工作區。本文記錄在 Ubuntu 上安裝 Coder,並使用 PostgreSQL 作為資料庫的步驟。 + +# 安裝 Coder + +透過官方安裝腳本安裝。 + +```bash +curl -L https://coder.com/install.sh | sh +``` + +# 修改 Coder 綁定的位址 + +預設僅綁定本機,改為 `0.0.0.0:3000` 以開放外部連線。 + +```bash +echo 'export CODER_HTTP_ADDRESS=0.0.0.0:3000' >> ~/.bashrc && source ~/.bashrc +``` + +# 設定 Coder 服務檔 + +```bash +systemctl edit coder +``` + +# 啟動服務 + +設為開機自動啟動並立即啟動服務。 + +```bash +systemctl enable --now coder +``` + +# 設定資料庫 + +以 postgres 系統帳號進入 PostgreSQL 互動介面。 + +```bash +sudo -u postgres psql +``` + +新建專屬使用者與資料庫。 + +```sql +CREATE USER coder WITH PASSWORD 'coder'; + +CREATE DATABASE coder; +``` + +設定資料庫權限(Postgres 15 以後,schema 權限需另外授予,否則應用程式無法建立資料表)。 + +```sql +-- 1. Give ownership of the database to the app user +ALTER DATABASE coder OWNER TO coder; + +-- 2. Give ownership of the public schema to the app user +ALTER SCHEMA public OWNER TO coder; + +-- 3. Ensure the user has create permissions (Crucial for Postgres 15+) +GRANT USAGE, CREATE ON SCHEMA public TO coder; +```