Skip to content

Commit

Permalink
Merge pull request #21 from jiro4989/develop
Browse files Browse the repository at this point in the history
CIでAPIにリクエストを送るテストを追加 #8
  • Loading branch information
jiro4989 authored Dec 9, 2019
2 parents 6e1cafa + a214220 commit 734ac42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ jobs:
run: docker-compose -f docker-compose-ci.yml run server test -Y
- name: Build server
run: docker-compose -f docker-compose-ci.yml run server
- name: Test API
run: |
pushd websh_server
WEBSH_DOCKER_IMAGE=jiro4989/websh ./bin/websh_server &
pid=$!
sleep 2
# 出力内容を確認する用
curl -s --connect-timeout 5 -X POST -d '{"code":"echo hello"}' 'http://0.0.0.0:5000/shellgei'
# 標準出力のテスト
cnt=$(curl -s --connect-timeout 5 -X POST -d '{"code":"echo hello"}' 'http://0.0.0.0:5000/shellgei' | grep hello | wc -l)
[ "$cnt" -eq 1 ]
# 標準エラー出力のテスト
cnt=$(curl -s --connect-timeout 5 -X POST -d '{"code":"echo hello >&2"}' 'http://0.0.0.0:5000/shellgei' | grep hello | wc -l)
[ "$cnt" -eq 1 ]
kill $pid
popd
- name: Build front
run: docker-compose -f docker-compose-ci.yml run front
- name: Archive release files
Expand Down
7 changes: 4 additions & 3 deletions websh_server/src/websh_server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ router myrouter:
removeDir(imageDir)
info &"{imageDir} was removed"

# コマンドを実行するDockerイメージ名
createDir(imageDir)
let containerShellScriptPath = &"/tmp/{scriptName}"
let imageName = getEnv("WEBSH_DOCKER_IMAGE", "theoldmoon0602/shellgeibot")
let args = [
"run",
"--rm",
Expand All @@ -79,8 +81,7 @@ router myrouter:
"-v", &"{shellScriptPath}:{containerShellScriptPath}",
"-v", &"{imageDir}:/{img}",
# "-v", "./media:/media:ro",
"theoldmoon0602/shellgeibot",
#"theoldmoon0602/shellgeibot:master",
imageName,
"bash", "-c", &"chmod +x {containerShellScriptPath} && sync && timeout -sKILL 20 {containerShellScriptPath} | stdbuf -o0 head -c 100K",
]
let (stdoutStr, stderrStr) = runCommand("docker", args)
Expand All @@ -103,7 +104,7 @@ router myrouter:
resp %*{"status":"ok"}

proc main =
var port = getEnv("SHELLGEI_WEB_PORT", "5000").parseInt().Port
var port = getEnv("WEBSH_PORT", "5000").parseInt().Port
var settings = newSettings(port = port)
var jester = initJester(myrouter, settings = settings)
jester.serve()
Expand Down

0 comments on commit 734ac42

Please sign in to comment.