feat: Dockerize the application

This commit is contained in:
Prad Nukala 2025-01-04 19:52:54 -05:00
parent 466b34b5bd
commit 6e3cee596f
7 changed files with 48 additions and 78 deletions

3
Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM scratch
ENTRYPOINT ["/hway"]
COPY hway /

View File

@ -6,12 +6,12 @@ BINDIR ?= $(GOPATH)/bin
# for dockerized protobuf tools
DOCKER := $(shell which docker)
HTTPS_GIT := github.com/onsonr/hway.git
export RELEASE_DATE="$(date +%Y).$(date +%V).$(date +%u)"
all: install test
build: go.sum
go build -o build/hway ./cmd
go build -o build/hway .
install: go.sum
go install -mod=readonly ./cmd/hway

View File

@ -1,12 +1,12 @@
// Package gateway provides the default routes for the Sonr hway.
package gateway
package app
import (
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
echomiddleware "github.com/labstack/echo/v4/middleware"
"github.com/onsonr/hway/gateway/handlers"
config "github.com/onsonr/hway/internal/config/hway"
config "github.com/onsonr/hway/internal/config"
hwayorm "github.com/onsonr/hway/internal/models"
"github.com/onsonr/hway/pkg/common"
"github.com/onsonr/hway/pkg/context"

View File

@ -1,48 +0,0 @@
package main
import (
"context"
_ "embed"
"fmt"
"os"
"github.com/jackc/pgx/v5"
hwayorm "github.com/onsonr/hway/internal/models"
)
// main is the entry point for the application
func main() {
cmd := rootCmd()
if err := cmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(0)
}
func loadEnvImplFromArgs(args []string) (config.Hway, error) {
cmd := rootCmd()
if err := cmd.ParseFlags(args); err != nil {
return nil, err
}
env := &config.HwayImpl{
ServePort: servePort,
ChainId: chainID,
IpfsGatewayUrl: ipfsGatewayURL,
SonrApiUrl: sonrAPIURL,
SonrGrpcUrl: sonrGrpcURL,
SonrRpcUrl: sonrRPCURL,
PsqlDSN: formatPsqlDSN(),
}
return env, nil
}
func setupPostgresDB() (*hwayorm.Queries, error) {
pgdsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", psqlHost, psqlUser, psqlPass, psqlDB)
conn, err := pgx.Connect(context.Background(), pgdsn)
if err != nil {
return nil, err
}
return hwayorm.New(conn), nil
}

View File

@ -1,13 +1,17 @@
package main
import (
"database/sql"
_ "embed"
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/onsonr/hway/gateway"
"github.com/onsonr/hway/app"
"github.com/onsonr/hway/internal/config"
hwayorm "github.com/onsonr/hway/internal/models"
"github.com/onsonr/hway/pkg/common"
"github.com/spf13/cobra"
)
@ -27,6 +31,16 @@ var (
psqlDB string // PostgresSQL Database Flag
)
// main is the entry point for the application
func main() {
cmd := rootCmd()
if err := cmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(0)
}
func rootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "hway",
@ -40,11 +54,11 @@ func rootCmd() *cobra.Command {
if err != nil {
panic(err)
}
dbq, err := setupPostgresDB()
dbq, err := setupSQLiteDB()
if err != nil {
panic(err)
}
e, err := gateway.New(env, ipc, dbq)
e, err := app.New(env, ipc, dbq)
if err != nil {
panic(err)
}
@ -69,24 +83,27 @@ func rootCmd() *cobra.Command {
return cmd
}
func formatPsqlDSN() string {
if psqlHost == "" {
return ""
func loadEnvImplFromArgs(args []string) (config.Hway, error) {
cmd := rootCmd()
if err := cmd.ParseFlags(args); err != nil {
return nil, err
}
host := psqlHost
port := "5432"
if parts := strings.Split(psqlHost, ":"); len(parts) == 2 {
host = parts[0]
port = parts[1]
env := &config.HwayImpl{
ServePort: servePort,
ChainId: chainID,
IpfsGatewayUrl: ipfsGatewayURL,
SonrApiUrl: sonrAPIURL,
SonrGrpcUrl: sonrGrpcURL,
SonrRpcUrl: sonrRPCURL,
}
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=verify-full",
host, port, psqlUser, psqlPass, psqlDB)
log.Printf("Attempting to connect to PostgreSQL with DSN: host=%s port=%s user=%s dbname=%s",
host, port, psqlUser, psqlDB) // Don't log the password
return dsn
return env, nil
}
func setupSQLiteDB() (*hwayorm.Queries, error) {
conn, err := sql.Open("sqlite3", ":memory:")
if err != nil {
return nil, err
}
return hwayorm.New(conn), nil
}

View File

@ -3,9 +3,9 @@ package common
import (
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
nodev1beta1 "github.com/cosmos/cosmos-sdk/client/grpc/node"
didv1 "github.com/onsonr/hway/api/did/v1"
dwnv1 "github.com/onsonr/hway/api/dwn/v1"
svcv1 "github.com/onsonr/hway/api/svc/v1"
didv1 "github.com/onsonr/sonr/api/did/v1"
dwnv1 "github.com/onsonr/sonr/api/dwn/v1"
svcv1 "github.com/onsonr/sonr/api/svc/v1"
"google.golang.org/grpc"
)

View File

@ -8,8 +8,6 @@ import (
"github.com/golang-jwt/jwt"
"github.com/ipfs/go-cid"
"github.com/onsonr/hway/internal/crypto/keys"
"github.com/onsonr/hway/internal/crypto/ucan"
)
type IPFSTokenStore interface {