-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (55 loc) · 2.12 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
IMAGE_NAME := devsecops-toolkit
.DEFAULT_GOAL := help
# Get the latest release tag from git
LATEST_RELEASE := $(shell git describe --tags --abbrev=0)
include .env
BUILD_ARGS := $(foreach VAR,$(shell sed 's/=.*//' .env),--build-arg $(VAR)=$($(VAR)))
# Use buildx only in GitHub Actions
ifdef GITHUB_ACTIONS
DOCKER_BUILD_CMD := docker buildx build --load --cache-from type=gha --cache-to type=gha,mode=max
else
DOCKER_BUILD_CMD := docker build
endif
help:
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Targets:"
@echo " build Build the Docker image with the software versions described in the .env file"
@echo " rebuild Forces build, even if a previous image exists. Won't delete previous images"
@echo " release Build the Docker image with the software versions described in the .env file, but from a specific release of this repo"
@echo " exec Run an interactive shell inside the container"
@echo " clean Remove Docke image $(IMAGE_NAME) and wipe cache (CAREFUL)"
@echo ""
@echo "Examples:"
@echo " make"
@echo " make build"
@echo " make rebuild"
@echo " make release"
@echo " make exec"
@echo " make clean"
@echo ""
# Build the Docker image using current branch
build:
@if ! docker images $(IMAGE_NAME) | awk '{ print $$1 }' | grep -q "^$(IMAGE_NAME)$$"; then \
echo "Docker image $(IMAGE_NAME) not found. Building now..."; \
$(DOCKER_BUILD_CMD) $(BUILD_ARGS) -t $(IMAGE_NAME) .; \
else \
echo "Image found, not building. If you want to rebuild, run make rebuild"; \
fi
rebuild:
@echo "Rebuilding $(IMAGE_NAME) without cache, will take a while."
@$(DOCKER_BUILD_CMD) $(BUILD_ARGS) --no-cache -t $(IMAGE_NAME) .;
# Build the Docker image using the latest release
release:
@git checkout $(LATEST_RELEASE)
@$(MAKE) build
@git checkout -
# TODO: Check this.
exec: build
@echo "Running interactive shell inside the $(IMAGE_NAME) container..."
@docker run --hostname trg --rm -it -v $(PWD):/workdir $(IMAGE_NAME):latest /bin/zsh
clean:
@echo "Removing Docker image with the name $(IMAGE_NAME)..."
@docker rmi -f $(IMAGE_NAME) && docker builder prune -f
.PHONY: help build rebuild release exec clean