Skip to content

Commit

Permalink
Merge pull request #215 from V01d42/add-generate-url
Browse files Browse the repository at this point in the history
Generate a mysqlURL from host, port, user, password, database
  • Loading branch information
whywaita authored Sep 17, 2024
2 parents 59b9c82 + d8163a4 commit a689ce3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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

0 comments on commit a689ce3

Please sign in to comment.