operations: terraform to standup prod infrastructure.
This commit is contained in:
20
api/Dockerfile
Normal file
20
api/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
FROM 063932952339.dkr.ecr.us-west-2.amazonaws.com/alpine-nim:nim-1.4.8 AS build
|
||||
MAINTAINER jonathan@jdbernard.com
|
||||
|
||||
COPY hff_entry_forms_api.nimble /hff_entry_forms_api/
|
||||
COPY src /hff_entry_forms_api/src
|
||||
WORKDIR /hff_entry_forms_api
|
||||
RUN nimble build -y
|
||||
|
||||
FROM alpine
|
||||
EXPOSE 80
|
||||
RUN apk -v --update add --no-cache \
|
||||
ca-certificates \
|
||||
libcrypto1.1 \
|
||||
libssl1.1 \
|
||||
pcre \
|
||||
postgresql-client
|
||||
|
||||
COPY --from=build /hff_entry_forms_api/hff_entry_forms_api /
|
||||
COPY hff_entry_forms_api.config.docker.json /hff_entry_forms_api.config.json
|
||||
CMD ["/hff_entry_forms_api", "serve"]
|
81
api/Makefile
Normal file
81
api/Makefile
Normal file
@ -0,0 +1,81 @@
|
||||
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
|
||||
# DB_CONN_STRING, 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
|
||||
# -------
|
||||
|
||||
# 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"
|
7
api/hff_entry_forms_api.config.docker.json
Normal file
7
api/hff_entry_forms_api.config.docker.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"eventParentId": "ffff5ca5cb0547b6a99fb78cdb9b0170",
|
||||
"knownOrigins": [ "https://forms.hopefamilyfellowship.com" ],
|
||||
"notionApiBaseUrl": "https://api.notion.com/v1",
|
||||
"notionVersion": "2021-08-16",
|
||||
"port": 80
|
||||
}
|
@ -26,7 +26,7 @@ proc loadConfig(args: Table[string, docopt.Value]): HffEntryFormsApiConfig =
|
||||
let cfg = CombinedConfig(docopt: args, json: json)
|
||||
|
||||
result = HffEntryFormsApiConfig(
|
||||
debug: parseBool(cfg.getVal("debug")),
|
||||
debug: args["--debug"],
|
||||
eventParentId: cfg.getVal("event-parent-id"),
|
||||
integrationToken: cfg.getVal("integration-token"),
|
||||
knownOrigins: cfg.getVal("known-origins")[1..^2].split(',').mapIt(it[1..^2]),
|
||||
|
Reference in New Issue
Block a user