-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (51 loc) · 1.56 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
REMOTE ?= [email protected]
REMOTE_PATH ?= ~/apps/blog_api
STAGE ?= dev
# Expose env vars from .env to this Makefile
-include .env
.PHONY: .ensure-stage-exists
.ensure-stage-exists:
ifeq (,$(wildcard ./docker-compose.$(STAGE).yml))
@echo "Env $(STAGE) not supported."
@exit 1
endif
.PHONY: .validate-tag
.validate-tag:
ifneq ($(STAGE),dev)
ifeq ($(IMAGE_TAG),)
@echo "You can't build, push or deploy to production without an IMAGE_TAG.\n"
@exit 1
endif
endif
.PHONY: .remote-edit-env
.remote-edit-env:
ssh -t ${REMOTE} 'vim ${REMOTE_PATH}/.env'
.PHONY: cp-env
cp-env:
cp .env.dist .env
.PHONY:
install-deps:
docker-compose -f ./docker-compose.$(STAGE).yml run --rm api_php composer install
.PHONY:
start:
docker-compose -f ./docker-compose.$(STAGE).yml up
.PHONY: build
build: .ensure-stage-exists .validate-tag
docker-compose -f ./docker-compose.$(STAGE).yml build
.PHONY: push
push: .ensure-stage-exists .validate-tag
ifeq ($(STAGE),dev)
@echo "You can't push dev env to remote repo.\n"
@exit 1
endif
docker-compose -f ./docker-compose.$(STAGE).yml push
.PHONY: remote-deploy
remote-deploy: .ensure-stage-exists .validate-tag .remote-edit-env
scp ./docker-compose.$(STAGE).yml ${REMOTE}:${REMOTE_PATH}/docker-compose.$(STAGE).yml
ssh -t ${REMOTE} '\
cd ${REMOTE_PATH} && \
source ${REMOTE_PATH}/.env && \
export IMAGE_TAG=$(IMAGE_TAG) && \
docker-compose -f ./docker-compose.${STAGE}.yml pull --include-deps && \
docker-compose -f ./docker-compose.$(STAGE).yml up -d --no-build --remove-orphans && \
docker-compose -f ./docker-compose.$(STAGE).yml ps'