-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
88 lines (66 loc) · 2.5 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
#!/bin/bash
# Build a container via the command "make build"
# By Jason Gegere <[email protected]>
bold=\033[1m
normal=\033[00m
include .env # .env file needs to created for this to work properly
TAG = 1.9.0
CONTAINER = apache
IMAGE_REPO = htmlgraphic
IMAGE_NAME = $(IMAGE_REPO)/$(CONTAINER)
NODE_ENV=$(shell grep NODE_ENVIRONMENT .env | cut -d '=' -f 2-)
ifeq ($(NODE_ENV),dev)
COMPOSE_FILE = docker-compose.local.yml
else
COMPOSE_FILE = docker-compose.yml
endif
all:: help
help:
@echo ""
@echo "-- Help Menu for $(IMAGE_NAME):$(TAG)"
@echo ""
@echo " make build - Build Image"
@echo " make push - Push $(IMAGE_NAME):$(TAG) to public Docker repo"
@echo " make run - Run docker-compose and create local development environment"
@echo " make start - Start the EXISTING $(CONTAINER) container"
@echo " make stop - Stop running containers"
@echo " make state - View state $(CONTAINER) container"
@echo " make logs - View logs"
env:
@[ ! -f .env ] && echo " .env file does not exist, copy env template \n" && cp .env.example .env || echo " env file exists \n"
@echo "The following environment varibles exist:"
@echo $(shell sed 's/=.*//' .env)
@echo ''
build:
@make env
docker build --no-cache \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--rm -t $(IMAGE_NAME):$(TAG) -t $(IMAGE_NAME):latest .
push:
@echo "note: If the repository is set as an automatted build you will NOT be able to push"
docker push $(IMAGE_NAME):$(TAG)
run:
@echo "Setting environment varibles...\n"
@make env
@echo "Checking... initial directory structure \n"
@if [ $(NODE_ENV) == 'dev' ]; then \
if [ ! -d "~/SITES/docker" ]; then \
echo " Creating project folders \n" && sudo mkdir -p ~/SITES/docker && sudo chmod 777 ~/SITES/docker ; fi \
fi
@echo "${bold}Run the following on the MySQL container, to setup a GLOBAL admin:${normal}\n"
@echo " THE PASSWORD FOR ${bold}$(MYSQL_USER)${normal} IS ${bold}$(MYSQL_PASSWORD)${normal};"
@echo ''
@echo " docker exec -it apache_db /bin/bash \n \
mysql -p '$(MYSQL_ROOT_PASSWORD)' \n \
GRANT ALL PRIVILEGES ON * . * TO '$(MYSQL_USER)'@'%' with grant option; \n"
docker-compose -f $(COMPOSE_FILE) up -d --remove-orphans
start: run
stop:
@echo "containers are specifically referenced, as to not destroy ANY persistent data"
docker-compose down --remove-orphans
state:
docker ps -a | grep $(CONTAINER)
logs:
@echo "Build $(CONTAINER)..."
docker logs -f $(CONTAINER)