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

Generate a mysqlURL from host, port, user, password, database #215

Merged
merged 3 commits into from
Sep 17, 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
5 changes: 5 additions & 0 deletions docs/01_01_for_admin_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ A config variables can set from environment values.
- `MYSQL_URL`
- required
- DataSource Name, ex) `username:password@tcp(localhost:3306)/myshoes`
- if `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_DATABASE` all are set, this env value are ignored.
- `MYSQL_USER`, `MYSQL_PASSWORD`, `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_DATABASE`
- optional
- If all environment variables are set, mysql_url is constructed and loaded in the following way, then `MYSQL_URL` env will be ignored.
- example) `${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(${MYSQL_HOST}:${MYSQL_PORT})/${MYSQL_DATABASE}`
- `PLUGIN`
- required
- set path of myshoes-provider binary.
Expand Down
7 changes: 6 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Conf struct {
GitHubURL string
RunnerVersion string

DockerHubCredential DockerHubCredential
DockerHubCredential DockerHubCredential
ProvideDockerHubMetrics bool
}

Expand All @@ -51,6 +51,11 @@ const (
EnvGitHubAppID = "GITHUB_APP_ID"
EnvGitHubAppSecret = "GITHUB_APP_SECRET"
EnvGitHubAppPrivateKeyBase64 = "GITHUB_PRIVATE_KEY_BASE64"
EnvMySQLHost = "MYSQL_HOST"
EnvMySQLPort = "MYSQL_PORT"
EnvMySQLUser = "MYSQL_USER"
EnvMySQLPassword = "MYSQL_PASSWORD"
EnvMySQLDatabase = "MYSQL_DATABASE"
EnvMySQLURL = "MYSQL_URL"
EnvPort = "PORT"
EnvShoesPluginPath = "PLUGIN"
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ func LoadGitHubApps() *GitHubApp {

// LoadMySQLURL load MySQL URL from environment
func LoadMySQLURL() string {
mysqlHost, ok_Host := os.LookupEnv(EnvMySQLHost)
mysqlPort, ok_Port := os.LookupEnv(EnvMySQLPort)
mysqlUser, ok_User := os.LookupEnv(EnvMySQLUser)
mysqlPassword, ok_Password := os.LookupEnv(EnvMySQLPassword)
mysqlDatabase, ok_Database := os.LookupEnv(EnvMySQLDatabase)
if ok_Host && ok_Port && ok_User && ok_Password && ok_Database {
mysqlURL := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", mysqlUser, mysqlPassword, mysqlHost, mysqlPort, mysqlDatabase)
log.Println("load MySQL URL from environment variables MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, MYSQL_DATABASE, not MYSQL_URL")
return mysqlURL
}
mysqlURL := os.Getenv(EnvMySQLURL)
if mysqlURL == "" {
log.Panicf("%s must be set", EnvMySQLURL)
Expand Down