-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
95 lines (70 loc) · 2.09 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
CONTAINER_NAME=storybooks-api-server
run-local:
docker-compose up -d
docker-compose logs -f
teardown-local:
docker-compose down -v
RM=
stop-local:
docker container stop $(CONTAINER_NAME)
$(if $(RM),docker container rm $(CONTAINER_NAME))
###
ENV?=staging
check-env:
ifndef ENV
$(error Please set ENV=[staging|prod])
endif
###
terraform-create-workspace: check-env
cd terraform && \
terraform workspace new $(ENV)
terraform-init: check-env
cd terraform && \
terraform workspace select $(ENV) && \
terraform init
TF_ACTION?=plan
terraform-action: check-env
@cd terraform && \
terraform workspace select $(ENV) && \
terraform $(TF_ACTION) \
-var-file="./environments/common.tfvars"
###
GITHUB_SHA?=latest
APP_NAME=
LOCAL_TAG=storybooks-app:$(GITHUB_SHA)
REMOTE_TAG=$(DOCKERHUB_USERNAME)/$(LOCAL_TAG)
HEROKU_REMOTE_TAG=registry.heroku.com/$(APP_NAME)
check-app-name:
ifndef APP_NAME
$(error Please set APP_NAME)
endif
build:
docker build --rm -t $(LOCAL_TAG) .
push:
echo "tagging docker image..."
docker tag $(LOCAL_TAG) $(REMOTE_TAG)
echo "pushing image to dockerhub..."
docker push $(REMOTE_TAG)
heroku-push: check-app-name
echo "pulling new container image..."
docker pull $(REMOTE_TAG)
echo "removing old container image"
-docker rmi $(HEROKU_REMOTE_TAG)
echo "tagging new image..."
docker tag $(REMOTE_TAG) $(HEROKU_REMOTE_TAG)
echo "pushing new image to heroku..."
docker push $(HEROKU_REMOTE_TAG)
IMAGE_ID=`docker inspect $(HEROKU_REMOTE_TAG) --format={{.Id}}`
deploy: check-app-name
echo "releasing new image..."
@curl --write-out '%{http_code}' --fail --silent --output /dev/null \
-X PATCH https://api.heroku.com/apps/$(APP_NAME)/formation \
-H 'Content-Type:application/json' \
-H 'Accept:application/vnd.heroku+json; version=3.docker-releases' \
-H "Authorization:Bearer $(HEROKU_API_KEY)" \
-d '{"updates": [{"type": "web","docker_image": "$(IMAGE_ID)"}]}'
run-deploy: check-app-name
@$(MAKE) deploy IMAGE_ID=$(IMAGE_ID)
check-app-health: check-app-name
chmod u+r+x ./scripts/health-check
@sh -c "./scripts/health-check https://$(APP_NAME).herokuapp.com/"