Skip to content

Commit

Permalink
add top level workflow for pushing AMIs
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineChikhaoui committed Jun 5, 2023
1 parent 4c44c09 commit 1a20608
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/create-amis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ on:
build_nr:
required: true
type: number

permissions:
id-token: write
contents: read
description: hydra.nixos.org image build number

env:
AWS_REGION: "eu-west-1"
Expand All @@ -43,11 +40,14 @@ jobs:
- working-directory: amis
id: get-store-path
run: |
echo ${{steps.get-build.outputs.build_json}} \
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 init
working-directory: amis
- run: |
nix develop --command \
terraform workspace select -or-create \
Expand All @@ -56,3 +56,4 @@ jobs:
- run: |
nix develop --command \
terraform plan -var image_store_path=${{steps.get-store-path.outputs.store_path}}
working-directory: amis
25 changes: 25 additions & 0 deletions .github/workflows/release-amis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Push current NixOS release AMIs

on:
workflow_dispatch:
# TODO: just for testing, switch to workflow_dispatch only
push:
branches: ["terraform-create-amis"]

permissions:
id-token: write
contents: read

jobs:
x86_64-amis:
uses: ./.github/workflows/create-amis.yml
with:
build_nr: 222822268
architecture: x86_64
release: "23.05"
aarch64-amis:
uses: ./.github/workflows/create-amis.yml
with:
build_nr: 222822272
architecture: aarch64
release: "23.05"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Terraform
.terraform*
!.terraform.lock.hcl
*tfstate
*tfstate.backup
*.aarch64.*.tfvars
Expand Down
24 changes: 0 additions & 24 deletions amis/.terraform.lock.hcl

This file was deleted.

3 changes: 2 additions & 1 deletion amis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

arch=x86_64
version=23.05
build-nr=

tfvarsFile=$(version).$(arch).current.tfvars

$(tfvarsFile) .current-workspace:
./pull-latest $(version) $(arch)
./pull-latest $(version) $(arch) $(build-nr)

copy.tf.json: regions.jq regions.json
@jq -f regions.jq regions.json > copy.tf.json
Expand Down
18 changes: 13 additions & 5 deletions amis/pull-latest
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#! /usr/bin/env bash
#

version="$1"
arch="$2"
hydraJob="nixos.amazonImage"
baseUrl="https://hydra.nixos.org/job/nixos"

build=$(curl -sL \
-H 'Content-type: application/json' \
"${baseUrl}/release-${version}-small/${hydraJob}.${arch}-linux/latest")
version="$1"
arch="$2"
buildNr="$3"

if [[ -z "$buildNr" ]]
then
buildUrl="${baseUrl}/release-${version}-small/${hydraJob}.${arch}-linux/latest"
else
buildUrl="${baseUrl}/build/${buildNr}"
fi


build=$(curl -sL -H 'Content-type: application/json' "$buildUrl")

storePath=$(echo "$build" | jq '.buildoutputs|.out|.path' -r)
buildId=$(echo "$build" | jq .id -r)
Expand Down

0 comments on commit 1a20608

Please sign in to comment.