hff-entry-forms/api/Makefile

85 lines
2.7 KiB
Makefile

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)
PORT ?= 8300
# 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
# INTEGRATION_TOKEN, for example).
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
# -------
clean:
-docker image rm $(ECR_ACCOUNT_URL)/hff_entry_forms_api:$(VERSION)
# 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"