Add AMI publish flake app
This commit is contained in:
@@ -21,8 +21,7 @@ The normal flow builds on a temporary EC2 instance, so your local machine does
|
|||||||
not need to be the same architecture as the target AMI:
|
not need to be the same architecture as the target AMI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd tofu/ami-builder
|
nix run ./tofu/ami-builder#publish-ami -- --builder-instance-type t4g.large
|
||||||
./publish-ami.sh --builder-instance-type t4g.large
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`publish-ami.sh` applies this OpenTofu project to create a temporary builder
|
`publish-ami.sh` applies this OpenTofu project to create a temporary builder
|
||||||
@@ -42,7 +41,7 @@ deregistering the AMI.
|
|||||||
Pass extra OpenTofu variables after `--`:
|
Pass extra OpenTofu variables after `--`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./publish-ami.sh --builder-instance-type t4g.large -- \
|
nix run ./tofu/ami-builder#publish-ami -- --builder-instance-type t4g.large -- \
|
||||||
-var base_nixos_ami_id=ami-...
|
-var base_nixos_ami_id=ami-...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -72,11 +72,32 @@
|
|||||||
exec ${pkgs.nodejs_24}/bin/node ${ami-artifacts-script}/libexec/ami-artifacts/manage-amis.mjs "$@"
|
exec ${pkgs.nodejs_24}/bin/node ${ami-artifacts-script}/libexec/ami-artifacts/manage-amis.mjs "$@"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
publish-ami = pkgs.writeShellApplication {
|
||||||
|
name = "publish-ami";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.awscli2
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.git
|
||||||
|
pkgs.jq
|
||||||
|
pkgs.opentofu
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
git_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
||||||
|
if [ -d "$git_root/tofu/ami-builder" ]; then
|
||||||
|
ami_builder_dir="$git_root/tofu/ami-builder"
|
||||||
|
else
|
||||||
|
ami_builder_dir="$git_root"
|
||||||
|
fi
|
||||||
|
cd "$ami_builder_dir"
|
||||||
|
exec ./publish-ami.sh "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
rootImage = config.system.build.images.amazon;
|
rootImage = config.system.build.images.amazon;
|
||||||
systemClosure = config.system.build.toplevel;
|
systemClosure = config.system.build.toplevel;
|
||||||
ami-artifacts = ami-artifacts;
|
ami-artifacts = ami-artifacts;
|
||||||
|
publish-ami = publish-ami;
|
||||||
default = ami-artifacts;
|
default = ami-artifacts;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -85,6 +106,10 @@
|
|||||||
type = "app";
|
type = "app";
|
||||||
program = "${self.packages.${system}.ami-artifacts}/bin/ami-artifacts";
|
program = "${self.packages.${system}.ami-artifacts}/bin/ami-artifacts";
|
||||||
};
|
};
|
||||||
|
publish-ami = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.packages.${system}.publish-ami}/bin/publish-ami";
|
||||||
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user