This repository was archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakefile.common
82 lines (62 loc) · 3.01 KB
/
makefile.common
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
## Copyright (c) 2021, Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
# Version management
.PHONY: version
version: ## Output current version
@echo $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
.PHONY: update-version
update-version: version ## update the version file with new version
@read -p "New version? " ver; \
echo "$$ver" | awk -F"." '{ printf "MAJOR_VERSION=%s\nMINOR_VERSION=%s\nPATCH_VERSION=%s\n", $$1,$$2,$$3 }' > $(VERSION_FILE)
.PHONY: image-version
image-version: ## Output current image with version
@echo $(DOCKER_REPO)/$(APP_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
# DOCKER TASKS
.PHONY: build
build: ## Build the container
docker build -t $(APP_NAME) $(CURRENT_PATH)
.PHONY: build-nc
build-nc: ## Build the container without caching
docker build --no-cache --pull -t $(APP_NAME) $(CURRENT_PATH)
.PHONY: up
up: build run ## Run container on port configured in `config.env` (Alias to run)
.PHONY: stop
stop: ## Stop and remove a running container
docker stop $(APP_NAME); docker rm $(APP_NAME)
.PHONY: repo-login
repo-login: ## Login to the registry
@docker login -u "$(DOCKER_USERNAME)" -p "$(DOCKER_PASSWORD)" $(DOCKER_REPO)
.PHONY: release
release: build-nc publish ## Make a release by building and publishing the `{version}` ans `latest` tagged containers to registry
.PHONY: publish
publish: repo-login publish-latest publish-version ## Publish the `{version}` ans `latest` tagged containers to ECR
.PHONY: publish-latest
publish-latest: tag-latest ## Publish the `latest` tagged container
@echo 'publish latest to $(DOCKER_REPO)'
docker push $(DOCKER_REPO)/$(APP_NAME):latest
.PHONY: publish-version
publish-version: tag-version ## Publish the `{version}` tagged container
@echo 'publish $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) to $(DOCKER_REPO)'
docker push $(DOCKER_REPO)/$(APP_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
.PHONY: tag
tag: tag-latest tag-version ## Generate container tags for the `{version}` ans `latest` tags
.PHONY: tag-latest
tag-latest: ## Generate container `latest` tag
@echo 'create tag latest'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest
.PHONY: tag-version
tag-version: ## Generate container `{version}` tag
@echo 'create tag $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
.PHONY: pull-latest
pull-latest: repo-login ## pull latest tag
docker pull $(DOCKER_REPO)/$(APP_NAME):latest
DIGEST_CMD = "docker inspect --format='{{index .RepoDigests 0}}' $(DOCKER_REPO)/$(APP_NAME):latest"
.PHONY: digest
digest: ## Output latest image digest (! requires published image)
$(eval DIGEST = $(shell eval $(DIGEST_CMD)))
@echo $(DIGEST)
.PHONY: digest-sha
digest-sha: ## Output latest image digest sha (! requires published image)
$(eval DIGEST_SHA = $(shell eval $(DIGEST_CMD) | awk -F"@" '{print $$2}'))
@echo $(DIGEST_SHA)