-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
115 lines (89 loc) · 3.67 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
###################################################################################################
# Makefile to control building images for docker/k8s use
# - Emotional Support Pizza
###################################################################################################
###############################################################################
# Variables and Constants
###############################################################################
# enable the use of buildkit for multiarch builds
export DOCKER_BUILDKIT=1
# git related stuff here
GIT_REPO?=esp_project
GIT_TAG?=$(shell git rev-parse --short HEAD)
# Docker stuff
HUB_USER?=iammrcupp
HUB_REPO?=${GIT_REPO}
HUB_PULL_SECRET?=$(shell docker secret list | grep DockerHub | cut -f1 -d' ')
TAG?=${GIT_TAG}
# for local dev
DEV_LOCAL_IMAGE?=${HUB_REPO}:edge
# images for docker hub
DEV_IMAGE?=${HUB_USER}/${HUB_REPO}:edge
PROD_IMAGE?=${HUB_USER}/${HUB_REPO}:${TAG}
PROD_IMAGE_LATEST?=${HUB_USER}/${HUB_REPO}:latest
# images for ghcr.io
GHCR_DEV_IMAGE?=${HUB_USER}/${HUB_REPO}:edge
GHCR_PROD_IMAGE?=${HUB_USER}/${HUB_REPO}:${TAG}
GHCR_PROD_IMAGE_LATEST?=${HUB_USER}/${HUB_REPO}:latest
BUILDX_PLATFORMS?=linux/amd64,linux/arm64,linux/arm/v7
###############################################################################
# make stuff here
###############################################################################
# build image locally and use it for DEV purposes
.PHONY: dev
dev:
@COMPOSE_DOCKER_CLI_BUILD=1 IMAGE=${DEV_LOCAL_IMAGE} docker-compose -f docker-compose.yaml up --build --force-recreate
# run unit tests
.PHONY: build-test unit-test test
unit-test:
@docker --context default build --progress plain --target test .
test: unit-test
# build production image
.PHONY: build
build:
@docker --context default build --target prod --tag ${PROD_IMAGE} .
# push the image to registry
.PHONY: push
push:
@docker --context default push ${PROD_IMAGE}
# run PRODUCTION locally
.PHONY: deploy run logs down
run:
@IMAGE=${PROD_IMAGE} docker-compose -f docker-compose.yaml up -d
logs:
@IMAGE=${PROD_IMAGE} docker-compose -f docker-compose.yaml logs
down:
@IMAGE=${PROD_IMAGE} docker-compose -f docker-compose.yaml down
deploy: build push check-env
@HUB_PULL_SECRET=${HUB_PULL_SECRET} IMAGE=${PROD_IMAGE} docker compose up
# remove and cleanup DEV environment
.PHONY: clean
clean:
@docker-compose -f docker-compose.yaml down
@docker rmi ${DEV_IMAGE} || true
@docker builder prune --force --filter type=exec.cachemount --filter unused-for=24h
.PHONY: check-env
check-env:
ifndef HUB_PULL_SECRET
$(error HUB_PULL_SECRET is undefined. Ensure this has the proper API access token)
endif
# build multi-arch containers
.PHONY: cross-build cross-build-dev
cross-build:
@docker buildx create --name mutiarchbuilder --use
@docker buildx build --platform ${BUILDX_PLATFORMS} -t ${PROD_IMAGE} -t ${PROD_IMAGE_LATEST} --push .
cross-build-latest:
@docker buildx create --name mutiarchbuilder --use
@docker buildx build --platform ${BUILDX_PLATFORMS} -t ${PROD_IMAGE_LATEST} --push .
cross-build-dev:
@docker buildx create --name mutiarchbuilder --use
@docker buildx build --platform ${BUILDX_PLATFORMS} -t ${DEV_IMAGE} --push .
cross-build-ghcr:
@docker buildx create --name mutiarchbuilder --use
@docker buildx build --platform ${BUILDX_PLATFORMS} -t ${GHCR_PROD_IMAGE} -t ${GHCR_PROD_IMAGE_LATEST} --push .
cross-build-latest-ghcr:
@docker buildx create --name mutiarchbuilder --use
@docker buildx build --platform ${BUILDX_PLATFORMS} -t ${GHCR_PROD_IMAGE_LATEST} --push .
cross-build-dev-ghcr:
@docker buildx create --name mutiarchbuilder --use
@docker buildx build --platform ${BUILDX_PLATFORMS} -t ${GHCR_DEV_IMAGE} --push .