forked from rancher/elemental-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
165 lines (140 loc) · 5.34 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Directory of Makefile
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
DISK?=$(shell ls $(ROOT_DIR)/build/*.qcow2 2> /dev/null)
DISKSIZE?=20G
ISO?=$(shell ls $(ROOT_DIR)/build/*.iso 2> /dev/null)
FLAVOR?=green
ARCH?=$(shell uname -m)
PLATFORM?=linux/$(ARCH)
IMAGE_SIZE?=20G
REPO?=local/elemental-$(FLAVOR)
TOOLKIT_REPO?=local/elemental-toolkit
DOCKER?=docker
BASE_OS_IMAGE?=registry.opensuse.org/opensuse/tumbleweed
BASE_OS_VERSION?=latest
DOCKER_SOCK?=/var/run/docker.sock
GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
VERSION?=$(GIT_TAG)-g$(GIT_COMMIT_SHORT)
PKG:=./cmd ./pkg/...
LDFLAGS:=-w -s
LDFLAGS+=-X "github.com/rancher/elemental-toolkit/v2/internal/version.version=$(GIT_TAG)"
LDFLAGS+=-X "github.com/rancher/elemental-toolkit/v2/internal/version.gitCommit=$(GIT_COMMIT)"
# For RISC-V 64bit support
ifeq ($(PLATFORM),linux/riscv64)
BASE_OS_IMAGE=registry.opensuse.org/opensuse/factory/riscv/images/opensuse/tumbleweed
BASE_OS_VERSION=latest
ifeq ($(FLAVOR),tumbleweed)
OS_IMAGE=registry.opensuse.org/opensuse/factory/riscv/images/opensuse/tumbleweed
ADD_REPO=https://download.opensuse.org/repositories/devel:/RISCV:/Factory:/Contrib:/StarFive:/VisionFive2/standard
BUILD_OPTS=--build-arg OS_IMAGE=$(OS_IMAGE) --build-arg ADD_REPO=$(ADD_REPO)
endif
endif
# default target
.PHONY: all
all: build build-cli
#----------------------- includes -----------------------
include make/Makefile.test
#----------------------- targets ------------------------
.PHONY: build
build:
$(DOCKER) build --platform $(PLATFORM) ${DOCKER_ARGS} \
--build-arg ELEMENTAL_VERSION=$(GIT_TAG) \
--build-arg ELEMENTAL_COMMIT=$(GIT_COMMIT) \
--build-arg BASE_OS_IMAGE=$(BASE_OS_IMAGE) \
--build-arg BASE_OS_VERSION=$(BASE_OS_VERSION) \
--target elemental-toolkit -t $(TOOLKIT_REPO):$(VERSION) .
.PHONY: push-toolkit
push-toolkit:
$(DOCKER) push $(TOOLKIT_REPO):$(VERSION)
.PHONY: pull-toolkit
pull-toolkit:
for retry in 1 2 3 4 5 ; do \
$(DOCKER) pull $(TOOLKIT_REPO):$(VERSION) && exit 0; \
sleep 5; \
done
.PHONY: build-cli
build-cli:
go generate ./...
go build -ldflags '$(LDFLAGS)' -o build/elemental
.PHONY: build-os
build-os:
$(DOCKER) build --platform $(PLATFORM) ${DOCKER_ARGS} \
--build-arg TOOLKIT_REPO=$(TOOLKIT_REPO) \
--build-arg VERSION=$(VERSION) \
--build-arg REPO=$(REPO) -t $(REPO):$(VERSION) \
$(BUILD_OPTS) examples/$(FLAVOR)
.PHONY: push-os
push-os:
$(DOCKER) push $(REPO):$(VERSION)
.PHONY: pull-os
pull-os:
$(DOCKER) pull $(REPO):$(VERSION)
.PHONY: build-iso
build-iso:
@echo Building $(ARCH) ISO
mkdir -p $(ROOT_DIR)/build
$(DOCKER) run --rm -v $(DOCKER_SOCK):$(DOCKER_SOCK) -v $(ROOT_DIR)/build:/build \
-v $(ROOT_DIR)/tests/assets/remote_login.yaml:/overlay-iso/iso-config/remote_login.yaml \
--entrypoint /usr/bin/elemental $(TOOLKIT_REPO):$(VERSION) --debug build-iso \
-n elemental-$(FLAVOR).$(ARCH) --overlay-iso /overlay-iso \
--local --platform $(PLATFORM) -o /build $(REPO):$(VERSION)
.PHONY: build-disk
build-disk:
@echo Building $(ARCH) disk
mkdir -p $(ROOT_DIR)/build
$(DOCKER) run --rm -v $(DOCKER_SOCK):$(DOCKER_SOCK) -v $(ROOT_DIR)/build:/build -v $(ROOT_DIR)/tests/assets:/assets \
--entrypoint /usr/bin/elemental $(TOOLKIT_REPO):$(VERSION) --debug build-disk --platform $(PLATFORM) \
--expandable -n elemental-$(FLAVOR).$(ARCH) --local --cloud-init /assets/remote_login.yaml -o /build --system $(REPO):$(VERSION)
qemu-img convert -O qcow2 $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).raw $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2
qemu-img resize $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).qcow2 $(DISKSIZE)
.PHONY: build-rpi-disk
build-rpi-disk:
ifneq ("$(PLATFORM)","linux/arm64")
@echo "Cannot build Raspberry Pi disk for $(PLATFORM)"
@exit 1
endif
@echo Building $(ARCH) disk
mkdir -p $(ROOT_DIR)/build
$(DOCKER) run --rm -v $(DOCKER_SOCK):$(DOCKER_SOCK) -v $(ROOT_DIR)/examples:/examples -v $(ROOT_DIR)/build:/build \
--entrypoint /usr/bin/elemental \
$(TOOLKIT_REPO):$(VERSION) --debug build-disk --platform $(PLATFORM) --cloud-init-paths /examples/$(FLAVOR) --expandable -n elemental-$(FLAVOR).aarch64 --local \
--squash-no-compression -o /build --system $(REPO):$(VERSION)
PHONY: build-vf2-disk
build-vf2-disk:
ifneq ("$(PLATFORM)","linux/riscv64")
@echo "Cannot build VisionFive2 disk for $(PLATFORM)"
@exit 1
endif
@echo Building $(ARCH) disk
mkdir -p $(ROOT_DIR)/build
$(DOCKER) run --rm -v $(DOCKER_SOCK):$(DOCKER_SOCK) -v $(ROOT_DIR)/examples:/examples -v $(ROOT_DIR)/build:/build \
--entrypoint /usr/bin/elemental \
$(TOOLKIT_REPO):$(VERSION) --debug build-disk --platform $(PLATFORM) --cloud-init-paths /examples/$(FLAVOR) --expandable -n elemental-$(FLAVOR).riscv64 --local \
--squash-no-compression -o /build --system $(REPO):$(VERSION)
.PHONY: clean
clean:
rm -fv $(ROOT_DIR)/build/elemental-$(FLAVOR).$(ARCH).{raw,img,qcow2,iso,iso.sha256}
.PHONY: vet
vet:
go vet $(PKG)
.PHONY: fmt
fmt:
ifneq ($(shell go fmt $(PKG)),)
@echo "Please commit the changes from 'make fmt'"
@exit 1
else
@echo "All files formatted"
@exit 0
endif
.PHONY: license-check
license-check:
@.github/license_check.sh
.PHONY: lint
lint: fmt vet
.PHONY: build-docs
build-docs:
@./scripts/docs-build.sh
go generate ./...
cd docs && go run generate_docs.go