2021-10-24 22:23:39 +00:00
|
|
|
SOURCES=$(wildcard src/*.nim) $(wildcard src/hff_entry_forms_apipkg/*.nim)
|
|
|
|
|
|
|
|
# AWS Account URL for the ECR repository
|
|
|
|
ECR_ACCOUNT_URL ?= 063932952339.dkr.ecr.us-west-2.amazonaws.com
|
|
|
|
|
|
|
|
# The port on the host machine (not the container)
|
2024-08-12 18:18:02 +00:00
|
|
|
ifeq ($(TARGET_ENV),prod)
|
|
|
|
PORT=6006
|
|
|
|
else
|
|
|
|
PORT=6005
|
|
|
|
endif
|
|
|
|
|
|
|
|
# The server to target when publishing the API
|
|
|
|
TARGET_SERVER ?= sobeck.jdb-software.com
|
2021-10-24 22:23:39 +00:00
|
|
|
|
2024-08-12 20:46:52 +00:00
|
|
|
TARGET_ENV ?= local
|
|
|
|
|
2021-10-24 22:23:39 +00:00
|
|
|
# The Notion integration token.
|
|
|
|
AUTH_SECRET ?= 123abc
|
|
|
|
|
|
|
|
VERSION ?=`git describe`
|
|
|
|
|
|
|
|
default: serve-docker
|
|
|
|
|
|
|
|
# Running the API locally on bare metal
|
|
|
|
# -------------------------------------
|
|
|
|
|
|
|
|
hff_entry_forms_api: $(SOURCES)
|
|
|
|
nimble build
|
|
|
|
|
|
|
|
# Run the API on this machine. Note that configuration is taken by default
|
|
|
|
# from the `hff_entry_forms_api.config.json` file, but environment variables
|
|
|
|
# specified when running make can be used to override these (to change the
|
2021-10-25 14:34:00 +00:00
|
|
|
# INTEGRATION_TOKEN, for example).
|
2021-10-24 22:23:39 +00:00
|
|
|
serve: hff_entry_forms_api
|
|
|
|
./hff_entry_forms_api serve --debug
|
|
|
|
|
|
|
|
# Run tests
|
|
|
|
# ---------
|
|
|
|
#unittest:
|
|
|
|
# nim c -r src/unittest/nim/runner
|
|
|
|
#
|
|
|
|
#functest: DB_NAME = live_budget_test
|
|
|
|
#functest: DB_CONFIG = test
|
|
|
|
#functest: hff_entry_forms_api start-postgres
|
|
|
|
# echo "\n--------" >> functest-api-server.log
|
|
|
|
# ./hff_entry_forms_api serve --config hff_entry_forms_api.config.test.json >> functest-api-server.log &
|
|
|
|
# -nim c -r src/functest/nim/runner "$(TEST_NAME)"
|
|
|
|
# curl -s -X POST localhost:$(PORT)/api/v1/control/shutdown | jq .
|
|
|
|
# db_migrate down -c database-$(DB_CONFIG).json
|
|
|
|
# PGPASSWORD=password psql -p 5500 -U postgres -h localhost -c "DROP DATABASE $(DB_NAME);"
|
|
|
|
|
|
|
|
# Building and deploying the API container image
|
|
|
|
# ----------------------------------------------
|
|
|
|
|
|
|
|
# Build the container image.
|
|
|
|
build-image: $(SOURCES)
|
|
|
|
docker image build -t $(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION) .
|
|
|
|
|
|
|
|
# Push the container image to the private AWS ECR
|
|
|
|
push-image: build-image
|
|
|
|
docker push $(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION)
|
|
|
|
|
|
|
|
# Running locally in a container
|
|
|
|
# --------------------------------------
|
|
|
|
|
|
|
|
# Run the API in a docker container. Note that the configuration loaded into
|
|
|
|
# the Docker container defines very little of the actual configuration as
|
|
|
|
# environment variables are used in the deployed environments. Accordingly,
|
|
|
|
# we must specify them explicitly here.
|
|
|
|
serve-docker: build-image
|
|
|
|
docker run \
|
|
|
|
-e INTEGRATION_TOKEN=$(INTEGRATION_TOKEN) \
|
|
|
|
-e PORT=80 \
|
|
|
|
-p 127.0.0.1:$(PORT):80/tcp \
|
|
|
|
$(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION)
|
|
|
|
|
|
|
|
# Utility
|
|
|
|
# -------
|
|
|
|
|
2021-11-16 12:37:58 +00:00
|
|
|
clean:
|
|
|
|
-docker image rm $(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION)
|
|
|
|
|
2021-10-24 22:23:39 +00:00
|
|
|
# Authenticate docker to the AWS private elastic container repository.
|
|
|
|
ecr-auth:
|
|
|
|
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $(ECR_ACCOUNT_URL)
|
|
|
|
|
|
|
|
echo-vars:
|
|
|
|
@echo \
|
|
|
|
" ECR_ACCOUNT_URL=$(ECR_ACCOUNT_URL)\n" \
|
|
|
|
"VERSION=$(VERSION)\n" \
|
|
|
|
"PORT=$(PORT)\n" \
|
|
|
|
"INTEGRATION_TOKEN=$(INTEGRATION_TOKEN)\n"
|
2024-08-12 17:14:01 +00:00
|
|
|
|
2024-08-12 19:45:49 +00:00
|
|
|
publish:
|
2024-08-12 17:14:01 +00:00
|
|
|
-rm -r deploy
|
|
|
|
-mkdir deploy
|
|
|
|
m4 \
|
|
|
|
-D "HFF_ENTRY_FORMS_API_VERSION=$(VERSION)" \
|
|
|
|
-D "TARGET_ENV=$(TARGET_ENV)" \
|
2024-08-12 19:45:49 +00:00
|
|
|
-D "TARGET_PORT=$(PORT)" \
|
2024-08-12 17:14:01 +00:00
|
|
|
hff_entry_forms_api.service \
|
|
|
|
> deploy/hff_entry_forms_api.$(TARGET_ENV).service
|
2024-08-12 19:45:49 +00:00
|
|
|
-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)"
|
2024-08-12 17:14:01 +00:00
|
|
|
scp \
|
2024-08-12 19:45:49 +00:00
|
|
|
deploy/hff_entry_forms_api.$(TARGET_ENV).service \
|
|
|
|
deployer@$(TARGET_SERVER):/etc/systemd/system/hff_entry_forms_api.$(TARGET_ENV).service
|
2024-08-12 17:14:01 +00:00
|
|
|
ssh deployer@$(TARGET_SERVER) "sudo systemctl daemon-reload"
|
2024-08-12 19:45:49 +00:00
|
|
|
ssh deployer@$(TARGET_SERVER) "sudo systemctl start hff_entry_forms_api.$(TARGET_ENV)"
|