From b29262fc59eb15674c6f1ae2f46ca8c13d30667d Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Mon, 18 Dec 2023 23:04:17 -0500 Subject: [PATCH] Updates to support running in docker --- Dockerfile | 3 +++ README.md | 12 +++++++++++- app/config/load.go | 11 ++++++++--- cmd/main.go | 3 ++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc1506d..65c7a0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,9 @@ RUN CGO_ENABLED=1 go build -a -o $APP_ROOT/src/alert-system github.com/bitcoin-s # Copy the controller-manager into a thin image FROM registry.access.redhat.com/ubi9-minimal WORKDIR / +RUN mkdir /.bitcoin +RUN touch /.bitcoin/alert_system_private_key COPY --from=builder /opt/app-root/src/alert-system . +COPY example_settings_local.conf settings_local.conf USER 65534:65534 CMD ["/alert-system"] diff --git a/README.md b/README.md index ad23b6f..5440dbc 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,14 @@ $ cp example_settings_local.conf settings_local.conf $ go run cmd/main.go ``` -TODO: Running with docker: +### Running with docker: +``` +$ touch +$ docker run -u root -e P2P_ALERT_SYSTEM_PROTOCOL_ID=/bitcoin/alert-system/0.0.1 -e P2P_BOOTSTRAP_PEER=/ip4/68.183.57.231/tcp/9906/p2p/12D3KooWQs6ptKvoKNHurCzqRaVp3uFs9731NQwS3AmVcNc2TGpb -e P2P_PORT=9906 -e P2P_IP=0.0.0.0 -v :/alert_system_datastore.db docker.io/galtbv/alert-system:0.0.1 +``` + +### Running with Podman +``` +$ touch +$ podman run -u root -e P2P_ALERT_SYSTEM_PROTOCOL_ID=/bitcoin/alert-system/0.0.1 -e P2P_BOOTSTRAP_PEER=/ip4/68.183.57.231/tcp/9906/p2p/12D3KooWQs6ptKvoKNHurCzqRaVp3uFs9731NQwS3AmVcNc2TGpb -e P2P_PORT=9906 -e P2P_IP=0.0.0.0 -v /git/alert-system/foo.db:/alert_system_datastore.db:Z docker.io/galtbv/alert-system:0.0.1 +``` diff --git a/app/config/load.go b/app/config/load.go index a4c9149..64ee505 100644 --- a/app/config/load.go +++ b/app/config/load.go @@ -15,6 +15,13 @@ import ( // LoadConfig will load the configuration and services // models is a list of models to auto-migrate when the datastore is created func LoadConfig(ctx context.Context, models []interface{}, isTesting bool) (_appConfig *Config, err error) { + var ok bool + + dbPath := "" + // Load the database path + if dbPath, ok = gocore.Config().Get("ALERT_SYSTEM_DATABASE_PATH"); !ok { + dbPath = DatabasePathDefault + } // Sync the configuration struct _appConfig = &Config{ @@ -33,7 +40,7 @@ func LoadConfig(ctx context.Context, models []interface{}, isTesting bool) (_app TablePrefix: DatabasePrefix, }, Shared: false, - DatabasePath: DatabasePathDefault, + DatabasePath: dbPath, }, }, WebServer: &WebServerConfig{ @@ -49,8 +56,6 @@ func LoadConfig(ctx context.Context, models []interface{}, isTesting bool) (_app Logger: gocore.Log(ApplicationName), } - var ok bool - // Load the RPC user if _appConfig.RPCUser, ok = gocore.Config().Get("RPC_USER"); !ok { return nil, ErrNoRPCUser diff --git a/cmd/main.go b/cmd/main.go index 487a081..cbfa959 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,6 +3,7 @@ package main import ( "context" + "log" "os" "os/signal" @@ -19,7 +20,7 @@ func main() { // Load the configuration and services _appConfig, err := config.LoadConfig(context.Background(), models.BaseModels, false) if err != nil { - _appConfig.Services.Log.Fatalf("error loading configuration: %s", err.Error()) + log.Fatalf("error loading configuration: %s", err.Error()) } defer func() { _appConfig.CloseAll(context.Background())