Skip to content

Commit

Permalink
Merge pull request #415 from chhsiao1981/docker-2
Browse files Browse the repository at this point in the history
refine docker settings
  • Loading branch information
chhsiao1981 authored Oct 17, 2024
2 parents 8ad8159 + f55c5e6 commit 5100ad8
Show file tree
Hide file tree
Showing 31 changed files with 690 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: ^1.19
go-version: ^1.22

- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ issues:
- '`setBBottom` is unused'
- '`pwcuSetByBit` is unused'
- 'unused-parameter: parameter'
- G115
exclude-rules:
exclude-use-default: true
30 changes: 15 additions & 15 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

This project intends to be the go implementation of [ptt/pttbbs](https://github.com/ptt/pttbbs).

Collaborating with [Ptt-official-app middleware](https://github.com/ptt-official-app/go-openbbsmiddleware), go-pttbbs intends to be web-based bbs.
Collaborating with [Ptt-official-app go-pttbbsweb](https://github.com/ptt-official-app/go-pttbbsweb), go-pttbbs intends to be web-based bbs.

## Getting Started

You can start with the [swagger api](https://api.devptt.dev:8080)
You can start with the [swagger api](https://doc-pttbbs.devptt.dev)
and check the api document.

## Coding Convention
Expand All @@ -29,10 +29,10 @@ and check the api document.
You can do the following to start with docker-compose:

* copy `docs/etc/` to some etc directory (ex: `/etc/go-pttbbs`).
* copy `01-config.docker.ini` to the etc directory as production.ini (ex: `cp 01-config.docker.ini /etc/go-pttbbs/production.ini`).
* copy `docker_compose.env.template` to `docker_compose.env` and modify the settings.
* copy `docs/config/01-config.docker.ini` to the etc directory as production.ini (ex: `cp docs/config/01-config.docker.ini /etc/go-pttbbs/production.ini`).
* copy `docker/go-pttbbs/docker_compose.env.template` to `docker/go-pttbbs/docker_compose.env` and modify the settings.
* `./scripts/docker_initbbs.sh [BBSHOME] pttofficialapps/go-pttbbs:latest`
* `docker-compose --env-file docker_compose.env -f docker-compose.yaml up -d`
* `docker-compose --env-file docker/go-pttbbs/docker_compose.env -f docker/go-pttbbs/docker-compose.yaml up -d`
* register SYSOP and guest (api.GUEST) at `http://localhost:3456/v1/register`
* register your account at `http://localhost:3456/register`
* login at `http://localhost:3456/v1/login`
Expand Down Expand Up @@ -69,9 +69,9 @@ You can do the following to increase users using docker:
You can do the following to run with ./scripts/run.sh:

* Mac:
Copy `memory.plist` to `/Library/LaunchDaemons` then reboot
Copy `docs/mac/memory.plist` to `/Library/LaunchDaemons` then reboot
```sh
sudo cp memory.plist /Library/LaunchDaemons/memory.plist
sudo cp docs/mac/memory.plist /Library/LaunchDaemons/memory.plist
```

* Check that we do have 16M shared-mem
Expand All @@ -82,9 +82,9 @@ You can do the following to run with ./scripts/run.sh:
```
./scripts/docker_initbbs.sh [BBSHOME] pttofficialapps/go-pttbbs:latest
```
* `cp 02-config-run.go.template ptttype/02-config-run.go`
* `cp 02-config.run.template.ini 02-config.run.ini`
* Setup BBSHOME in 02-config.run.ini
* `cp docs/config/02-config-run.go.template ptttype/02-config-run.go`
* `cp docs/config/02-config.run.template.ini docs/config/02-config.run.ini`
* Setup BBSHOME in docs/config/02-config.run.ini
* Do the following step ONLY IF you want to reset shared-mem:
`ipcrm -M 0x000004cc`
`ipcrm -S 0x000007da`
Expand Down Expand Up @@ -124,11 +124,11 @@ For the normal config-variables, we use config.ini
as the configuration.

For the const config-variables in ptttype,
We use 00-config-[dev-mode].go with +build flag
We use docs/config/00-config-[dev-mode].go with +build flag

### 00-config.ini
### docs/config/00-config.ini
We use viper and .ini as our config-framework.
00-config.template.ini is the config-template file.
docs/config/00-config.template.ini is the config-template file.

We have 3 files For every module with the config:

Expand All @@ -140,7 +140,7 @@ We have 3 files For every module with the config:

We can customized ptttype/00-config-default.go with the following steps:

1. Copy 00-config-production.go.template to ptttype/00-config-production.go and change the +build and variables accordingly.
1. Copy docs/config/00-config-production.go.template to ptttype/00-config-production.go and change the +build and variables accordingly.
2. `go build -tag [dev-mode]`

## Swagger.sh
Expand All @@ -150,6 +150,6 @@ which is a python-project.
You can do following for the swagger-api:

1. setup the python virtualenv.
2. cd apidoc; pip install . && pip uninstall apidoc -y && python setup.py develop; cd ..
2. cd apidoc; pip install -e . ; cd ..
3. ./scripts/swagger.sh
4. browse to [http://localhost:8080](http://localhost:8080).
33 changes: 16 additions & 17 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

這是使用 go 實作的 [ptt/pttbbs](https://github.com/ptt/pttbbs)

[Ptt-official-app middleware](https://github.com/ptt-official-app/go-openbbsmiddleware) 一起成為 web-based BBS.
[Ptt-official-app go-pttbbsweb](https://github.com/ptt-official-app/go-pttbbsweb) 一起成為 web-based BBS.

## 開始

您可以從 [swagger api](https://api.devptt.dev:8080) 查看 api 文件.
您可以從 [swagger api](https://doc-pttbbs.devptt.dev) 查看 api 文件.

## Coding Convention

Expand All @@ -28,10 +28,10 @@
您可以利用 docker-compose 開始:

*`docs/etc/` 複製到另一個 etc 目錄 (例: `/etc/go-pttbbs`).
*`01-config.docker.ini` 複製到 etc 目錄為 production.ini (例: `cp 01-config.docker.ini /etc/go-pttbbs/production.ini`).
*`docker_compose.env.template` 複製到 `docker_compose.env` 並且更改相關設定.
*`docs/config/01-config.docker.ini` 複製到 etc 目錄為 production.ini (例: `cp docs/config/01-config.docker.ini /etc/go-pttbbs/production.ini`).
*`docker/go-pttbbs/docker_compose.env.template` 複製到 `docker/go-pttbbs/docker_compose.env` 並且更改相關設定.
* `./scripts/docker_initbbs.sh [BBSHOME] pttofficialapps/go-pttbbs:latest`
* `docker-compose --env-file docker_compose.env -f docker-compose.yaml up -d`
* `docker-compose --env-file docker/go-pttbbs/docker_compose.env -f docker/go-pttbbs/docker-compose.yaml up -d`
* 使用 `http://localhost:3456/v1/register` 註冊 SYSOP 和 guest (api.GUEST).
* 使用 `http://localhost:3456/register` 註冊您的帳號.
* 使用 `http://localhost:3456/v1/login` 登入.
Expand Down Expand Up @@ -68,9 +68,9 @@
您可以使用以下方式執行 ./scripts/run.sh

* Mac:
`memory.plist` 複製到 `/Library/LaunchDaemons` 然後重新啟動 Mac.
`docs/mac/memory.plist` 複製到 `/Library/LaunchDaemons` 然後重新啟動 Mac.
```sh
sudo cp memory.plist /Library/LaunchDaemons/memory.plist
sudo cp docs/mac/memory.plist /Library/LaunchDaemons/memory.plist
```

* 確認我們真的有 16M shared-mem
Expand All @@ -80,10 +80,9 @@
* 起始您的 BBSHOME:
```
./scripts/docker_initbbs.sh [BBSHOME] pttofficialapps/go-pttbbs:latest
```
* `cp 02-config-run.go.template ptttype/02-config-run.go`
* `cp 02-config.run.template.ini 02-config.run.ini`
* 在 02-config.run.ini 裡設定 BBSHOME.

* `cp docs/config/02-config.run.template.ini docs/config/02-config.run.ini`
* 在 docs/config/02-config.run.ini 裡設定 BBSHOME.
* "只有如果" 您想要重新設定 shared-mem, 您可以使用以下方式:
`ipcrm -M 0x000004cc`
`ipcrm -S 0x000007da`
Expand Down Expand Up @@ -119,24 +118,24 @@

對於一般的 config-variables, 我們在 config.ini 裡設定.

對於 ptttype 裡常數的 config-variables, 我們使用 00-config-[dev-mode].go 和 +build flag.
對於 ptttype 裡常數的 config-variables, 我們使用 docs/config/00-config-[dev-mode].go 和 +build flag.

### 00-config.ini
### docs/config/00-config.ini

我們使用 viper 和 .ini 作為我們的 config-framework.
00-config.template.ini 是 config-template file.
docs/config/00-config.template.ini 是 config-template file.

對於每個 module, 我們有以下 3 個 source files 來完成 config:

1. 00-config.go: 定義 config 的 variables.
2. config.go: 定義設定 variables 的 func.
3. config_util.go: 輔助 functions.

### 00-config-\[dev-mode\].go
### docs/config/00-config-\[dev-mode\].go

我們可以使用以下方式更改 ptttype/00-config-default.go:

1. 複製 00-config-production.go.template 到 ptttype/00-config-[dev-mode].go 並且更改 +build 和 variables.
1. 複製 docs/config/00-config-production.go.template 到 ptttype/00-config-[dev-mode].go 並且更改 +build 和 variables.
2. `go build -tag [dev-mode]`

## Swagger.sh
Expand All @@ -147,6 +146,6 @@
您可以使用以下方式設定 swagger-api:

1. 設定 python virtualenv.
2. cd apidoc; pip install . && pip uninstall apidoc -y && python setup.py develop; cd ..
2. cd apidoc; pip install -e . ; cd ..
3. ./scripts/swagger.sh
4. 使用 browser 觀看 [http://localhost:8080](http://localhost:8080).
2 changes: 1 addition & 1 deletion api/get_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GetUser(remoteAddr string, uuserID bbs.UUserID, params interface{}, path in
return nil, ErrInvalidUser
}

user, err := bbs.GetUser(uuserID)
user, err := bbs.GetUser(thePath.UserID)
if err != nil {
return nil, err
}
Expand Down
18 changes: 9 additions & 9 deletions api/testcases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{0xaf, 0xab}, // 神
PasswdHash: ptttype.Passwd_t{0x62, 0x68, 0x77, 0x76, 0x4f, 0x4a, 0x74, 0x66, 0x54, 0x31, 0x54, 0x41, 0x49, 0x00},

UFlag: 33557088,
UserLevel: 7 | ptttype.PERM_BOARD | ptttype.PERM_POST | ptttype.PERM_LOGINOK,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_DEFAULT | ptttype.PERM_BOARD | ptttype.PERM_POST | ptttype.PERM_LOGINOK,
NumLoginDays: 2,
NumPosts: 0,
FirstLogin: 1600681288,
Expand All @@ -81,14 +81,14 @@ func initTestVars() {
}

testNewPostUserRaw1 = &ptttype.UserecRaw{
Version: 4194,
Version: ptttype.PASSWD_VERSION,
UserID: ptttype.UserID_t{65, 49}, // A1
RealName: ptttype.RealName_t{67, 111, 100, 105, 110, 103, 77, 97, 110},
Nickname: ptttype.Nickname_t{175, 171},
PasswdHash: ptttype.Passwd_t{98, 104, 119, 118, 79, 74, 116, 102, 84, 49, 84, 65, 73, 0},

UFlag: 33557088,
UserLevel: 7 | ptttype.PERM_LOGINOK | ptttype.PERM_POST,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_DEFAULT | ptttype.PERM_LOGINOK | ptttype.PERM_POST,
NumLoginDays: 2,
NumPosts: 0,
FirstLogin: 1600681288,
Expand All @@ -110,8 +110,8 @@ func initTestVars() {
},
Nickname: []byte{0xaf, 0xab}, // 神

Uflag: 33557088,
Userlevel: 536871943,
Uflag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
Userlevel: ptttype.PERM_DEFAULT | ptttype.PERM_SYSSUBOP | ptttype.PERM_BM,
Numlogindays: 2,
Numposts: 0,
Firstlogin: 1600681288,
Expand Down Expand Up @@ -373,7 +373,7 @@ func initTestVars() {
BM: []bbs.UUserID{},
IdxByName: "1...........",
IdxByClass: "Li4uLg@1...........",
BrdAttr: 0x000008,
BrdAttr: ptttype.BRD_GROUPBOARD,
}

testClassDetail2 = &bbs.BoardDetail{
Expand Down Expand Up @@ -415,7 +415,7 @@ func initTestVars() {
BM: []bbs.UUserID{},
IdxByName: "2...........",
IdxByClass: "Li4uLg@2...........",
BrdAttr: 0x000008,
BrdAttr: ptttype.BRD_GROUPBOARD,
}

testClassDetail5 = &bbs.BoardDetail{
Expand Down
34 changes: 17 additions & 17 deletions bbs/testcases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{0xaf, 0xab}, // 神
PasswdHash: ptttype.Passwd_t{0x62, 0x68, 0x77, 0x76, 0x4f, 0x4a, 0x74, 0x66, 0x54, 0x31, 0x54, 0x41, 0x49, 0x00},

UFlag: 33557088,
UserLevel: 536871943,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_DEFAULT | ptttype.PERM_SYSSUBOP | ptttype.PERM_BM,
NumLoginDays: 2,
NumPosts: 0,
FirstLogin: 1600681288,
Expand Down Expand Up @@ -107,8 +107,8 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{0xaf, 0xab}, // 神
PasswdHash: ptttype.Passwd_t{0x62, 0x68, 0x77, 0x76, 0x4f, 0x4a, 0x74, 0x66, 0x54, 0x31, 0x54, 0x41, 0x49, 0x00},

UFlag: 33557088,
UserLevel: 7 | ptttype.PERM_BOARD | ptttype.PERM_POST | ptttype.PERM_LOGINOK,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_DEFAULT | ptttype.PERM_BOARD | ptttype.PERM_POST | ptttype.PERM_LOGINOK,
NumLoginDays: 2,
NumPosts: 0,
FirstLogin: 1600681288,
Expand Down Expand Up @@ -137,7 +137,7 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{0xaf, 0xab}, // 神
PasswdHash: ptttype.Passwd_t{0x62, 0x68, 0x77, 0x76, 0x4f, 0x4a, 0x74, 0x66, 0x54, 0x31, 0x54, 0x41, 0x49, 0x00},

UFlag: 33557088,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_SYSOP,
NumLoginDays: 2,
NumPosts: 0,
Expand Down Expand Up @@ -167,8 +167,8 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{0xaf, 0xab}, // 神
PasswdHash: ptttype.Passwd_t{0x62, 0x68, 0x77, 0x76, 0x4f, 0x4a, 0x74, 0x66, 0x54, 0x31, 0x54, 0x41, 0x49, 0x00},

UFlag: 33557088,
UserLevel: 7 | ptttype.PERM_BOARD | ptttype.PERM_POST | ptttype.PERM_LOGINOK,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_DEFAULT | ptttype.PERM_BOARD | ptttype.PERM_POST | ptttype.PERM_LOGINOK,
NumLoginDays: 2,
NumPosts: 0,
FirstLogin: 1600681288,
Expand Down Expand Up @@ -197,7 +197,7 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{0xaf, 0xab}, // 神
PasswdHash: ptttype.Passwd_t{0x62, 0x68, 0x77, 0x76, 0x4f, 0x4a, 0x74, 0x66, 0x54, 0x31, 0x54, 0x41, 0x49, 0x00},

UFlag: 33557088,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_BASIC,
NumLoginDays: 2,
NumPosts: 0,
Expand Down Expand Up @@ -225,8 +225,8 @@ func initTestVars() {
Nickname: ptttype.Nickname_t{175, 171},
PasswdHash: ptttype.Passwd_t{98, 104, 119, 118, 79, 74, 116, 102, 84, 49, 84, 65, 73, 0},

UFlag: 33557088,
UserLevel: 7 | ptttype.PERM_LOGINOK | ptttype.PERM_POST,
UFlag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
UserLevel: ptttype.PERM_DEFAULT | ptttype.PERM_LOGINOK | ptttype.PERM_POST,
NumLoginDays: 2,
NumPosts: 0,
FirstLogin: 1600681288,
Expand All @@ -248,8 +248,8 @@ func initTestVars() {
},
Nickname: []byte{0xaf, 0xab}, // 神

Uflag: 33557088,
Userlevel: 536871943,
Uflag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
Userlevel: ptttype.PERM_DEFAULT | ptttype.PERM_SYSSUBOP | ptttype.PERM_BM,
Numlogindays: 2,
Numposts: 0,
Firstlogin: 1600681288,
Expand All @@ -273,8 +273,8 @@ func initTestVars() {
UUserID: UUserID("B1"),
Username: "B1",
Lasthost: "127.0.0.1",
Uflag: 33557088,
Userlevel: 7,
Uflag: ptttype.UF_CURSOR_ASCII | ptttype.UF_DBCS_DROP_REPEAT | ptttype.UF_DBCS_AWARE | ptttype.UF_ADBANNER | ptttype.UF_BRDSORT,
Userlevel: ptttype.PERM_DEFAULT,
Numlogindays: 1,
Pager: 1,
Over18: true,
Expand Down Expand Up @@ -526,7 +526,7 @@ func initTestVars() {
BM: []UUserID{},
IdxByName: "mnewboard",
IdxByClass: "Q1BCTA@mnewboard",
BrdAttr: 0x200000,
BrdAttr: ptttype.BRD_CPLOG,
}

testClassSummary2 = &BoardSummary{
Expand All @@ -546,7 +546,7 @@ func initTestVars() {
BM: []UUserID{},
IdxByName: "1...........",
IdxByClass: "Li4uLg@1...........",
BrdAttr: 0x000008,
BrdAttr: ptttype.BRD_GROUPBOARD,
}

testClassDetail2 = &BoardDetail{
Expand Down Expand Up @@ -588,7 +588,7 @@ func initTestVars() {
BM: []UUserID{},
IdxByName: "2...........",
IdxByClass: "Li4uLg@2...........",
BrdAttr: 0x000008,
BrdAttr: ptttype.BRD_GROUPBOARD,
}

testClassDetail5 = &BoardDetail{
Expand Down
Loading

0 comments on commit 5100ad8

Please sign in to comment.