diff --git a/.gitignore b/.gitignore index 8aefd50b..ae7c06e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,12 @@ -./certs -./parachute +certs +parachute +OpenRegistry .cache -./parachute.yaml +parachute.yaml .idea/ tests .go-skynet +config.yaml +config.yml +OpenRegistry.yaml +OpenRegistry.yml diff --git a/Dockerfile b/Dockerfile index 8e3b3c82..dcd799af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,11 @@ COPY . . RUN apk add gcc make git curl ca-certificates && go mod download github.com/NebulousLabs/go-skynet/v2 && make mod-fix && go mod download -RUN CGO_ENABLED=0 go build -o openregistry main.go +RUN CGO_ENABLED=0 go build -o openregistry -ldflags="-w -s" main.go FROM alpine:latest COPY --from=build /root/openregistry/openregistry . -COPY ./parachute.yaml . +COPY ./config.yaml . EXPOSE 80 CMD ["./openregistry"] diff --git a/auth/auth.go b/auth/auth.go index c35734af..504a1d29 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,8 +1,8 @@ package auth import ( - "github.com/jay-dee7/parachute/cache" - "github.com/jay-dee7/parachute/config" + "github.com/jay-dee7/OpenRegistry/cache" + "github.com/jay-dee7/OpenRegistry/config" "github.com/labstack/echo/v4" ) diff --git a/cache/go-skynet b/cache/go-skynet deleted file mode 160000 index dbd04076..00000000 --- a/cache/go-skynet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dbd04076aba6c75be57055507f2e01c15acdc091 diff --git a/cache/store.go b/cache/store.go index fdf548f1..d8fc1d04 100644 --- a/cache/store.go +++ b/cache/store.go @@ -6,7 +6,7 @@ import ( "net/http" badger "github.com/dgraph-io/badger/v3" - "github.com/jay-dee7/parachute/types" + "github.com/jay-dee7/OpenRegistry/types" "github.com/labstack/echo/v4" ) diff --git a/certs/openregistry-origin.pem b/certs/openregistry-origin.pem deleted file mode 100644 index fa7aca41..00000000 --- a/certs/openregistry-origin.pem +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDLDC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KCaIoxG4pfGF/lRmS9kbelrfC9p8A/k90Z8y4Xw7O ------END CERTIFICATE----- diff --git a/certs/openregistry-privkey.pem b/certs/openregistry-privkey.pem deleted file mode 100644 index 3c76fb92..00000000 --- a/certs/openregistry-privkey.pem +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgecOKL12Y6dPDJrgU -TM/mwKR/xV8HI67BvQ2d0TYgJp6hRANCAARx+yXSfUvCxxIhz1OKfrbBi63s8yWG -GoLVQtV2rAx5RteG7Ta2Uzj3KaVoR7qPvC9ZT54CD0GLTlLtCFq9oMoL ------END PRIVATE KEY----- diff --git a/config/config.go b/config/config.go index 8f0ff447..494efbed 100644 --- a/config/config.go +++ b/config/config.go @@ -2,9 +2,7 @@ package config import ( "fmt" - "log" "os" - "os/user" "github.com/spf13/viper" ) @@ -16,10 +14,6 @@ type ( Host string `mapstructure:"host"` Port uint `mapstructure:"port"` SkynetPortalURL string `mapstructure:"skynet_portal_url"` - SkynetLinkResolvers []string `mapstructure:"skynet_link_resolvers"` - SkynetStorePath string `mapstructure:"skynet_store_path"` - TLSCertPath string `mapstructure:"tls_cert_path"` - TLSKeyPath string `mapstructure:"tls_key_path"` SigningSecret string `mapstructure:"signing_secret"` SkynetConfig SkynetConfig `mapstructure:"skynet_config"` } @@ -35,22 +29,29 @@ func (r *RegistryConfig) Address() string { return fmt.Sprintf("%s:%d", r.Host, r.Port) } -func Load(path string) (*RegistryConfig, error) { - viper.AddConfigPath(path) - viper.SetConfigName("parachute") - viper.SetConfigType("yaml") +func LoadFromENV() (*RegistryConfig, error) { + // TODO - Add Support for loading from config + // loading config from path is not possible right now, + // since aksah does not support pull from private container repositories + // viper.AddConfigPath(path) + // viper.SetConfigName("config") + // viper.SetConfigType("yaml") + viper.SetEnvPrefix("OPEN_REGISTRY") viper.AutomaticEnv() - - err := viper.ReadInConfig() - if err != nil { - setDefaults() - } - - var config RegistryConfig - err = viper.Unmarshal(&config) - if err != nil { - return nil, err + // err := viper.ReadInConfig() + // if err != nil { + // return nil, err + // } + + config := RegistryConfig{ + Debug: viper.GetBool("DEBUG"), + Environment: viper.GetString("ENVIRONMENT"), + Host: viper.GetString("HOST"), + Port: viper.GetUint("PORT"), + SkynetPortalURL: viper.GetString("SKYNET_PORTAL_URL"), + SigningSecret: viper.GetString("SIGNING_SECRET"), + SkynetConfig: SkynetConfig{}, } if config.SigningSecret == "" { @@ -60,27 +61,3 @@ func Load(path string) (*RegistryConfig, error) { return &config, nil } - -func setDefaults() { - - user, err := user.Current() - if err != nil { - log.Fatalln(err.Error()) - } - - defaultStorePath := user.HomeDir + "/.parachute" - defaultLinkResolverPath := defaultStorePath + "/links" - - _ = os.MkdirAll(defaultLinkResolverPath, os.ModePerm) - - viper.SetDefault("debug", true) - viper.SetDefault("environment", "devel") - viper.SetDefault("domain", "alpha.openregistry.dev") - viper.SetDefault("host", "0.0.0.0") - viper.SetDefault("port", "5000") - viper.SetDefault("tls_key_path", "./certs/key.pem") - viper.SetDefault("tls_cert_path", "./certs/cert.pem") - viper.SetDefault("skynet_store_path", defaultStorePath) - viper.SetDefault("skynet_link_resolvers", defaultLinkResolverPath) - viper.SetDefault("skynet_portal_url", "https://siasky.net") -} diff --git a/env-vars.example b/env-vars.example new file mode 100644 index 00000000..6e43cb4f --- /dev/null +++ b/env-vars.example @@ -0,0 +1,6 @@ +export OPEN_REGISTRY_DEBUG=true +export OPEN_REGISTRY_DOMAIN="beta.openregistry.dev" +export OPEN_REGISTRY_HOST="100.87.37.43" +export OPEN_REGISTRY_PORT="5000" +export OPEN_REGISTRY_SKYNET_PORTAL_URL="https://siasky.net" +export OPEN_REGISTRY_SIGNING_SECRET="3tYnaKp@^%hbQA%J&x3cX!r2#mK%EBfAbTvPMv5CU2DP7bAoQGnUfT2&dW" diff --git a/go.mod b/go.mod index e5cb31b9..22b9c30d 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/jay-dee7/parachute +module github.com/jay-dee7/OpenRegistry go 1.16 diff --git a/main.go b/main.go index d258d567..3ac8e47c 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,18 @@ package main import ( - "github.com/jay-dee7/parachute/registry/v2" "log" "net/http" "os" "time" + "github.com/jay-dee7/OpenRegistry/registry/v2" + "github.com/fatih/color" - "github.com/jay-dee7/parachute/auth" - "github.com/jay-dee7/parachute/cache" - "github.com/jay-dee7/parachute/config" - "github.com/jay-dee7/parachute/skynet" + "github.com/jay-dee7/OpenRegistry/auth" + "github.com/jay-dee7/OpenRegistry/cache" + "github.com/jay-dee7/OpenRegistry/config" + "github.com/jay-dee7/OpenRegistry/skynet" "github.com/labstack/echo-contrib/prometheus" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -19,12 +20,7 @@ import ( ) func main() { - var configPath string - if len(os.Args) != 2 { - configPath = "./" - } - - cfg, err := config.Load(configPath) + cfg, err := config.LoadFromENV() if err != nil { color.Red("error reading cfg file: %s", err.Error()) os.Exit(1) @@ -35,9 +31,6 @@ func main() { p.Use(e) e.HideBanner = true - // e.Use(middleware.HTTPSNonWWWRedirect()) - // e.Use(middleware.HTTPSRedirect()) - l := setupLogger() localCache, err := cache.New("/tmp/badger") if err != nil { diff --git a/parachute b/parachute deleted file mode 100755 index b53225cf..00000000 Binary files a/parachute and /dev/null differ diff --git a/parachute.yaml b/parachute.yaml deleted file mode 100644 index 884fbe51..00000000 --- a/parachute.yaml +++ /dev/null @@ -1,14 +0,0 @@ -debug: true -domain: "beta.openregistry.dev" -host: 0.0.0.0 -port: 5000 -tls_key_path: ./openregistry-privkey.pem -tls_cert_path: ./openregistry-origin.pem -skynet_store_path: /Users/jasdeep/.parachute -skynet_link_resolvers: /Users/jasdeep/.parachute/links -skynet_portal_url: https://siasky.net -signing_secret: 3tYnaKp@^%hbQA%J&x3cX!r2#mK%EBfAbTvPMv5CU2DP7bAoQGnUfT2&dW -skynet_config: - endpoint_path: "" - api_key: "" - custom_user_agent: "parachute-registry" diff --git a/parachute.yaml.example b/parachute.yaml.example deleted file mode 100644 index 01d76492..00000000 --- a/parachute.yaml.example +++ /dev/null @@ -1,13 +0,0 @@ -debug: true -domain: "beta.openregistry.dev" -host: 100.87.37.43 -port: 5000 -tls_key_path: ./certs/beta-openregistry.key -tls_cert_path: ./certs/beta-openregistry.crt -skynet_store_path: /Users/jasdeep/.parachute -skynet_link_resolvers: /Users/jasdeep/.parachute/links -skynet_portal_url: https://siasky.net -skynet_config: - endpoint_path: "" - api_key: "" - custom_user_agent: "parachute-registry" diff --git a/registry/v2/registry.go b/registry/v2/registry.go index 842fef54..42bb3283 100644 --- a/registry/v2/registry.go +++ b/registry/v2/registry.go @@ -13,9 +13,9 @@ import ( skynetsdk "github.com/NebulousLabs/go-skynet/v2" "github.com/docker/distribution/uuid" "github.com/fatih/color" - "github.com/jay-dee7/parachute/cache" - "github.com/jay-dee7/parachute/skynet" - "github.com/jay-dee7/parachute/types" + "github.com/jay-dee7/OpenRegistry/cache" + "github.com/jay-dee7/OpenRegistry/skynet" + "github.com/jay-dee7/OpenRegistry/types" "github.com/labstack/echo/v4" "github.com/rs/zerolog" ) diff --git a/registry/v2/types.go b/registry/v2/types.go index b8f11188..7b789416 100644 --- a/registry/v2/types.go +++ b/registry/v2/types.go @@ -3,8 +3,8 @@ package registry import ( "sync" - "github.com/jay-dee7/parachute/cache" - "github.com/jay-dee7/parachute/skynet" + "github.com/jay-dee7/OpenRegistry/cache" + "github.com/jay-dee7/OpenRegistry/skynet" "github.com/labstack/echo/v4" "github.com/rs/zerolog" ) diff --git a/skynet/skynet.go b/skynet/skynet.go index 50bd0313..cfd220b0 100644 --- a/skynet/skynet.go +++ b/skynet/skynet.go @@ -7,7 +7,7 @@ import ( "strconv" "github.com/NebulousLabs/go-skynet/v2" - "github.com/jay-dee7/parachute/config" + "github.com/jay-dee7/OpenRegistry/config" tar "github.com/whyrusleeping/tar-utils" )