Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add cluster recreate action #67

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/cluster_recreate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: recreate ci cluster

on:
workflow_dispatch:

env:
azure_resource_group: nunki-ci

jobs:
recreate:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@8a218f9e264e9c3803c9a1ee1c30d8e4ab55be63 #v2
- name: Login to Azure
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
with:
creds: ${{ secrets.NUNKI_CI_INFRA_AZURE }}
- name: Cleanup .azure dir
run: rm $HOME/.azure/{commandIndex.json,versionCheck.json}
- name: Destroy existing CI cluster
continue-on-error: true
run: nix run .#destroy-coco-aks -- --name="$azure_resource_group"
- name: Create CI cluster
run: nix run .#create-coco-aks -- --name="$azure_resource_group"
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"gopls": {
"formatting.gofumpt": true,
},
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast",
],
"go.testFlags": [
"-race"
],
}
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
packages = import ./packages { inherit pkgs version; };

devShells.default = pkgs.mkShell {
packages = with pkgs; [ just ];
packages = with pkgs; [
golangci-lint
just
];
shellHook = ''alias make=just'';
};

Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ get-credentials:

# Destroy a running AKS cluster.
destroy:
nix run .#destroy-coco-aks -- "$azure_resource_group"
nix run .#destroy-coco-aks -- --name="$azure_resource_group"

# Run code generators.
codegen:
Expand Down
7 changes: 4 additions & 3 deletions packages/create-coco-aks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ for i in "$@"; do
esac
done

# Will always fail in CI due to lack of permissions.
# In GH actions, CI=true is part of the environment.
az group create \
--name "${name}" \
--location "${location:-westeurope}"
--location "${location:-westeurope}" ||
$CI

az aks create \
--resource-group "${name}" \
Expand All @@ -41,8 +44,6 @@ az aks create \
--os-sku AzureLinux \
--node-vm-size Standard_DC4as_cc_v5 \
--node-count 1 \
--enable-oidc-issuer \
--enable-workload-identity \
--generate-ssh-keys

az aks nodepool add \
Expand Down
2 changes: 1 addition & 1 deletion packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ rec {
destroy-coco-aks = writeShellApplication {
name = "destroy-coco-aks";
runtimeInputs = [ azure-cli-with-extensions ];
text = ''az group delete --name "$1"'';
text = builtins.readFile ./destroy-coco-aks.sh;
};

generate = writeShellApplication {
Expand Down
33 changes: 33 additions & 0 deletions packages/destroy-coco-aks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -euo pipefail
set -x

for i in "$@"; do
case $i in
--name=*)
name="${i#*=}"
shift
;;
*)
echo "Unknown option $i"
exit 1
;;
esac
done

exitcode=0

az aks nodepool delete \
--resource-group "${name}" \
--name nodepool2 \
--cluster-name "${name}" ||
exitcode=$?

az aks delete \
--resource-group "${name}" \
--name "${name}" \
--yes ||
exitcode=$?

exit "${exitcode}"