forked from airbnb/ottr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (103 loc) · 7.29 KB
/
Makefile
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
PATH := ${PATH}:/usr/bin:/usr/local/bin:/Library/Developer/CommandLineTools/usr/bin
CURRENT_DIR = $(shell pwd)
OS_VERSION = $(shell uname)
VERSION := $(shell git describe --tags --always)
CONTAINERS_DIR = platforms
CONTAINERS_PREFIX = otter
CONTAINERS = $(shell find $(CONTAINERS_DIR) -type d -name template -prune -o -mindepth 1 -maxdepth 1 -exec basename {} \;)
.check-api-args:
ifndef PREFIX
$(error PREFIX is not set. please use `make {XXX} PREFIX=<YOUR_PREFIX>.`)
endif
ifndef AWS_ACCOUNT_ID
$(error AWS_ACCOUNT_ID is not set. please use `make {XXX} AWS_ACCOUNT_ID=<YOUR_PREFIX>.`)
endif
ifndef AWS_REGION
$(error AWS_REGION is not set. please use `make {XXX} AWS_REGION=<YOUR_PREFIX>.`)
endif
ifndef TABLE
$(error TABLE is not set. please use `make {XXX} TABLE=<YOUR_PREFIX>.`)
endif
.check-args:
ifndef AWS_REGION
$(error AWS_REGION is not set. please use `make {XXX} AWS_REGION=<YOUR_PREFIX>.`)
endif
ifndef AWS_ACCOUNT_ID
$(error AWS_ACCOUNT_ID is not set. please use `make {XXX} AWS_ACCOUNT_ID=<YOUR_PREFIX>.`)
endif
# ------------------------------------------------------------------------------
# Build and Push All Platform Containers
# ------------------------------------------------------------------------------
build-containers-release: .check-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
@for container in $(CONTAINERS); do \
echo "building $$container" ; \
docker build -t $(CONTAINERS_PREFIX)-$$container $(CONTAINERS_DIR)/$$container/. ;\
docker tag $(CONTAINERS_PREFIX)-$$container:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-$$container:latest ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-$$container:latest ; \
done
# ------------------------------------------------------------------------------
# Built Ottr Router Lambda
# ------------------------------------------------------------------------------
build-otter-router: .check-args
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t otter-infrastructure:router otter/router/.
docker tag otter-infrastructure:router $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-infrastructure:router ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-infrastructure:router ; \
# ------------------------------------------------------------------------------
# Build Ottr Handler Lambda
# ------------------------------------------------------------------------------
build-otter-handler: .check-args
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t otter-infrastructure:handler otter/handler/.
docker tag otter-infrastructure:handler $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-infrastructure:handler ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-infrastructure:handler ; \
# ------------------------------------------------------------------------------
# Build Ottr API
# ------------------------------------------------------------------------------
build-api: .check-api-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
AWS_REGION=${AWS_REGION} AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID} TABLE=${TABLE} PREFIX=${PREFIX} docker-compose -f api/docker-compose.yaml build
# API Server Image
docker tag otter-api:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-acme-api:server
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-acme-api:server
# Envoy Sidecar Image
docker tag otter-envoy:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-acme-api:envoy
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/otter-acme-api:envoy
aws ecs update-service --cluster otter --service otter-api-service --force-new-deployment
# ------------------------------------------------------------------------------
# Platform Specific Containers
# ------------------------------------------------------------------------------
build-panos-8.x: .check-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t $(CONTAINERS_PREFIX)-panos-8.x:latest $(CONTAINERS_DIR)/panos-8.x/.
docker tag $(CONTAINERS_PREFIX)-panos-8.x:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-panos-8.x:latest ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-panos-8.x:latest ; \
build-panos-9.x: .check-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t $(CONTAINERS_PREFIX)-panos-9.x:latest $(CONTAINERS_DIR)/panos-9.x/.
docker tag $(CONTAINERS_PREFIX)-panos-9.x:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-panos-9.x:latest ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-panos-9.x:latest ; \
build-f5-14.x: .check-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t $(CONTAINERS_PREFIX)-f5-14.x:latest $(CONTAINERS_DIR)/f5-14.x/.
docker tag $(CONTAINERS_PREFIX)-f5-14.x:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-f5-14.x:latest ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-f5-14.x:latest ; \
build-lighthouse-21.x: .check-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t $(CONTAINERS_PREFIX)-lighthouse-21.x:latest $(CONTAINERS_DIR)/lighthouse-21.x/.
docker tag $(CONTAINERS_PREFIX)-lighthouse-21.x:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-lighthouse-21.x:latest ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-lighthouse-21.x:latest ; \
build-linux-aws-ssm: .check-args
$(info *** build and upload containers to AWS ECR)
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
docker build -t $(CONTAINERS_PREFIX)-linux-aws-ssm:latest $(CONTAINERS_DIR)/linux-aws-ssm/.
docker tag $(CONTAINERS_PREFIX)-linux-aws-ssm:latest $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-linux-aws-ssm:latest ; \
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(CONTAINERS_PREFIX)-linux-aws-ssm:latest ; \
# .PHONY:build-containers-release