11package main
22
33import (
4- "fmt"
54 "io/ioutil"
65 "log"
6+ "net"
7+ "net/url"
78 "os"
89 "os/exec"
10+ "strings"
911)
1012
1113const (
@@ -17,10 +19,16 @@ const (
1719
1820func main () {
1921 log .Println ("INFO: Starting registry..." )
20- mEndpoint := os .Getenv (minioEndpointEnvVar )
2122 os .Setenv ("REGISTRY_STORAGE" , "s3" )
22- os .Setenv ("REGISTRY_STORAGE_S3_BACKEND" , "minio" )
23- os .Setenv ("REGISTRY_STORAGE_S3_REGIONENDPOINT" , fmt .Sprintf ("http://%s" , mEndpoint ))
23+ mEndpoint := os .Getenv (minioEndpointEnvVar )
24+ os .Setenv ("REGISTRY_STORAGE_S3_REGIONENDPOINT" , mEndpoint )
25+ region := "us-east-1" //region is required in distribution
26+ if endpointURL , err := url .Parse (mEndpoint ); err == nil {
27+ if endpointURL .Hostname () != "" && net .ParseIP (endpointURL .Hostname ()) == nil {
28+ region = strings .Split (endpointURL .Hostname (), "." )[0 ]
29+ }
30+ }
31+ os .Setenv ("REGISTRY_STORAGE_S3_REGION" , region )
2432
2533 if accesskey , err := ioutil .ReadFile ("/var/run/secrets/drycc/minio/creds/accesskey" ); err != nil {
2634 log .Fatal (err )
@@ -45,8 +53,6 @@ func main() {
4553 os .Setenv ("REGISTRY_STORAGE_S3_BUCKET" , "registry" ) // default bucket
4654 }
4755
48- os .Setenv ("REGISTRY_STORAGE_S3_REGION" , "us-east-1" )
49-
5056 // run /bin/create_bucket
5157 cmd := exec .Command ("/bin/create_bucket" )
5258 cmd .Stdout = os .Stdout
0 commit comments