-
Notifications
You must be signed in to change notification settings - Fork 83
/
Makefile
82 lines (71 loc) · 2.98 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
VERSION ?= `cat VERSION | grep elixir | cut -d' ' -f2`
ERLANG_VERSION ?= `cat VERSION | grep erlang | cut -d' ' -f2`
MAJ_VERSION := $(shell echo $(VERSION) | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\(\.[0-9][0-9]*\)*/\1/')
MIN_VERSION := $(shell echo $(VERSION) | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\(\.[0-9][0-9]*\)*/\1.\2/')
IMAGE_NAME ?= bitwalker/alpine-elixir
XDG_CACHE_HOME ?= /tmp
BUILDX_CACHE_DIR ?= $(XDG_CACHE_HOME)/buildx
.PHONY: help
help:
@echo "$(IMAGE_NAME):$(VERSION)"
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: test
test: ## Test the Docker image
docker run --rm $(IMAGE_NAME):$(VERSION) elixir --version
.PHONY: shell
shell: ## Run an Elixir shell in the image
docker run --rm -it $(IMAGE_NAME):$(VERSION) iex
.PHONY: sh
sh: ## Boot to a shell prompt
docker run --rm -it $(IMAGE_NAME):$(VERSION) /bin/sh
.PHONY: setup-buildx
setup-buildx: ## Setup a Buildx builder
@mkdir -p "$(BUILDX_CACHE_DIR)"
@if ! docker buildx ls | grep buildx-builder >/dev/null; then \
docker buildx create --name buildx-builder --driver docker-container --use && \
docker buildx inspect --bootstrap --builder buildx-builder; \
fi
.PHONY: build
build: setup-buildx ## Build the Docker image
docker buildx build --output "type=image,push=false" \
--build-arg ERLANG_VERSION=$(ERLANG_VERSION) \
--build-arg ELIXIR_VERSION=$(VERSION) \
--platform linux/amd64 \
--cache-from "type=local,src=$(BUILDX_CACHE_DIR)" \
--cache-to "type=local,dest=$(BUILDX_CACHE_DIR)" \
-t $(IMAGE_NAME):$(VERSION) \
-t $(IMAGE_NAME):$(MIN_VERSION) \
-t $(IMAGE_NAME):$(MAJ_VERSION) \
-t $(IMAGE_NAME):latest .
.PHONY: build-local
build-local: setup-buildx ## Build the Docker image
docker buildx build --load \
--build-arg ERLANG_VERSION=$(ERLANG_VERSION) \
--build-arg ELIXIR_VERSION=$(VERSION) \
--platform linux/amd64 \
--cache-from "type=local,src=$(BUILDX_CACHE_DIR)" \
--cache-to "type=local,dest=$(BUILDX_CACHE_DIR)" \
-t $(IMAGE_NAME):$(VERSION) \
-t $(IMAGE_NAME):$(MIN_VERSION) \
-t $(IMAGE_NAME):$(MAJ_VERSION) \
-t $(IMAGE_NAME):latest .
.PHONY: validate
validate: build-local ## Build and test the amd64 image
docker run --rm $(IMAGE_NAME):$(VERSION) elixir --version
.PHONY: clean
clean: ## Clean up generated images
@docker rmi --force $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):$(MIN_VERSION) $(IMAGE_NAME):$(MAJ_VERSION) $(IMAGE_NAME):latest
.PHONY: rebuild
rebuild: clean build ## Rebuild the Docker image
.PHONY: release
release: setup-buildx ## Build and release the Docker image to Docker Hub
docker buildx build --push \
--build-arg ERLANG_VERSION=$(ERLANG_VERSION) \
--build-arg ELIXIR_VERSION=$(VERSION) \
--platform linux/amd64 \
--cache-from "type=local,src=$(BUILDX_CACHE_DIR)" \
--cache-to "type=local,dest=$(BUILDX_CACHE_DIR)" \
-t $(IMAGE_NAME):$(VERSION) \
-t $(IMAGE_NAME):$(MIN_VERSION) \
-t $(IMAGE_NAME):$(MAJ_VERSION) \
-t $(IMAGE_NAME):latest .