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

Cleanup - app vars, certs, and config files #11

Merged
merged 1 commit into from
Jul 14, 2021
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 .gitignore
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down
1 change: 0 additions & 1 deletion cache/go-skynet
Submodule go-skynet deleted from dbd040
2 changes: 1 addition & 1 deletion cache/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
19 changes: 0 additions & 19 deletions certs/openregistry-origin.pem

This file was deleted.

5 changes: 0 additions & 5 deletions certs/openregistry-privkey.pem

This file was deleted.

65 changes: 21 additions & 44 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package config

import (
"fmt"
"log"
"os"
"os/user"

"github.com/spf13/viper"
)
Expand All @@ -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"`
}
Expand All @@ -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 == "" {
Expand All @@ -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")
}
6 changes: 6 additions & 0 deletions env-vars.example
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jay-dee7/parachute
module github.com/jay-dee7/OpenRegistry

go 1.16

Expand Down
21 changes: 7 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
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"
"github.com/rs/zerolog"
)

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)
Expand All @@ -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 {
Expand Down
Binary file removed parachute
Binary file not shown.
14 changes: 0 additions & 14 deletions parachute.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions parachute.yaml.example

This file was deleted.

6 changes: 3 additions & 3 deletions registry/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions registry/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion skynet/skynet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down