Skip to content

Commit b752b4c

Browse files
authored
Merge pull request #55 from showwin/scoreboard-improvement
Add useful commands for scoreboard management
2 parents e095382 + 0a0fd7c commit b752b4c

22 files changed

+146
-90
lines changed

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Node.js(TypeScript), Crystal, Scala は参考実装が残っていますが、OS
3434
│   ├── ami # PackerでAMIの作成 (手動)
3535
│   ├── benchmarker # ベンチマーカーの実装
3636
├── contest # コンテストのイベント実施用のリソース
37-
│   ├── portal # コンテスト用ポータルサイトの実装. Terraformから参照されてS3にアップロードされる
37+
│   ├── scoreboard # コンテスト用スコアボードの実装. Terraformから参照されてS3にアップロードされる
3838
│   └── terraform # コンテスト用のインフラリソース準備
3939
├── doc # 参加者向けのドキュメント
4040
├── docker # ローカルでISHOCONに取り組む & CIで使う用のDocker Image

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ISUCONは3人チームで取り組むことを基準に課題が作られてい
1717

1818
## 問題詳細
1919
* マニュアル: [ISHOCON1マニュアル](https://github.com/showwin/ISHOCON1/blob/master/doc/manual.md)
20-
* AMI: `ami-073e32684d5ff32c8`
20+
* AMI: `ami-04241d5ce3f2f0a79`
2121
* インスタンスタイプ: `c7i.xlarge`
2222
* 参考実装言語: Ruby, Go, Python
2323
* メンテナンス外: Node.js(TypeScript), Crystal(by [@Goryudyuma](https://github.com/Goryudyuma)), Scala(by [@Goryudyuma](https://github.com/Goryudyuma))

Diff for: admin/benchmarker/scenario.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func showScore() {
168168
}
169169

170170
func postScore() {
171-
apiURL := os.Getenv("BENCH_PORTAL_APIGW_URL")
171+
apiURL := os.Getenv("BENCH_SCOREBOARD_APIGW_URL")
172172
teamName := os.Getenv("BENCH_TEAM_NAME")
173173
if apiURL == "" && teamName == "" {
174174
return
@@ -218,5 +218,5 @@ func postScore() {
218218
return
219219
}
220220
defer resp.Body.Close()
221-
log.Print("Sent score to portal site")
221+
log.Print("Sent score to scoreboard")
222222
}
File renamed without changes.
File renamed without changes.

Diff for: contest/portal/dist/main.js renamed to contest/scoreboard/dist/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ function updateGraph() {
186186
}
187187
// Initial graph rendering
188188
updateGraph();
189-
// Fetch and refresh the graph every 3 minutes (180,000 ms)
190-
setInterval(updateGraph, 180000);
189+
// Fetch and refresh the graph every 30 seconds (30,000 ms)
190+
setInterval(updateGraph, 30000);

Diff for: contest/portal/index.html renamed to contest/scoreboard/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Score Portal</title>
6+
<title>Scoreboard</title>
77
<script src="https://d3js.org/d3.v7.min.js"></script>
88
<style>
99
body {
@@ -46,7 +46,7 @@
4646
</style>
4747
</head>
4848
<body>
49-
<h1>ISHOCON1 Score Portal</h1>
49+
<h1>ISHOCON1 Scoreboard</h1>
5050

5151
<div id="timeline-chart"></div>
5252
<div id="bar-chart"></div>

Diff for: contest/portal/package-lock.json renamed to contest/scoreboard/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: contest/portal/package.json renamed to contest/scoreboard/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "ISHOCON1-portal",
2+
"name": "ISHOCON1-scoreboard",
33
"version": "1.0.0",
4-
"description": "ISHOCON1 Portal",
4+
"description": "ISHOCON1 Scoreboard",
55
"main": "dist/main.js",
66
"scripts": {
77
"build": "tsc"
File renamed without changes.

Diff for: contest/portal/src/main.ts renamed to contest/scoreboard/src/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,5 @@ function updateGraph() {
215215
// Initial graph rendering
216216
updateGraph();
217217

218-
// Fetch and refresh the graph every 3 minutes (180,000 ms)
219-
setInterval(updateGraph, 180000);
218+
// Fetch and refresh the graph every 30 seconds (30,000 ms)
219+
setInterval(updateGraph, 30000);
File renamed without changes.

Diff for: contest/terraform/README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ TerraformでISHOCON1の環境が構築できます。
77

88
## 作成されるもの
99
* チーム毎に1台の競技に使用するEC2インスタンス
10-
* 各チームのスコアがリアルタイムに見れるポータルサイト
10+
* 各チームのスコアがリアルタイムに見れるスコアボード
1111

1212
## 必要なもの
1313

1414
- 支払情報が紐付けされたAWSアカウント
15-
- ポータルサイトは低コストになるように実装していますが、主に以下の費用がかかります。
15+
- スコアボードは低コストになるように実装していますが、主に以下の費用がかかります。
1616
- DynamoDB, Lambda, CloudWatch, API Gateway, S3
1717
- IAMユーザのアクセスIDとシークレットアクセスキー
1818

@@ -55,24 +55,33 @@ ip_addr = {
5555
"team1" = "11.111.111.111"
5656
"team2" = "11.111.111.112"
5757
}
58-
portal_url = "http://ishocon1-portal123456789.s3-website-ap-northeast-1.amazonaws.com"
58+
scoreboard_url = "http://ishocon1-scoreboard123456789.s3-website-ap-northeast-1.amazonaws.com"
5959
```
6060

61-
Outputに競技で使用するインスタンスのIPアドレスとポータルサイトのアドレスが出力されるので、参加者に共有する。
61+
Outputに競技で使用するインスタンスのIPアドレスとスコアボードのアドレスが出力されるので、参加者に共有する。
6262

6363
```
6464
$ ssh ishocon@<instance_ip>
6565
```
6666

6767
でインスタンスにSSHできる。
68-
ベンチマーカーを実行すると、スコアを `apigateway_url` に投稿するようになっており、自動的にポータルサイトに結果が表示される
68+
ベンチマーカーを実行すると、スコアを `apigateway_url` に投稿するようになっており、自動的にスコアボードに結果が表示される
6969

70-
ポータルサイトに表示されているデータをすべて削除したい場合は以下のコマンドを実行する。
70+
## スコアボード管理の便利コマンド
7171

7272
```
73-
$ terraform output -raw apigateway_url | xargs -I {} curl -X "DELETE" "{}teams"
73+
$ cd terraform/main
74+
75+
$ make close-scoreboard # 競技1時間前などにスコアを非表示にする
76+
$ make reopen-scoreboard # 非表示にしたスコアボードを再度表示する
77+
78+
$ make freeze-scoreboard # 競技終了後にベンチマーカーを動かしてもスコアボードに反映されないようにする
79+
$ make unfreeze-scoreboard # スコアボードの凍結を解除し、ベンチマーカーの結果がスコアボードに反映されるようにする
80+
81+
$ make delete-scoreboard-data # [注意] スコアボードに表示されているデータをすべて削除
7482
```
7583

84+
7685
## 注意点
7786

7887
- デフォルトでは、ISHOCON1の推奨インスタンスタイプである `c7i.xlarge` でインスタンスが起動します

Diff for: contest/terraform/main/Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: delete-scoreboard-data
2+
delete-scoreboard-data:
3+
terraform output -raw apigateway_url | xargs -I {} curl -X "DELETE" "{}teams"
4+
5+
.PHONY: close-scoreboard
6+
close-scoreboard:
7+
aws apigatewayv2 update-route --api-id `terraform output -raw api_gateway_id` --route-id `terraform output -raw api_gateway_get_route_id` --authorization-type AWS_IAM > /dev/null
8+
@echo "Scoreboard is closed."
9+
10+
.PHONY: reopen-scoreboard
11+
reopen-scoreboard:
12+
aws apigatewayv2 update-route --api-id `terraform output -raw api_gateway_id` --route-id `terraform output -raw api_gateway_get_route_id` --authorization-type NONE > /dev/null
13+
@echo "Scoreboard is reopened."
14+
15+
.PHONY: freeze-scoreboard
16+
freeze-scoreboard:
17+
aws apigatewayv2 update-route --api-id `terraform output -raw api_gateway_id` --route-id `terraform output -raw api_gateway_put_route_id` --authorization-type AWS_IAM > /dev/null
18+
@echo "Scoreboard is freezed."
19+
20+
.PHONY: unfreeze-scoreboard
21+
unfreeze-scoreboard:
22+
aws apigatewayv2 update-route --api-id `terraform output -raw api_gateway_id` --route-id `terraform output -raw api_gateway_put_route_id` --authorization-type NONE > /dev/null
23+
@echo "Scoreboard can accepts new score."

Diff for: contest/terraform/main/output.tf

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@ output "ip_addr" {
22
value = module.main.ip_addr
33
}
44

5-
output "portal_url" {
6-
value = module.main.portal_url
5+
output "scoreboard_url" {
6+
value = module.main.scoreboard_url
77
}
88

9+
# For commands in Makefile
910
output "apigateway_url" {
1011
value = module.main.apigateway_url
1112
}
13+
14+
output "api_gateway_id" {
15+
value = module.main.api_gateway_id
16+
}
17+
18+
output "api_gateway_get_route_id" {
19+
value = module.main.api_gateway_get_route_id
20+
}
21+
22+
output "api_gateway_put_route_id" {
23+
value = module.main.api_gateway_put_route_id
24+
}

Diff for: contest/terraform/module/ec2.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ${join("\n", [for admin in var.admins : "curl https://github.com/${admin}.keys >
1919
chown -R ishocon:ishocon /home/ishocon/.ssh
2020
useradd -u 1001 -g 1001 -o -N -d /home/ishocon -s /bin/bash ${each.value}
2121
echo "export BENCH_TEAM_NAME=${each.value}" >> /home/ishocon/.bashrc
22-
echo "export BENCH_PORTAL_APIGW_URL=${aws_apigatewayv2_stage.portal.invoke_url}" >> /home/ishocon/.bashrc
22+
echo "export BENCH_SCOREBOARD_APIGW_URL=${aws_apigatewayv2_stage.scoreboard.invoke_url}" >> /home/ishocon/.bashrc
2323
2424
EOF
2525

Diff for: contest/terraform/module/ec2_spot.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ${join("\n", [for admin in var.admins : "curl https://github.com/${admin}.keys >
1919
chown -R ishocon:ishocon /home/ishocon/.ssh
2020
useradd -u 1001 -g 1001 -o -N -d /home/ishocon -s /bin/bash ${each.value}
2121
echo "export BENCH_TEAM_NAME=${each.value}" >> /home/ishocon/.bashrc
22-
echo "export BENCH_PORTAL_APIGW_URL=${aws_apigatewayv2_stage.portal.invoke_url}" >> /home/ishocon/.bashrc
22+
echo "export BENCH_SCOREBOARD_APIGW_URL=${aws_apigatewayv2_stage.scoreboard.invoke_url}" >> /home/ishocon/.bashrc
2323
2424
EOF
2525

Diff for: contest/terraform/module/output.tf

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@ output "ip_addr" {
55
}
66
}
77

8-
output "portal_url" {
9-
value = "http://${aws_s3_bucket_website_configuration.portal.website_endpoint}"
8+
output "scoreboard_url" {
9+
value = "http://${aws_s3_bucket_website_configuration.scoreboard.website_endpoint}"
1010
}
1111

1212
output "apigateway_url" {
13-
value = aws_apigatewayv2_stage.portal.invoke_url
13+
value = aws_apigatewayv2_stage.scoreboard.invoke_url
14+
}
15+
16+
output "api_gateway_id" {
17+
value = aws_apigatewayv2_api.scoreboard.id
18+
}
19+
20+
output "api_gateway_get_route_id" {
21+
value = aws_apigatewayv2_route.scoreboard_teams_get.id
22+
}
23+
24+
output "api_gateway_put_route_id" {
25+
value = aws_apigatewayv2_route.scoreboard_teams_put.id
1426
}

0 commit comments

Comments
 (0)