Skip to content

Commit

Permalink
Merge pull request #691 from isucon/feature_docker_external_service
Browse files Browse the repository at this point in the history
Add Dockerfile and compose.yml for external service
  • Loading branch information
catatsuy authored Jan 14, 2024
2 parents b1adc84 + f48bbca commit c4e0361
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ docker build -t isucari-benchmarker -f bench/Dockerfile .
docker run -p 5678:5678 -p 7890:7890 -i isucari-benchmarker /opt/go/benchmarker -target-url http://host.docker.internal -data-dir /initial-data -static-dir /static -payment-url http://host.docker.internal:5678 -payment-port 5678 -shipment-url http://host.docker.internal:7890 -shipment-port 7890
```

### external service

以上だけでもベンチマークを実行することはできるが、外部サービスを起動しないと購入などのアクションを行えないため、外部サービスは別途起動する必要がある。

```bash
docker compose up
```

手元のマシンのIPアドレスが192.0.2.2の場合は以下のコマンドを実行する。ベンチマーク走行時にこの値は書き換わるので、ベンチマーク走行後に確認したい場合も都度実行する必要がある。

```
$ cat initialize.json
{
"payment_service_url": "http://192.0.2.2:5556",
"shipment_service_url": "http://192.0.2.2:7002"
}
$ curl -XPOST http://127.0.0.1:8000/initialize \
-H 'Content-Type: application/json' \
-d @initialize.json
```

## 運営側のブログ

技術情報などについても記載されているので参考にしてください。
Expand Down
16 changes: 16 additions & 0 deletions bench/Dockerfile-external
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.21

RUN mkdir -p /opt/go
WORKDIR /opt/go

COPY initial-data /initial-data

COPY go.mod /opt/go/go.mod
COPY go.sum /opt/go/go.sum
RUN go mod download

COPY cmd/ /opt/go/cmd
COPY bench/ /opt/go/bench

RUN go build -o bin/shipment cmd/shipment/main.go
RUN go build -o bin/payment cmd/payment/main.go
17 changes: 17 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: isucari
services:
payment:
build:
context: .
dockerfile: bench/Dockerfile-external
command: ["/opt/go/bin/payment", "-port", "5556"]
ports:
- "5556:5556"

shipment:
build:
context: .
dockerfile: bench/Dockerfile-external
command: ["/opt/go/bin/shipment", "-data-dir", "/initial-data", "-port", "7002"]
ports:
- "7002:7002"

0 comments on commit c4e0361

Please sign in to comment.