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

feat(mantis): making solver run and restart, with proper funds secure mnemonic #1

Merged
merged 5 commits into from
Nov 23, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
export TF_VAR_GITHUB_TOKEN=${{ secrets.TF_VAR_GITHUB_TOKEN }}
export TF_VAR_AWS_ACCESS_KEY_ID=${{ secrets.TF_VAR_AWS_ACCESS_KEY_ID }}
export TF_VAR_AWS_SECRET_ACCESS_KEY=${{ secrets.TF_VAR_AWS_SECRET_ACCESS_KEY }}
export TV_VAR_MANTIS_COSMOS_MNEMONIC=${{ secrets.TV_VAR_MANTIS_COSMOS_MNEMONIC }}
export TF_VAR_MANTIS_COSMOS_MNEMONIC=${{ secrets.TF_VAR_MANTIS_COSMOS_MNEMONIC }}
export TF_VAR_CI_SSH_KEY=${{ secrets.TF_VAR_CI_SSH_KEY }}
export GITHUB_TOKEN=${{ secrets.TF_VAR_GITHUB_TOKEN }}
export AWS_ACCESS_KEY_ID=${{ secrets.TF_VAR_AWS_ACCESS_KEY_ID }}
export AWS_SECRET_ACCESS_KEY=${{ secrets.TF_VAR_AWS_SECRET_ACCESS_KEY }}
export MANTIS_COSMOS_MNEMONIC=${{ secrets.TV_VAR_MANTIS_COSMOS_MNEMONIC }}
export MANTIS_COSMOS_MNEMONIC=${{ secrets.TF_VAR_MANTIS_COSMOS_MNEMONIC }}
export CI_SSH_KEY=${{ secrets.TF_VAR_CI_SSH_KEY }}

nix run .#terraform --impure -- init
Expand Down
27 changes: 13 additions & 14 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
};

terraform = pkgs.writeShellScriptBin "terraform" ''
if [ -f .env ]; then
source .env
fi
export TF_VAR_bootstrap_img_path="${bootstrap-img-path}"
export TF_VAR_live_config_path="${live-config}"
export TF_VAR_AWS_REGION="eu-central-1"
Expand Down
13 changes: 13 additions & 0 deletions terraform/aws/mantis.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@ variable "live_config_path" {
type = string
description = "Path to the live NixOS config we want to deploy"
}
variable "MANTIS_COSMOS_MNEMONIC" {
type = string
sensitive = true
}

resource "local_sensitive_file" "ssh_key" {
content = base64decode(var.CI_SSH_KEY)
filename = "${path.module}/${aws_instance.mantis_server.public_dns}"
}

resource "local_sensitive_file" "MANTIS_COSMOS_MNEMONIC" {
content = var.MANTIS_COSMOS_MNEMONIC
filename = "${path.module}/MANTIS_COSMOS_MNEMONIC"
}



resource "null_resource" "nixos_deployment" {
triggers = {
live_config_path = var.live_config_path
public_dns = aws_instance.mantis_server.public_dns
MANTIS_COSMOS_MNEMONIC = var.MANTIS_COSMOS_MNEMONIC
}

provisioner "local-exec" {
command = <<-EOT
ssh-keyscan ${aws_instance.mantis_server.public_dns} >> ~/.ssh/known_hosts
export NIX_SSHOPTS="-i ${local_sensitive_file.ssh_key.filename}"
nix-copy-closure $TARGET ${var.live_config_path}
scp -i ${local_sensitive_file.ssh_key.filename} ${local_sensitive_file.MANTIS_COSMOS_MNEMONIC} $TARGET:~/MANTIS_COSMOS_MNEMONIC
ssh -i ${local_sensitive_file.ssh_key.filename} $TARGET '${var.live_config_path}/bin/switch-to-configuration switch && nix-collect-garbage'
EOT
environment = {
Expand Down
Loading