mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/khuedoan/homelab.git
synced 2026-09-20 08:03:58 +08:00
refactor!: replace make with task
- Better UX - Make has the advantage of being everywhere, but since we require Nix anyway, tasks are already in development tools, so it's not a problem.
This commit is contained in:
@@ -10,7 +10,7 @@ steps:
|
||||
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
|
||||
# - echo 'trusted-substituters = http://nix-cache.nix-cache' >> /etc/nix/nix.conf
|
||||
# - echo 'substituters = http://nix-cache.nix-cache' >> /etc/nix/nix.conf
|
||||
- nix develop --command make -C test filter=ToolsVersions
|
||||
- nix develop --command task test:tools
|
||||
when:
|
||||
- event: pull_request
|
||||
path:
|
||||
|
||||
59
Makefile
59
Makefile
@@ -1,59 +0,0 @@
|
||||
.POSIX:
|
||||
.PHONY: *
|
||||
.EXPORT_ALL_VARIABLES:
|
||||
|
||||
env ?= dev
|
||||
KUBECONFIG = $(shell pwd)/metal/kubeconfig-${env}.yaml
|
||||
KUBE_CONFIG_PATH = $(KUBECONFIG)
|
||||
|
||||
default: metal system external smoke-test post-install
|
||||
|
||||
configure:
|
||||
./scripts/configure
|
||||
git status
|
||||
|
||||
metal:
|
||||
[ "$(env)" = "dev" ] \
|
||||
&& make k3d \
|
||||
|| make -C metal
|
||||
|
||||
system:
|
||||
make -C system
|
||||
|
||||
external:
|
||||
[ "$(env)" != "dev" ] && make -C external
|
||||
|
||||
smoke-test:
|
||||
make -C test filter=Smoke
|
||||
|
||||
post-install:
|
||||
@./scripts/hacks
|
||||
|
||||
# TODO maybe there's a better way to manage backup with GitOps?
|
||||
backup:
|
||||
./scripts/backup --action setup --namespace=actualbudget --pvc=actualbudget-data
|
||||
./scripts/backup --action setup --namespace=jellyfin --pvc=jellyfin-data
|
||||
|
||||
restore:
|
||||
./scripts/backup --action restore --namespace=actualbudget --pvc=actualbudget-data
|
||||
./scripts/backup --action restore --namespace=jellyfin --pvc=jellyfin-data
|
||||
|
||||
test:
|
||||
make -C test
|
||||
|
||||
clean:
|
||||
docker compose --project-directory ./metal/roles/pxe_server/files down
|
||||
k3d cluster delete homelab-dev
|
||||
|
||||
docs:
|
||||
mkdocs serve
|
||||
|
||||
git-hooks:
|
||||
pre-commit install
|
||||
|
||||
info:
|
||||
kubectl cluster-info
|
||||
|
||||
k3d:
|
||||
k3d cluster start homelab-dev || k3d cluster create --config metal/k3d-${env}.yaml
|
||||
k3d kubeconfig get homelab-dev > metal/kubeconfig-${env}.yaml
|
||||
50
Taskfile.yaml
Normal file
50
Taskfile.yaml
Normal file
@@ -0,0 +1,50 @@
|
||||
version: '3'
|
||||
|
||||
vars:
|
||||
CLUSTER: '{{.CLUSTER| default "dev"}}'
|
||||
env:
|
||||
KUBECONFIG: '{{.ROOT_DIR}}/metal/kubeconfig-{{.CLUSTER}}.yaml'
|
||||
includes:
|
||||
metal:
|
||||
taskfile: ./metal/Taskfile.yaml
|
||||
dir: ./metal
|
||||
system:
|
||||
taskfile: ./system/Taskfile.yaml
|
||||
dir: ./system
|
||||
external:
|
||||
taskfile: ./external/Taskfile.yaml
|
||||
dir: ./external
|
||||
test:
|
||||
taskfile: ./test/Taskfile.yaml
|
||||
dir: ./test
|
||||
tasks:
|
||||
default:
|
||||
silent: true
|
||||
desc: List all tasks
|
||||
cmds:
|
||||
- task --list-all
|
||||
dev:
|
||||
desc: Apply dev cluster
|
||||
cmds:
|
||||
- task: metal:k3d
|
||||
- task: system
|
||||
- task: test:smoke
|
||||
production:
|
||||
desc: Apply production cluster
|
||||
cmds:
|
||||
- task: metal
|
||||
- task: system
|
||||
- task: test:smoke
|
||||
configure:
|
||||
- ./scripts/configure
|
||||
- git status
|
||||
docs:
|
||||
desc: Preview documentation
|
||||
cmds:
|
||||
- mkdocs serve
|
||||
info:
|
||||
desc: Display cluster information
|
||||
silent: true
|
||||
cmds:
|
||||
- echo "Running on {{.CLUSTER}} cluster"
|
||||
- kubectl cluster-info
|
||||
@@ -1,23 +0,0 @@
|
||||
.POSIX:
|
||||
|
||||
default: apply
|
||||
|
||||
~/.terraform.d/credentials.tfrc.json:
|
||||
tofu login
|
||||
|
||||
terraform.tfvars:
|
||||
cp terraform.tfvars.example ${@}
|
||||
nvim ${@}
|
||||
|
||||
.terraform.lock.hcl: ~/.terraform.d/credentials.tfrc.json versions.tf terraform.tfvars
|
||||
tofu init
|
||||
touch ${@}
|
||||
|
||||
namespaces:
|
||||
ansible-playbook namespaces.yml
|
||||
|
||||
plan: .terraform.lock.hcl
|
||||
tofu plan
|
||||
|
||||
apply: .terraform.lock.hcl namespaces
|
||||
tofu apply -auto-approve
|
||||
14
external/Taskfile.yaml
Normal file
14
external/Taskfile.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
- task: apply
|
||||
plan:
|
||||
desc: Plan external resources
|
||||
cmds:
|
||||
- tofu plan
|
||||
apply:
|
||||
desc: Apply external resources
|
||||
cmds:
|
||||
- ansible-playbook namespaces.yml
|
||||
- tofu apply --auto-approve
|
||||
@@ -17,13 +17,13 @@
|
||||
packages = [
|
||||
ansible
|
||||
ansible-lint
|
||||
bmake
|
||||
diffutils
|
||||
docker
|
||||
docker-compose
|
||||
dyff
|
||||
git
|
||||
go
|
||||
go-task
|
||||
gotestsum
|
||||
iproute2
|
||||
jq
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
.POSIX:
|
||||
|
||||
env ?= prod
|
||||
export KUBECONFIG = $(shell pwd)/kubeconfig-${env}.yaml
|
||||
|
||||
default: boot cluster
|
||||
|
||||
~/.ssh/id_ed25519:
|
||||
ssh-keygen -t ed25519 -P '' -f "$@"
|
||||
|
||||
boot: ~/.ssh/id_ed25519
|
||||
ansible-playbook \
|
||||
--inventory inventories/${env}.yml \
|
||||
boot.yml
|
||||
|
||||
cluster:
|
||||
ansible-playbook \
|
||||
--inventory inventories/${env}.yml \
|
||||
cluster.yml
|
||||
|
||||
console:
|
||||
ansible-console \
|
||||
--inventory inventories/${env}.yml
|
||||
24
metal/Taskfile.yaml
Normal file
24
metal/Taskfile.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- task: boot
|
||||
- task: cluster
|
||||
boot:
|
||||
desc: Install OS via PXE boot
|
||||
cmds:
|
||||
- ansible-playbook --inventory inventories/${env}.yml boot.yml
|
||||
cluster:
|
||||
desc: Setup cluster
|
||||
cmds:
|
||||
- ansible-playbook --inventory inventories/${env}.yml cluster.yml
|
||||
console:
|
||||
desc: Open console for executing commands on all nodes
|
||||
cmds:
|
||||
- ansible-console --inventory inventories/${env}.yml
|
||||
k3d:
|
||||
desc: Create a local k3d cluster for development
|
||||
cmds:
|
||||
- k3d cluster start homelab-{{.CLUSTER}} 2> /dev/null || k3d cluster create --config k3d-{{.CLUSTER}}.yaml
|
||||
- k3d kubeconfig get homelab-{{.CLUSTER}} > kubeconfig-${{.CLUSTER}}.yaml
|
||||
@@ -1,8 +1,8 @@
|
||||
apiVersion: k3d.io/v1alpha4
|
||||
apiVersion: k3d.io/v1alpha5
|
||||
kind: Simple
|
||||
metadata:
|
||||
name: homelab-dev
|
||||
image: docker.io/rancher/k3s:v1.27.1-k3s1
|
||||
image: docker.io/rancher/k3s:v1.31.4-k3s1
|
||||
servers: 1
|
||||
agents: 0
|
||||
options:
|
||||
@@ -11,9 +11,6 @@ options:
|
||||
- arg: --disable=traefik
|
||||
nodeFilters:
|
||||
- server:*
|
||||
- arg: --disable-cloud-controller
|
||||
nodeFilters:
|
||||
- server:*
|
||||
ports:
|
||||
- port: 80:80
|
||||
nodeFilters:
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
.POSIX:
|
||||
|
||||
export KUBECONFIG = $(shell pwd)/../metal/kubeconfig-${env}.yaml
|
||||
|
||||
.PHONY: bootstrap
|
||||
bootstrap:
|
||||
ansible-playbook \
|
||||
--extra-vars "env=${env}" \
|
||||
bootstrap.yml
|
||||
9
system/Taskfile.yaml
Normal file
9
system/Taskfile.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
- task: bootstrap
|
||||
bootstrap:
|
||||
desc: Bootstrap GitOps on the {{.CLUSTER}} cluster
|
||||
cmds:
|
||||
- ansible-playbook --extra-vars "cluster={{.CLUSTER}}" bootstrap.yml
|
||||
@@ -25,7 +25,7 @@
|
||||
release_namespace: argocd
|
||||
dependency_update: true
|
||||
values_files:
|
||||
- "argocd/values-{{ env }}.yaml"
|
||||
- "argocd/values-{{ cluster }}.yaml"
|
||||
- "argocd/{{ (first_install.resources | length == 0) | ternary('values-seed.yaml', 'values.yaml') }}"
|
||||
register: argocd_manifests
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
.POSIX:
|
||||
|
||||
filter=.
|
||||
|
||||
default: test
|
||||
|
||||
test:
|
||||
gotestsum --format testname -- -timeout 30m -run "${filter}"
|
||||
18
test/Taskfile.yaml
Normal file
18
test/Taskfile.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
- task: tools
|
||||
- task: smoke
|
||||
tools:
|
||||
desc: Test tools compatibility
|
||||
cmds:
|
||||
- gotestsum --format testname -- -run Tools
|
||||
smoke:
|
||||
desc: Run smoke tests
|
||||
cmds:
|
||||
- gotestsum --format testname -- -timeout 30m -run Smoke
|
||||
all:
|
||||
desc: Run all tests
|
||||
cmds:
|
||||
- gotestsum --format testname -- -timeout 30m
|
||||
Reference in New Issue
Block a user