-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
123 lines (107 loc) · 4.69 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
121
122
123
DOCKER_CLI_EXPERIMENTAL := enabled
DOCKER_BUILDKIT := 1
DOCKER_USERNAME := peaceiris
DOCKER_IMAGE_NAME := mdbook
DOCKER_HUB_BASE_NAME := ${DOCKER_USERNAME}/${DOCKER_IMAGE_NAME}
DOCKER_BASE_NAME := ghcr.io/${DOCKER_HUB_BASE_NAME}
DOCKER_VERSION := $(shell cat ./deps/Cargo.toml | grep 'mdbook = ' | awk '{print $$3}' | tr -d '"')
MDBOOK_MERMAID_VERSION := $(shell cat ./deps/Cargo.toml | grep 'mdbook-mermaid = ' | awk '{print $$3}' | tr -d '"')
MDBOOK_TOC_VERSION := $(shell cat ./deps/Cargo.toml | grep 'mdbook-toc = ' | awk '{print $$3}' | tr -d '"')
MDBOOK_ADMONISH_VERSION := $(shell cat ./deps/Cargo.toml | grep 'mdbook-admonish = ' | awk '{print $$3}' | tr -d '"')
DOCKER_TAG := v${DOCKER_VERSION}
GITHUB_REF_NAME ?= local
DOCKER_SCOPE := mdbook-${GITHUB_REF_NAME}
DOCKER_OUTPUT_TYPE ?= docker
ifeq ($(IS_PULL_REQUEST), false)
DOCKER_OUTPUT_TYPE := registry
endif
PKG_NAME := ${DOCKER_BASE_NAME}:${DOCKER_TAG}
HUB_NAME := ${DOCKER_HUB_BASE_NAME}:${DOCKER_TAG}
PKG_LATEST := ${DOCKER_BASE_NAME}:latest
HUB_LATEST := ${DOCKER_HUB_BASE_NAME}:latest
ARCH := $(shell uname -m)
ifeq ($(ARCH), x86_64)
PLATFORM := amd64
CARGO_TARGET := x86_64-unknown-linux-musl
else ifeq ($(ARCH), arm64)
PLATFORM := arm64
CARGO_TARGET := aarch64-unknown-linux-musl
else ifeq ($(ARCH), aarch64)
PLATFORM := arm64
CARGO_TARGET := aarch64-unknown-linux-musl
endif
.PHONY: login-dockerhub
login-dockerhub:
echo "${DOCKER_HUB_TOKEN}" | docker login -u "${DOCKER_USERNAME}" --password-stdin
.PHONY: login-ghcr
login-ghcr:
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${DOCKER_USERNAME}" --password-stdin
.PHONY: login
login: login-dockerhub login-ghcr
.PHONY: setup-buildx
setup-buildx:
docker buildx create --use --driver docker-container
docker buildx inspect --bootstrap
docker version
.PHONY: build
build: build-alpine build-rust
.PHONY: build-alpine
build-alpine:
docker buildx build . \
--tag "${HUB_NAME}-$(PLATFORM)" \
--output "type=${DOCKER_OUTPUT_TYPE}" \
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" \
--build-arg MDBOOK_VERSION="${DOCKER_VERSION}" \
--build-arg BASE_IMAGE="alpine:3.20.0" \
--build-arg MDBOOK_MERMAID_VERSION="${MDBOOK_MERMAID_VERSION}" \
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}" \
--build-arg MDBOOK_ADMONISH_VERSION="${MDBOOK_ADMONISH_VERSION}" \
--build-arg CARGO_TARGET="${CARGO_TARGET}"
.PHONY: build-rust
build-rust:
docker buildx build . \
--tag "${HUB_NAME}-rust-$(PLATFORM)" \
--output "type=${DOCKER_OUTPUT_TYPE}" \
--cache-from "type=gha,scope=${DOCKER_SCOPE}" \
--cache-to "type=gha,mode=max,scope=${DOCKER_SCOPE}" \
--build-arg MDBOOK_VERSION="${DOCKER_VERSION}" \
--build-arg BASE_IMAGE="rust:1.78.0-alpine3.20" \
--build-arg MDBOOK_MERMAID_VERSION="${MDBOOK_MERMAID_VERSION}" \
--build-arg MDBOOK_TOC_VERSION="${MDBOOK_TOC_VERSION}" \
--build-arg MDBOOK_ADMONISH_VERSION="${MDBOOK_ADMONISH_VERSION}" \
--build-arg CARGO_TARGET="${CARGO_TARGET}"
.PHONY: merge
merge:
docker buildx imagetools create --tag "${PKG_NAME}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create --tag "${HUB_NAME}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create --tag "${PKG_LATEST}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create --tag "${HUB_LATEST}" "${HUB_NAME}-amd64" "${HUB_NAME}-arm64"
docker buildx imagetools create --tag "${PKG_NAME}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
docker buildx imagetools create --tag "${HUB_NAME}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
docker buildx imagetools create --tag "${PKG_LATEST}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
docker buildx imagetools create --tag "${HUB_LATEST}-rust" "${HUB_NAME}-rust-amd64" "${HUB_NAME}-rust-arm64"
.PHONY: test
test:
@docker run --rm "${HUB_NAME}-$(PLATFORM)" --version
@docker run --rm "${HUB_NAME}-rust-$(PLATFORM)" --version
.PHONY: test-build
test-build:
docker run --rm -v "./example:/book" "${HUB_NAME}-$(PLATFORM)" build
docker run --rm -v "./example:/book" --entrypoint sh "${HUB_NAME}-$(PLATFORM)" -c 'mdbook-admonish install /book'
.PHONY: test-build-with-latest
test-build-with-latest:
docker run --rm -v "./example:/book" "${HUB_LATEST}" build
docker run --rm -v "./example:/book" --entrypoint sh "${HUB_LATEST}" -c 'mdbook-admonish install /book'
.PHONY: run
run:
docker run --rm -i -t -v "./example:/book" -p "3000:3000" -p "3001:3001" --entrypoint sh "${HUB_NAME}-$(PLATFORM)"
.PHONY: compose-build
compose-build:
cd ./example && \
docker compose run --rm mdbook build && \
docker compose run --rm --entrypoint sh mdbook -c 'mdbook-admonish install /book'
.PHONY: compose-serve
compose-serve:
cd ./example && \
docker compose up