From f9184379b257932c7f188a1465b63d9ca8684b56 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 12 Aug 2024 14:45:49 -0500 Subject: [PATCH] api: Fix file naming, add support for DEBUG env var. --- .gitignore | 1 + api/Makefile | 14 +++++++------- ...y_forms.service => hff_entry_forms_api.service} | 2 +- api/src/hff_entry_forms_api.nim | 11 ++++++----- 4 files changed, 15 insertions(+), 13 deletions(-) rename api/{hff_entry_forms.service => hff_entry_forms_api.service} (79%) diff --git a/.gitignore b/.gitignore index 87cb9c2..4a2ab3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store .terraform node_modules +/api/deploy /web/dist /dist diff --git a/api/Makefile b/api/Makefile index 9c4d2b7..94a7a9b 100644 --- a/api/Makefile +++ b/api/Makefile @@ -90,19 +90,19 @@ echo-vars: "PORT=$(PORT)\n" \ "INTEGRATION_TOKEN=$(INTEGRATION_TOKEN)\n" -publis: +publish: -rm -r deploy -mkdir deploy m4 \ -D "HFF_ENTRY_FORMS_API_VERSION=$(VERSION)" \ -D "TARGET_ENV=$(TARGET_ENV)" \ - -D "TARGET_PORT=$(TARGET_PORT)" \ + -D "TARGET_PORT=$(PORT)" \ hff_entry_forms_api.service \ > deploy/hff_entry_forms_api.$(TARGET_ENV).service - -ssh deployer@$(TARGET_SERVER) "docker stop hff_entry_forms.$(TARGET_ENV).service && sudo systemctl stop hff_entry_forms.$(TARGET_ENV)" - ssh deployer@$(TARGET_SERVER) "aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $(ECR_ACCOUNT_URL) && docker pull $(ECR_ACCOUNT_URL)/hff_entry_forms:$(VERSION)" + -ssh deployer@$(TARGET_SERVER) "docker stop hff_entry_forms_api.$(TARGET_ENV).service && sudo systemctl stop hff_entry_forms_api.$(TARGET_ENV)" + ssh deployer@$(TARGET_SERVER) "aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $(ECR_ACCOUNT_URL) && docker pull $(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION)" scp \ - deploy/hff_entry_forms.$(TARGET_ENV).service \ - deployer@$(TARGET_SERVER):/etc/systemd/system/hff_entry_forms.$(TARGET_ENV).service + deploy/hff_entry_forms_api.$(TARGET_ENV).service \ + deployer@$(TARGET_SERVER):/etc/systemd/system/hff_entry_forms_api.$(TARGET_ENV).service ssh deployer@$(TARGET_SERVER) "sudo systemctl daemon-reload" - ssh deployer@$(TARGET_SERVER) "sudo systemctl start hff_entry_forms.$(TARGET_ENV)" + ssh deployer@$(TARGET_SERVER) "sudo systemctl start hff_entry_forms_api.$(TARGET_ENV)" diff --git a/api/hff_entry_forms.service b/api/hff_entry_forms_api.service similarity index 79% rename from api/hff_entry_forms.service rename to api/hff_entry_forms_api.service index d8c1314..5da0d9c 100644 --- a/api/hff_entry_forms.service +++ b/api/hff_entry_forms_api.service @@ -9,7 +9,7 @@ Restart=always ExecStartPre=-/usr/bin/docker rm %n ExecStart=/usr/bin/docker run --rm -p TARGET_PORT:80 --name %n \ --env-file /etc/hff_entry_forms/TARGET_ENV.env \ - 063932952339.dkr.ecr.us-west-2.amazonaws.com/hff_entry_forms:HFF_ENTRY_FORMS_VERSION + 063932952339.dkr.ecr.us-west-2.amazonaws.com/hff_entry_forms_api:HFF_ENTRY_FORMS_API_VERSION ExecStop=/usr/bin/docker stop --name %n [Install] diff --git a/api/src/hff_entry_forms_api.nim b/api/src/hff_entry_forms_api.nim index 4164233..c51a2dd 100644 --- a/api/src/hff_entry_forms_api.nim +++ b/api/src/hff_entry_forms_api.nim @@ -1,4 +1,5 @@ -import cliutils, docopt, json, logging, sequtils, strutils, tables +import std/[json, logging, os, sequtils, strutils, tables] +import cliutils, docopt import hff_entry_forms_apipkg/api import hff_entry_forms_apipkg/version @@ -26,7 +27,7 @@ proc loadConfig(args: Table[string, docopt.Value]): HffEntryFormsApiConfig = let cfg = CombinedConfig(docopt: args, json: json) result = HffEntryFormsApiConfig( - debug: args["--debug"], + debug: cfg.hasKey("debug") and cfg.getVal("debug") == "true", eventParentId: cfg.getVal("event-parent-id"), integrationToken: cfg.getVal("integration-token"), knownOrigins: cfg.getVal("known-origins")[1..^2].split(',').mapIt(it[1..^2]), @@ -59,11 +60,11 @@ Options: # Initialize our service context let args = docopt(doc, version = HFF_ENTRY_FORMS_API_VERSION) - if args["--debug"]: - consoleLogger.levelThreshold = lvlDebug - let cfg = loadConfig(args) + if cfg.debug: + consoleLogger.levelThreshold = lvlDebug + if args["serve"]: start(cfg) except: