Skip to content

Commit 22dc6e2

Browse files
authored
feat: initial mise files and tests (#3)
1 parent 4c3a5dc commit 22dc6e2

File tree

8 files changed

+258
-0
lines changed

8 files changed

+258
-0
lines changed

.github/workflows/run-tests.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: run-tests
3+
4+
on:
5+
workflow_dispatch:
6+
7+
permissions: read-all
8+
9+
env:
10+
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
11+
MISE_SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
12+
13+
jobs:
14+
docker-mise-linux:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15]
19+
timeout-minutes: 30
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
24+
- name: Run mise
25+
run: |
26+
docker run --rm -it \
27+
--env SOPS_AGE_KEY --env MISE_SOPS_AGE_KEY \
28+
-v "$PWD:/mnt" \
29+
-v "/var/run/docker.sock:/var/run/docker.sock" \
30+
--workdir /mnt \
31+
bash bash -c 'set -euxo pipefail && \
32+
apk add docker && \
33+
wget https://mise.run -O - | sh && \
34+
eval "$(~/.local/bin/mise activate bash)" && \
35+
mise run "create:*:*" && \
36+
mise run "delete:*:*" \
37+
'
38+
39+
mise-linux:
40+
runs-on: ${{ matrix.os }}
41+
strategy:
42+
matrix:
43+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15]
44+
timeout-minutes: 30
45+
steps:
46+
- name: Checkout Code
47+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
48+
49+
- name: Run mise
50+
run: |
51+
wget https://mise.run -O - | sh
52+
eval "$(~/.local/bin/mise activate bash)"
53+
mise run "create:*:*"
54+
mise run "delete:*:*"
55+
56+
mise-windows:
57+
runs-on: windows-2025
58+
timeout-minutes: 30
59+
steps:
60+
- name: Checkout Code
61+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
62+
63+
- name: Run mise
64+
run: |
65+
scoop install mise
66+
mise run "create:*:*"
67+
mise run "delete:*:*"

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,25 @@
22

33
Infrastructure as Code for provisioning multiple Kubernetes clusters, managed
44
using GitOps with ArgoCD
5+
6+
Tests:
7+
8+
```bash
9+
SOPS_AGE_KEY="$(grep -v ^# ~/Documents/secrets/age.txt)"
10+
export SOPS_AGE_KEY
11+
MISE_SOPS_AGE_KEY="$(grep -v ^# ~/Documents/secrets/age.txt)"
12+
export MISE_SOPS_AGE_KEY
13+
14+
docker run --rm -it \
15+
--env SOPS_AGE_KEY --env MISE_SOPS_AGE_KEY \
16+
-v "$PWD:/mnt" \
17+
-v "/var/run/docker.sock:/var/run/docker.sock" \
18+
--workdir /mnt \
19+
bash bash -c 'set -euxo pipefail && \
20+
apk add docker && \
21+
wget https://mise.run -O - | sh && \
22+
eval "$(~/.local/bin/mise activate bash)" && \
23+
mise run "create:*:*" && \
24+
mise run "delete:*:*" \
25+
'
26+
```

clusters/kind01-internal/.env.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SECRET: ENC[AES256_GCM,data:QIOd+nLFzAQ=,iv:6o+BhThDyGAQ1jwjG04bS95c55xdUCdB6XhezYrKv90=,tag:tnwKw9zZjc7OLDi7YbiYnw==,type:str]
2+
sops:
3+
kms: []
4+
gcp_kms: []
5+
azure_kv: []
6+
hc_vault: []
7+
age:
8+
- recipient: age1jjuamrdk3vrk6g8qhrjnqtt4x2yvvxw7fz2nkvf78398dj7vav7s74z4zz
9+
enc: |
10+
-----BEGIN AGE ENCRYPTED FILE-----
11+
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBTNXVyZWd4bTFWekVKbjdn
12+
dzlPcWZnWUxsME9UWlN2NjgzMGhoQ1VIV0drCnlScGZTYitqcTYyR291eVArYWVs
13+
c1JyU2FTVWJBajdWdFVGRFN5TXFsMWMKLS0tIEt2WjdNN3FWaU5UQnNwRDNseTVy
14+
TXhtbU94bVFjOTJiUmQyQ2U5VWU0WlkK5Ur8KSyl5/4/AJrADYLRF/27r7hEZzY1
15+
0Qo5LZDZOLXoJ6RBEAYi7WNj/hYbgoBd6maB93fMUaEW6MfC5zK6DA==
16+
-----END AGE ENCRYPTED FILE-----
17+
lastmodified: "2025-03-14T09:14:06Z"
18+
mac: ENC[AES256_GCM,data:kDFNXFwtCNtUISMdYQG0yu38ORYdwsp5v02KrzFZS/zj3mPSNU71RGRPn44Vp9noztBRzz0C6kwql7BaWC2twDVAlR9FIrQDl+jf9PQiO9kBmrQo60TJq4gFe0jesWaBFyKDAG3ffi/oELJs8NZVkbBXwpshNoLs0C06nwc989g=,iv:fPVkLhox+xd5KXFmC6t+CJJ8c4Nsjh8u0DSCvnanYKM=,tag:2isNCgC8yxDaZOojyqgEjA==,type:str]
19+
pgp: []
20+
unencrypted_suffix: _unencrypted
21+
version: 3.9.4

clusters/kind01-internal/mise.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[env]
2+
_.file = ".env.yaml"
3+
# keep-sorted start
4+
CLUSTER_FQDN = "kind01.internal"
5+
CLUSTER_NAME = "kind01"
6+
# keep-sorted end
7+
8+
[tasks."create"]
9+
description = 'Create K8s cluster'
10+
run = '${CLUSTERS_RUN_SCRIPT_DIRECTORY}/run-kind.sh create'
11+
12+
[tasks."delete"]
13+
description = 'Delete K8s cluster'
14+
run = '${CLUSTERS_RUN_SCRIPT_DIRECTORY}/run-kind.sh delete'

clusters/kind02-internal/.env.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SECRET: ENC[AES256_GCM,data:QIOd+nLFzAQ=,iv:6o+BhThDyGAQ1jwjG04bS95c55xdUCdB6XhezYrKv90=,tag:tnwKw9zZjc7OLDi7YbiYnw==,type:str]
2+
sops:
3+
kms: []
4+
gcp_kms: []
5+
azure_kv: []
6+
hc_vault: []
7+
age:
8+
- recipient: age1jjuamrdk3vrk6g8qhrjnqtt4x2yvvxw7fz2nkvf78398dj7vav7s74z4zz
9+
enc: |
10+
-----BEGIN AGE ENCRYPTED FILE-----
11+
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBTNXVyZWd4bTFWekVKbjdn
12+
dzlPcWZnWUxsME9UWlN2NjgzMGhoQ1VIV0drCnlScGZTYitqcTYyR291eVArYWVs
13+
c1JyU2FTVWJBajdWdFVGRFN5TXFsMWMKLS0tIEt2WjdNN3FWaU5UQnNwRDNseTVy
14+
TXhtbU94bVFjOTJiUmQyQ2U5VWU0WlkK5Ur8KSyl5/4/AJrADYLRF/27r7hEZzY1
15+
0Qo5LZDZOLXoJ6RBEAYi7WNj/hYbgoBd6maB93fMUaEW6MfC5zK6DA==
16+
-----END AGE ENCRYPTED FILE-----
17+
lastmodified: "2025-03-14T09:14:06Z"
18+
mac: ENC[AES256_GCM,data:kDFNXFwtCNtUISMdYQG0yu38ORYdwsp5v02KrzFZS/zj3mPSNU71RGRPn44Vp9noztBRzz0C6kwql7BaWC2twDVAlR9FIrQDl+jf9PQiO9kBmrQo60TJq4gFe0jesWaBFyKDAG3ffi/oELJs8NZVkbBXwpshNoLs0C06nwc989g=,iv:fPVkLhox+xd5KXFmC6t+CJJ8c4Nsjh8u0DSCvnanYKM=,tag:2isNCgC8yxDaZOojyqgEjA==,type:str]
19+
pgp: []
20+
unencrypted_suffix: _unencrypted
21+
version: 3.9.4

clusters/kind02-internal/mise.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[env]
2+
_.file = ".env.yaml"
3+
# keep-sorted start
4+
CLUSTER_FQDN = "kind02.internal"
5+
CLUSTER_NAME = "kind02"
6+
# keep-sorted end
7+
8+
[tasks."create"]
9+
description = 'Create K8s cluster'
10+
run = '${CLUSTERS_RUN_SCRIPT_DIRECTORY}/run-kind.sh create'
11+
12+
[tasks."delete"]
13+
description = 'Delete K8s cluster'
14+
run = '${CLUSTERS_RUN_SCRIPT_DIRECTORY}/run-kind.sh delete'

mise.toml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[tools]
2+
# keep-sorted start
3+
eksctl = "0.205.0"
4+
kind = "0.27.0"
5+
kubectl = "1.32.3"
6+
opentofu = "1.9.0"
7+
sops = "3.9.4"
8+
# keep-sorted end
9+
10+
[settings]
11+
experimental = true
12+
# Use MISE_SOPS_AGE_KEY="$(grep -v ^# ~/Documents/secrets/age.txt)" instead
13+
# sops.age_key_file = "~/Documents/secrets/age.txt"
14+
trusted_config_paths = ["/"]
15+
16+
[env]
17+
_.file = ".env.yaml"
18+
# Directory which contains the clusters mise configurations
19+
CLUSTERS_DIRECTORY = "{{ config_root }}/clusters"
20+
# Directory which contains the kubeconfig files for the created clusters (will be create if not exists)
21+
CLUSTERS_KUBECONFIG_DIRECTORY = "{{ config_root }}/clusters/.kubeconfig"
22+
# Directory which contains the scripts to create and delete the clusters
23+
CLUSTERS_RUN_SCRIPT_DIRECTORY = "{{ config_root }}/scripts"
24+
25+
[tasks."create:kind:kind01-internal"]
26+
description = 'Create kind01.internal K8s cluster'
27+
# Run mise again due to missing support for SOPS-encrypted environment variables in tasks: https://github.com/jdx/mise/discussions/4593
28+
run = 'cd "${CLUSTERS_DIRECTORY}/${MISE_TASK_NAME##*:}" && mise run create'
29+
30+
[tasks."delete:kind:kind01-internal"]
31+
description = 'Delete kind01.internal K8s cluster'
32+
run = 'cd "${CLUSTERS_DIRECTORY}/${MISE_TASK_NAME##*:}" && mise run delete'
33+
34+
[tasks."create:kind:kind02-internal"]
35+
description = 'Create kind02.internal K8s cluster'
36+
run = 'cd "${CLUSTERS_DIRECTORY}/${MISE_TASK_NAME##*:}" && mise run create'
37+
38+
[tasks."delete:kind:kind02-internal"]
39+
description = 'Delete kind02.internal K8s cluster'
40+
run = 'cd "${CLUSTERS_DIRECTORY}/${MISE_TASK_NAME##*:}" && mise run delete'

scripts/run-kind.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
# The "create" needs to be idempotent !
4+
create() {
5+
if kind get clusters 2>&1 | grep -q "^${CLUSTER_FQDN}$"; then
6+
echo "*** Cluster \"${CLUSTER_FQDN}\" already exists...."
7+
else
8+
mkdir -p "${CLUSTERS_KUBECONFIG_DIRECTORY}"
9+
cat << EOF | kind create cluster --name "${CLUSTER_FQDN}" --kubeconfig "${CLUSTERS_KUBECONFIG_DIRECTORY}/kubeconfig_${CLUSTER_FQDN}.yml" --config -
10+
kind: Cluster
11+
apiVersion: kind.x-k8s.io/v1alpha4
12+
nodes:
13+
- role: control-plane
14+
- role: worker
15+
EOF
16+
fi
17+
}
18+
19+
delete() {
20+
if kind get clusters | grep -q "^${CLUSTER_FQDN}$"; then
21+
kind delete cluster --name "${CLUSTER_FQDN}" --kubeconfig "${CLUSTERS_KUBECONFIG_DIRECTORY}/kubeconfig_${CLUSTER_FQDN}.yml"
22+
if [[ -f "${CLUSTERS_KUBECONFIG_DIRECTORY}/kubeconfig_${CLUSTER_FQDN}.yml" ]]; then
23+
echo "*** Deleting \"${CLUSTERS_KUBECONFIG_DIRECTORY}/kubeconfig_${CLUSTER_FQDN}.yml\" ..."
24+
rm "${CLUSTERS_KUBECONFIG_DIRECTORY}/kubeconfig_${CLUSTER_FQDN}.yml"
25+
fi
26+
if [[ -d "${CLUSTERS_KUBECONFIG_DIRECTORY}" && -z "$(ls -A "${CLUSTERS_KUBECONFIG_DIRECTORY}")" ]]; then
27+
echo "*** Deleting empty \"${CLUSTERS_KUBECONFIG_DIRECTORY}\" ..."
28+
rmdir "${CLUSTERS_KUBECONFIG_DIRECTORY}"
29+
fi
30+
else
31+
echo "*** Cluster \"${CLUSTER_FQDN}\" does not exist..."
32+
fi
33+
}
34+
35+
usage() {
36+
echo "*** Usage: $0 {create|delete}"
37+
exit 1
38+
}
39+
40+
: "${CLUSTER_FQDN:?Error: CLUSTER_FQDN environment variable is not set!}"
41+
: "${CLUSTERS_KUBECONFIG_DIRECTORY:?Error: CLUSTERS_KUBECONFIG_DIRECTORY environment variable is not set!}"
42+
43+
if [[ $# -ne 1 ]]; then
44+
usage
45+
fi
46+
47+
case "$1" in
48+
create)
49+
echo "*** Creating K8s cluster..."
50+
create
51+
;;
52+
delete)
53+
echo "*** Deleting K8s cluster..."
54+
delete
55+
;;
56+
*)
57+
usage
58+
;;
59+
esac

0 commit comments

Comments
 (0)