replace script with makefile
This commit is contained in:
@@ -1,69 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
if [ "$UID" != "0" ]; then
|
|
||||||
echo "This script must be run in root."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v "ssh-keygen"; then
|
|
||||||
echo "ssh-keygen is required for guest setup."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PATH="$PWD/scripts:$PATH"
|
|
||||||
|
|
||||||
validate.sh
|
|
||||||
|
|
||||||
if [[ "$?" != "0" ]]; then
|
|
||||||
echo "env validation failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
IMAGE_TAG=$(git rev-parse --short HEAD)
|
|
||||||
IMAGE_NAME=${IMAGE_NAME:-bearcloud}
|
|
||||||
|
|
||||||
HY_OPTS=${HY_OPTS:-"--no-cache"}
|
|
||||||
|
|
||||||
echo "Image tag: $IMAGE_NAME:$IMAGE_TAG and $IMAGE_NAME:latest"
|
|
||||||
echo "Additional arguments for VM image: $VM_OPTS"
|
|
||||||
echo "Additional arguments for Hypervisor Image: $HY_OPTS"
|
|
||||||
echo "Missing secret files like ssh host key will be automatically created."
|
|
||||||
echo "Continue?"
|
|
||||||
read
|
|
||||||
|
|
||||||
declare -A PRIVATE_KEYS=(["ssh_host_ecdsa_key"]="ecdsa"
|
|
||||||
["ssh_host_ed25519_key"]="ed25519"
|
|
||||||
["ssh_host_rsa_key"]="rsa")
|
|
||||||
|
|
||||||
for item in "${!PRIVATE_KEYS[@]}"; do
|
|
||||||
subject="secret/$item"
|
|
||||||
if [[ ! -f $subject ]]; then
|
|
||||||
echo "Creating missing secret $subject"
|
|
||||||
ssh-keygen -t "${PRIVATE_KEYS[$item]}" -f "$subject" \
|
|
||||||
-C "automatically generated bearcloud ssh key" \
|
|
||||||
-N ""
|
|
||||||
ssh-keygen -y -f "$subject" > "${subject}_pub"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
BUILDERS=$(docker buildx ls)
|
|
||||||
if ! (echo $BUILDERS | grep -q "bearcloud"); then
|
|
||||||
docker buildx create --name bearcloud --buildkitd-flags '--allow-insecure-entitlement security.insecure'
|
|
||||||
fi
|
|
||||||
echo "BUILDING VM DISK IMAGE"
|
|
||||||
docker build \
|
|
||||||
--builder bearcloud \
|
|
||||||
--allow security.insecure \
|
|
||||||
-f vm.Dockerfile \
|
|
||||||
--build-context host-modules=/lib/modules \
|
|
||||||
--target export \
|
|
||||||
--output type=local,dest=./data \
|
|
||||||
$VM_OPTS .
|
|
||||||
|
|
||||||
fallocate -d ./data/vm.raw
|
|
||||||
|
|
||||||
echo "BUILDING HYPERVISOR IMAGE"
|
|
||||||
docker build -t "$IMAGE_NAME:$IMAGE_TAG" -t "$IMAGE_NAME:latest" \
|
|
||||||
-f hypervisor.Dockerfile $HY_OPTS .
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
SHELL := /bin/bash
|
||||||
|
export PATH := $(PWD)/scripts:$(PATH)
|
||||||
|
|
||||||
|
IMAGE_TAG := $(shell git rev-parse --short HEAD)
|
||||||
|
IMAGE_NAME ?= bearcloud
|
||||||
|
HY_OPTS ?= --no-cache
|
||||||
|
VM_OPTS ?=
|
||||||
|
|
||||||
|
SECRET_KEYS := ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_key
|
||||||
|
KEYTYPE_ssh_host_ecdsa_key := ecdsa
|
||||||
|
KEYTYPE_ssh_host_ed25519_key := ed25519
|
||||||
|
KEYTYPE_ssh_host_rsa_key := rsa
|
||||||
|
|
||||||
|
SECRET_FILES := $(addprefix secret/,$(SECRET_KEYS))
|
||||||
|
|
||||||
|
.PHONY: all check-root check-deps validate secrets builder vm hypervisor confirm
|
||||||
|
|
||||||
|
all: vm hypervisor
|
||||||
|
|
||||||
|
check-root:
|
||||||
|
@if [ "$$(id -u)" != "0" ]; then \
|
||||||
|
echo "This script must be run in root."; \
|
||||||
|
exit 2; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
check-deps:
|
||||||
|
@if ! command -v ssh-keygen >/dev/null; then \
|
||||||
|
echo "ssh-keygen is required for guest setup."; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
validate: check-deps
|
||||||
|
@validate.sh || { echo "env validation failed"; exit 1; }
|
||||||
|
|
||||||
|
confirm: check-root validate
|
||||||
|
@echo "Image tag: $(IMAGE_NAME):$(IMAGE_TAG) and $(IMAGE_NAME):latest"
|
||||||
|
@echo "Additional arguments for VM image: $(VM_OPTS)"
|
||||||
|
@echo "Additional arguments for Hypervisor Image: $(HY_OPTS)"
|
||||||
|
@echo "Missing secret files like ssh host key will be automatically created."
|
||||||
|
@echo "Continue?"
|
||||||
|
@read
|
||||||
|
|
||||||
|
$(SECRET_FILES):
|
||||||
|
@echo "Creating missing secret $@"
|
||||||
|
ssh-keygen -t "$(KEYTYPE_$(notdir $@))" -f "$@" \
|
||||||
|
-C "automatically generated bearcloud ssh key" \
|
||||||
|
-N ""
|
||||||
|
ssh-keygen -y -f "$@" > "$@_pub"
|
||||||
|
|
||||||
|
secrets: $(SECRET_FILES)
|
||||||
|
|
||||||
|
builder:
|
||||||
|
@if ! docker buildx ls | grep -q "bearcloud"; then \
|
||||||
|
docker buildx create --name bearcloud \
|
||||||
|
--buildkitd-flags '--allow-insecure-entitlement security.insecure'; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
vm: confirm secrets builder
|
||||||
|
@echo "BUILDING VM DISK IMAGE"
|
||||||
|
docker build \
|
||||||
|
--builder bearcloud \
|
||||||
|
--allow security.insecure \
|
||||||
|
-f vm.Dockerfile \
|
||||||
|
--build-context host-modules=/lib/modules \
|
||||||
|
--target export \
|
||||||
|
--output type=local,dest=./data \
|
||||||
|
$(VM_OPTS) .
|
||||||
|
fallocate -d ./data/vm.raw
|
||||||
|
|
||||||
|
hypervisor: confirm secrets
|
||||||
|
@echo "BUILDING HYPERVISOR IMAGE"
|
||||||
|
docker build -t "$(IMAGE_NAME):$(IMAGE_TAG)" -t "$(IMAGE_NAME):latest" \
|
||||||
|
-f hypervisor.Dockerfile $(HY_OPTS) .
|
||||||
@@ -9,7 +9,7 @@ Edit corresponding files in [image/overlay](./image/overlay) to customize VM beh
|
|||||||
```bash
|
```bash
|
||||||
# cp .env.example .env
|
# cp .env.example .env
|
||||||
# vim .env
|
# vim .env
|
||||||
# VM_OPTS="--no-cache" HY_OPTS="--no-cache" ./BUILD.sh
|
# VM_OPTS="--no-cache" HY_OPTS="--no-cache" make
|
||||||
# fallocate -l 128G ./data/data.raw
|
# fallocate -l 128G ./data/data.raw
|
||||||
# sgdisk -o -n 1:0:0 -t 1:8300 ./data.raw
|
# sgdisk -o -n 1:0:0 -t 1:8300 ./data.raw
|
||||||
# losetup -Pf ./data.raw
|
# losetup -Pf ./data.raw
|
||||||
|
|||||||
Reference in New Issue
Block a user