Skip to content

Commit b9624ae

Browse files
committed
feat: automated AMI build on release via workflow_run
- Add .github/workflows/build-ami.yml (triggers after Release completes) - Add scripts/dappnode_ami_build.sh (prerequisites + pre-download + rc.local) - release.yml: rename to Release, mark as full release (not prerelease) - Workflow reuses existing AWS component, just bumps recipe and triggers - IAM role updated: added GetImageRecipe, removed unused CreateComponent
1 parent 529782a commit b9624ae

3 files changed

Lines changed: 18 additions & 57 deletions

File tree

.github/workflows/build-ami.yml

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build DAppNode AMI
22

33
on:
44
workflow_run:
5-
workflows: ["Pre-release"]
5+
workflows: ["Release"]
66
types: [completed]
77

88
permissions:
@@ -15,72 +15,35 @@ jobs:
1515
runs-on: ubuntu-latest
1616
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1717
steps:
18-
- name: Get release tag
19-
id: tag
20-
env:
21-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22-
run: |
23-
# Get the latest pre-release tag (the one just created by the triggering workflow)
24-
TAG=$(gh release list --repo ${{ github.repository }} \
25-
--limit 1 --json tagName --jq '.[0].tagName')
26-
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
27-
echo "Release tag: $TAG"
28-
2918
- name: Configure AWS credentials via OIDC
3019
uses: aws-actions/configure-aws-credentials@v4
3120
with:
3221
role-to-assume: ${{ secrets.IMAGE_BUILDER_ROLE_ARN }}
3322
aws-region: us-east-1
3423

35-
- name: Create component, recipe, and trigger AMI build
24+
- name: Bump recipe and trigger AMI build
3625
env:
3726
PIPELINE_ARN: ${{ secrets.IMAGE_BUILDER_PIPELINE_ARN }}
3827
INFRA_ARN: ${{ secrets.IMAGE_BUILDER_INFRA_ARN }}
3928
DIST_ARN: ${{ secrets.IMAGE_BUILDER_DIST_ARN }}
40-
TAG: ${{ steps.tag.outputs.tag }}
4129
run: |
42-
PROFILE_URL="https://github.com/dappnode/DAppNode/releases/download/${TAG}/dappnode_profile.sh"
43-
SCRIPT_URL="https://raw.githubusercontent.com/dappnode/DAppNode/${TAG}/scripts/dappnode_ami_build.sh"
44-
45-
# Derive component version from tag (v0.2.47 -> 0.2.47)
46-
COMP_VERSION="${TAG#v}"
47-
48-
# Create per-release component (thin wrapper: downloads repo script and runs it)
49-
COMPONENT_ARN=$(aws imagebuilder create-component \
50-
--name "dappnode-build" \
51-
--semantic-version "$COMP_VERSION" \
52-
--platform "Linux" \
53-
--supported-os-versions "Ubuntu" \
54-
--data "$(cat <<EOF
55-
name: DAppNodeBuild
56-
schemaVersion: 1.0
57-
phases:
58-
- name: build
59-
steps:
60-
- name: RunBuildScript
61-
action: ExecuteBash
62-
inputs:
63-
commands:
64-
- |
65-
export PROFILE_URL="${PROFILE_URL}"
66-
wget -O /tmp/dappnode_ami_build.sh "${SCRIPT_URL}"
67-
chmod +x /tmp/dappnode_ami_build.sh
68-
/tmp/dappnode_ami_build.sh
69-
EOF
70-
)" \
71-
--query 'componentBuildVersionArn' --output text)
72-
echo "Component: $COMPONENT_ARN"
73-
74-
# Get current recipe version and patch bump
75-
CURRENT_RECIPE=$(aws imagebuilder get-image-pipeline \
30+
# Get current recipe and extract component + version
31+
CURRENT_RECIPE_ARN=$(aws imagebuilder get-image-pipeline \
7632
--image-pipeline-arn "$PIPELINE_ARN" \
7733
--query 'imagePipeline.imageRecipeArn' --output text)
78-
CURRENT_VERSION=$(echo "$CURRENT_RECIPE" | grep -oP '[0-9]+\.[0-9]+\.[0-9]+$')
34+
35+
CURRENT_VERSION=$(echo "$CURRENT_RECIPE_ARN" | grep -oP '[0-9]+\.[0-9]+\.[0-9]+$')
7936
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
8037
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
8138
echo "Recipe: $CURRENT_VERSION -> $NEW_VERSION"
8239
83-
# Create recipe with per-release component
40+
# Get component from current recipe
41+
COMPONENT_ARN=$(aws imagebuilder get-image-recipe \
42+
--image-recipe-arn "$CURRENT_RECIPE_ARN" \
43+
--query 'imageRecipe.components[0].componentArn' --output text)
44+
echo "Component: $COMPONENT_ARN"
45+
46+
# Create new recipe version (same component, latest Ubuntu 24)
8447
RECIPE_ARN=$(aws imagebuilder create-image-recipe \
8548
--name "dappnode-image" \
8649
--semantic-version "$NEW_VERSION" \
@@ -103,7 +66,5 @@ jobs:
10366
--query 'imageBuildVersionArn' --output text)
10467
10568
echo "### AMI Build Triggered 🚀" >> "$GITHUB_STEP_SUMMARY"
106-
echo "- **Tag:** ${TAG}" >> "$GITHUB_STEP_SUMMARY"
10769
echo "- **Recipe:** ${NEW_VERSION}" >> "$GITHUB_STEP_SUMMARY"
108-
echo "- **Profile:** ${PROFILE_URL}" >> "$GITHUB_STEP_SUMMARY"
10970
echo "- **Image ARN:** ${EXECUTION}" >> "$GITHUB_STEP_SUMMARY"

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pre-release
1+
name: Release
22

33
on:
44
workflow_dispatch:
@@ -248,11 +248,11 @@ jobs:
248248
run: |
249249
echo "Images directory content:"
250250
ls -lrt images/
251-
- name: Create pre-release
251+
- name: Create release
252252
uses: softprops/action-gh-release@v2
253253
with:
254254
tag_name: ${{ needs.set-versions.outputs.core }}
255-
prerelease: true
255+
prerelease: false
256256
files: |
257257
./images/Dappnode-*-debian-*-attended.iso
258258
./images/Dappnode-*-debian-*-unattended.iso

scripts/dappnode_ami_build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# first-boot installer for EC2 Image Builder.
55
#
66
# Env vars:
7-
# PROFILE_URL — URL to dappnode_profile.sh with pinned versions (required)
7+
# PROFILE_URL — URL to dappnode_profile.sh (defaults to latest release)
88
#
99
# The installer still runs at first boot (via rc.local), but finds the heavy
1010
# Docker images already cached in /usr/src/dappnode/DNCORE/, making boot fast.
1111

1212
set -euo pipefail
1313

14-
: "${PROFILE_URL:?PROFILE_URL env var is required}"
14+
: "${PROFILE_URL:=https://github.com/dappnode/DAppNode/releases/latest/download/dappnode_profile.sh}"
1515

1616
DAPPNODE_DIR="/usr/src/dappnode"
1717
DNCORE_DIR="$DAPPNODE_DIR/DNCORE"

0 commit comments

Comments
 (0)