-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (75 loc) · 3.38 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
# Install the app
install: docker-down-clear docker-pull docker-build docker-up api-init
# Alias to start up the app
up: docker-up
# Alias to shut down the app
down: docker-down
# Restart the app
restart: down up
# Start up the app
docker-up:
docker-compose up --detach
# Shut down the app
docker-down:
docker-compose down --remove-orphans
# Pull docker containers
docker-pull:
docker-compose pull
# Build docker containers
docker-build:
docker-compose build
# Shut down the app and remove all volumes
docker-down-clear:
docker-compose down --volumes --remove-orphans
# Init API services
api-init: api-composer-install
# Install composer dependencies for API
api-composer-install:
docker-compose run --rm api-php-cli composer install
# Build all services for production
build: build-gateway build-frontend build-api
# Build the gateway service
build-gateway:
docker --log-level=debug build --pull --file=gateway/docker/production/nginx/Dockerfile --tag=${REGISTRY}/auction-gateway:${IMAGE_TAG} gateway/docker
# Build the front-end service
build-frontend:
docker --log-level=debug build --pull --file=frontend/docker/production/nginx/Dockerfile --tag=${REGISTRY}/auction-frontend:${IMAGE_TAG} frontend
# Build the API service
build-api:
docker --log-level=debug build --pull --file=api/docker/production/nginx/Dockerfile --tag=${REGISTRY}/auction-api:${IMAGE_TAG} api
docker --log-level=debug build --pull --file=api/docker/production/php-fpm/Dockerfile --tag=${REGISTRY}/auction-api-php-fpm:${IMAGE_TAG} api
docker --log-level=debug build --pull --file=api/docker/production/php-cli/Dockerfile --tag=${REGISTRY}/auction-api-php-cli:${IMAGE_TAG} api
# Check the build process
try-build:
REGISTRY=localhost IMAGE_TAG=0 make build
# Push all built services
push: push-gateway push-frontend push-api
# Push the gateway built service
push-gateway:
docker push ${REGISTRY}/auction-gateway:${IMAGE_TAG}
# Push the front-end built service
push-frontend:
docker push ${REGISTRY}/auction-frontend:${IMAGE_TAG}
# Push the API built service
push-api:
docker push ${REGISTRY}/auction-api:${IMAGE_TAG}
docker push ${REGISTRY}/auction-api-php-fpm:${IMAGE_TAG}
docker push ${REGISTRY}/auction-api-php-cli:${IMAGE_TAG}
# Deploy the app
deploy:
ssh ${HOST} -p ${PORT} 'rm -rf site_${BUILD_NUMBER}'
ssh ${HOST} -p ${PORT} 'mkdir site_${BUILD_NUMBER}'
scp -P ${PORT} docker-compose-production.yml ${HOST}:site_${BUILD_NUMBER}/docker-compose-production.yml
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && echo "COMPOSE_PROJECT_NAME=auction" >> .env'
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && echo "REGISTRY=${REGISTRY}" >> .env'
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && echo "IMAGE_TAG=${IMAGE_TAG}" >> .env'
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && docker-compose -f docker-compose-production.yml pull'
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && docker-compose -f docker-compose-production.yml up --build --remove-orphans -d'
ssh ${HOST} -p ${PORT} 'rm -f site'
ssh ${HOST} -p ${PORT} 'ln -sr site_${BUILD_NUMBER} site'
# Rollback the production build
rollback:
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && docker-compose -f docker-compose-production.yml pull'
ssh ${HOST} -p ${PORT} 'cd site_${BUILD_NUMBER} && docker-compose -f docker-compose-production.yml up --build --remove-orphans -d'
ssh ${HOST} -p ${PORT} 'rm -f site'
ssh ${HOST} -p ${PORT} 'ln -sr site_${BUILD_NUMBER} site'