-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
119 lines (90 loc) · 2.36 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
###
# Project commands
##
# Variables
## Defaults
ENV_FILE ?= .env
PACKAGE_INFO ?= .package-info
DOCKER_SERVER =
DOCKER_USERNAME =
DOCKER_PASSWORD =
## Load the environment
ifneq (,$(wildcard $(ENV_FILE)))
include $(ENV_FILE)
export $(shell sed 's/=.*//' $(ENV_FILE))
endif
APP_NAME = $(shell grep 'APP_NAME = ' $(PACKAGE_INFO) | sed 's/APP_NAME = //g')
VERSION = $(shell grep 'VERSION = ' $(PACKAGE_INFO) | sed 's/VERSION = //g')
DOCKER_TAG ?= $(DOCKER_USERNAME)/$(APP_NAME)
# Helpers
.PHONY: *
help:
@echo "Usage: make <command>"
@echo ""
@echo " .env Creates the .env file from .env.example"
@echo " build Builds the docker image"
@echo " shell Starts a shell in the docker image"
@echo ""
# help
.DEFAULT_GOAL := help
.env:
cp .env.example .env
# .env
version:
@echo $(VERSION)
# version
# DOCKER TASKS
# Builds the docker image
build:
docker build -t $(APP_NAME) .
# build
# Builds the docker image without cache
build-nc:
docker build --no-cache -t $(APP_NAME) .
# build-nc
## Publishes the docker image to the docker hub
release: build-nc publish
# Docker publish
LOGIN_CMD := "docker login"
ifneq (,$(DOCKER_USERNAME))
LOGIN_CMD += " --username $(DOCKER_USERNAME)"
endif
ifneq (,$(DOCKER_PASSWORD))
LOGIN_CMD += " --password $(DOCKER_PASSWORD)"
endif
ifneq (,$(DOCKER_SERVER))
LOGIN_CMD += " $(DOCKER_SERVER)"
endif
login:
@eval $(LOGIN_CMD)
# login
## Publish the `{version}` ans `latest` tagged containersto ECR
publish: login publish-latest publish-version
## Publish the `latest` taged container to ECR
publish-latest: tag-latest
@echo 'publish latest to $(DOCKER_TAG)'
docker push $(DOCKER_TAG):latest
# publish-latest
## Publish the `{version}` taged container to ECR
publish-version: tag-version
@echo 'publish $(VERSION) to $(DOCKER_TAG)'
docker push $(DOCKER_TAG):$(VERSION)
# publish-version
# Docker tagging
## Generate container tags for the `{version}` ans `latest` tags
tag: tag-latest tag-version
## Generate container `{version}` tag
tag-latest: build
@echo 'create tag latest'
docker tag $(APP_NAME) $(DOCKER_TAG):latest
# tag-latest
## Generate container `latest` tag
tag-version: build
@echo 'create tag $(VERSION)'
docker tag $(APP_NAME) $(DOCKER_TAG):$(VERSION)
# tag-version
# Starts a shell in the docker image
shell: build .env
docker run -it -v $(PWD):/srv -w /srv --env-file $(ENV_FILE) $(DOCKER_TAG) sh
# shell
# Makefile