Skip to content

Commit

Permalink
add initial Github Actions for pushing AMIs
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineChikhaoui committed Jun 5, 2023
1 parent 5c3859c commit d3b72a3
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/create-amis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Create NixOS AMIs

on:
workflow_dispatch:
workflow_call:
inputs:
release:
required: true
type: string
architecture:
required: true
type: string
default: x86_64
build_nr:
required: true
type: number

permissions:
id-token: write
contents: read

env:
AWS_REGION: "eu-west-1"

jobs:
create-nixos-amis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::080433136561:role/nixos-image-creator
role-session-name: gha-terraform-deploy-amis
aws-region: ${{ env.AWS_REGION }}
- working-directory: amis
id: get-build
run: |
echo "build_json=$(curl -H 'Content-type: application/json' \
https://hydra.nixos.org/build/${{inputs.build_nr}})" > "$GITHUB_OUTPUT"
- working-directory: amis
id: get-store-path
run: |
echo ${{steps.get-build.outputs.build_json}} \
| nix develop --command jq '.buildoutputs|.out|"store_path=\(.path)"' -r > "$GITHUB_OUTPUT"
- run: nix-store -r ${{steps.get-store-path.outputs.store_path}}
- run: nix develop --command jq -f regions.jq regions.json > copy.tf.json
working-directory: amis
- run: |
nix develop --command \
terraform workspace select -or-create \
${{inputs.release}}.${{inputs.architecture}}.${{inputs.build_nr}}
working-directory: amis
- run: |
nix develop --command \
terraform plan -var image_store_path=${{steps.get-store-path.outputs.store_path}}
60 changes: 60 additions & 0 deletions amis/flake.lock

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

26 changes: 26 additions & 0 deletions amis/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
inputs = {
nixpkgs.url = "nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = flakes @ { self, nixpkgs, flake-utils }:

flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells = {
default = with pkgs;
mkShell {
buildInputs = [
jq
(terraform.withPlugins (p: with p; [
aws
]))
];
};
};
});
}

0 comments on commit d3b72a3

Please sign in to comment.