-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
39 lines (30 loc) · 1.19 KB
/
Makefile
File metadata and controls
39 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
AWS_ACCOUNT_ID ?= 489702352871
REGION ?= us-west-2
REPO_NAME ?= troutlytics-api
REGISTRY := $(AWS_ACCOUNT_ID).dkr.ecr.$(REGION).amazonaws.com
IMAGE_LOCAL ?= api-prod:latest
IMAGE_REMOTE := $(REGISTRY)/$(REPO_NAME):latest
DOCKER_COMPOSE ?= docker compose
.PHONY: build login ensure-repo tag push publish
# Build the API image defined in docker-compose.yml (api-prod service).
build:
$(DOCKER_COMPOSE) build api-prod
# Authenticate Docker to ECR.
login:
aws ecr get-login-password --region $(REGION) | docker login --username AWS --password-stdin $(REGISTRY)
# Create the ECR repo if it does not already exist.
ensure-repo:
aws ecr describe-repositories --repository-names $(REPO_NAME) --region $(REGION) >/dev/null 2>&1 || \
aws ecr create-repository --repository-name $(REPO_NAME) --region $(REGION)
# Tag the built image for ECR.
tag: build
docker tag $(IMAGE_LOCAL) $(IMAGE_REMOTE)
updateLambda:
aws lambda update-function-code \
--function-name troutlytics-api \
--image-uri 489702352871.dkr.ecr.us-west-2.amazonaws.com/troutlytics-api:latest
# Push the image to ECR.
push: login ensure-repo tag
docker push $(IMAGE_REMOTE)
# Full pipeline: build, tag, and push.
publish: push