46 lines
1.7 KiB
Makefile

PGSQL_CONTAINER_ID=`cat postgres.container.id`
ECR_ACCOUNT_URL=063932952339.dkr.ecr.us-west-2.amazonaws.com
DB_NAME="personal_measure"
VERSION=`git describe`
SOURCES=$(wildcard src/main/nim/*.nim) $(wildcard src/main/nim/personal_measure_apipkg/*.nim)
serve-local: personal_measure_api start-postgres
./personal_measure_api serve
serve-docker: personal_measure_api-image start-postgres
docker run -e AUTH_SECRET=abc123 -e "DB_CONN_STRING=host=host.docker.internal port=5500 user=postgres password=password dbname=personal_measure" -e PORT=80 -p 127.0.0.1:8100:80/tcp $(ECR_ACCOUNT_URL)/personal_measure_api:$(VERSION)
postgres.container.id:
docker run --name postgres-$(DB_NAME) -e POSTGRES_PASSWORD=password -p 5500:5432 -d postgres > postgres.container.id
sleep 5
PGPASSWORD=password psql -p 5500 -U postgres -h localhost -c "CREATE DATABASE $(DB_NAME);"
db_migrate up -c database-local.json
start-postgres: postgres.container.id
docker start $(PGSQL_CONTAINER_ID)
sleep 1
db_migrate up -c database-local.json
stop-postgres: postgres.container.id
docker stop $(PGSQL_CONTAINER_ID)
delete-postgres-container:
-docker stop $(PGSQL_CONTAINER_ID)
docker container rm $(PGSQL_CONTAINER_ID)
rm postgres.container.id
connect:
PGPASSWORD=password psql -p 5500 -U postgres -h localhost ${DB_NAME}
ecr-auth:
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 063932952339.dkr.ecr.us-west-2.amazonaws.com
personal_measure_api: $(SOURCES)
nimble build
personal_measure_api-image: $(SOURCES)
docker image build -t $(ECR_ACCOUNT_URL)/personal_measure_api:$(VERSION) .
push-image: personal_measure_api-image
docker push $(ECR_ACCOUNT_URL)/personal_measure_api:$(VERSION)