Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[typing-server]: 接続するDBのアドレスを環境変数で指定できるように #13

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions typing-server/api/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ func main() {
return
}

var addr = os.Getenv("DB_ADDR")
if addr == "" {
addr = "db:3306" // アドレス(Docker Compose内でのサービス名とポート)
}

// MySQLの接続設定
mysqlConfig := &mysql.Config{
DBName: "typing-db", // データベース名
User: "user", // ユーザー名
Passwd: "password", // パスワード
Net: "tcp", // ネットワークタイプ
Addr: "db:3306", // アドレス(Docker Compose内でのサービス名とポート)
ParseTime: true, // 時刻をtime.Timeで解析する
Loc: jst, // タイムゾーン
Addr: addr,
ParseTime: true, // 時刻をtime.Timeで解析する
Loc: jst, // タイムゾーン
}

// entクライアントの初期化
Expand Down
2 changes: 2 additions & 0 deletions typing-server/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
dockerfile: Dockerfile
volumes:
- ./api:/app
environment:
DB_ADDR: ${DB_ADDR:-db:3306}
h-takeyeah marked this conversation as resolved.
Show resolved Hide resolved
ports:
- "8080:8080"
networks:
Expand Down
2 changes: 2 additions & 0 deletions typing-server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
dockerfile: Dockerfile
volumes:
- ./api:/app
environment:
DB_ADDR: ${DB_ADDR:-db:3306}
ports:
- "8080:8080"
networks:
Expand Down
Loading