-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
120 lines (100 loc) · 3.11 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
120
DOCKER_CLI_EXPERIMENTAL := enabled
DOCKER_BUILDKIT := 1
USERNAME := peaceiris
DOCKER_IMAGE_NAME := hugo
DOCKER_HUB_BASE_NAME := ${USERNAME}/${DOCKER_IMAGE_NAME}
DOCKER_BASE_NAME := ghcr.io/${DOCKER_HUB_BASE_NAME}
DOCKER_HUGO_VERSION := $(shell cd ./deps && go mod edit -json | jq -r '.Require[] | select(.Path == "github.com/gohugoio/hugo") | .Version | split("v") | .[1]')
DOCKER_GOLANG_VERSION := 1.20
DOCKER_DEBIAN_VERSION := bookworm
TAG_SPEC := v${DOCKER_HUGO_VERSION}
DOCKER_SCOPE := action-image-${GITHUB_REF_NAME}
PKG_SPEC := ${DOCKER_BASE_NAME}:${TAG_SPEC}
HUB_SPEC := ${DOCKER_HUB_BASE_NAME}:${TAG_SPEC}
TAG_LATEST := latest
PKG_LATEST := ${DOCKER_BASE_NAME}:${TAG_LATEST}
HUB_LATEST := ${DOCKER_HUB_BASE_NAME}:${TAG_LATEST}
.PHONY: get-go-version
get-go-version:
@cd ./deps && go mod edit -json | jq -r '.Go'
.PHONY: login
login:
echo "${DOCKER_HUB_TOKEN}" | docker login -u peaceiris --password-stdin
.PHONY: login-ghcr
login-ghcr:
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u ayamebot --password-stdin
.PHONY: setup-buildx
setup-buildx:
docker buildx create --use --driver docker-container
docker version
.PHONY: build-tpl
build-tpl: setup-buildx
docker buildx build . \
--tag "${PKG_NAME}" \
--platform "linux/amd64" \
--build-arg DOCKER_HUGO_VERSION="${DOCKER_HUGO_VERSION}" \
--build-arg BASE_IMAGE="${BASE_IMAGE}" \
--build-arg INSTALL_NODE="${INSTALL_NODE}" \
--output "type=docker" \
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}"
.PHONY: tag
tag:
docker tag ${PKG_SPEC} ${HUB_SPEC}
docker tag ${PKG_SPEC} ${HUB_LATEST}
docker tag ${PKG_SPEC} ${PKG_LATEST}
.PHONY: dump
dump:
docker run --rm "${PKG_NAME}" version
.PHONY: build
build: build-slim build-mod build-full
docker images
.PHONY: build-slim
build-slim:
$(MAKE) build-tpl \
PKG_NAME="${PKG_SPEC}" \
BASE_IMAGE="debian:${DOCKER_DEBIAN_VERSION}-slim" \
INSTALL_NODE="false"
$(MAKE) tag \
TAG_SPEC="v${DOCKER_HUGO_VERSION}" \
TAG_LATEST="latest"
$(MAKE) dump PKG_NAME="${PKG_SPEC}"
.PHONY: build-mod
build-mod:
$(MAKE) build-tpl \
PKG_NAME="${PKG_SPEC}-mod" \
BASE_IMAGE="golang:${DOCKER_GOLANG_VERSION}-${DOCKER_DEBIAN_VERSION}" \
INSTALL_NODE="false"
$(MAKE) tag \
TAG_SPEC="v${DOCKER_HUGO_VERSION}-mod" \
TAG_LATEST="latest-mod"
$(MAKE) dump PKG_NAME="${PKG_SPEC}-mod"
.PHONY: build-full
build-full:
$(MAKE) build-tpl \
PKG_NAME="${PKG_SPEC}-full" \
BASE_IMAGE="golang:${DOCKER_GOLANG_VERSION}-${DOCKER_DEBIAN_VERSION}" \
INSTALL_NODE="true"
$(MAKE) tag \
TAG_SPEC="v${DOCKER_HUGO_VERSION}-full" \
TAG_LATEST="latest-full"
$(MAKE) dump PKG_NAME="${PKG_SPEC}-full"
.PHONY: push-tpl
push-tpl:
echo "${PKG_SPEC}\n${HUB_SPEC}" | xargs -I % docker push %
echo "${PKG_LATEST}\n${HUB_LATEST}" | xargs -I % docker push %
.PHONY: push-slim
push-slim:
$(MAKE) push-tpl \
TAG_SPEC="v${DOCKER_HUGO_VERSION}" \
TAG_LATEST="latest"
.PHONY: push-mod
push-mod:
$(MAKE) push-tpl \
TAG_SPEC="v${DOCKER_HUGO_VERSION}-mod" \
TAG_LATEST="latest-mod"
.PHONY: push-full
push-full:
$(MAKE) push-tpl \
TAG_SPEC="v${DOCKER_HUGO_VERSION}-full" \
TAG_LATEST="latest-full"