Skip to content

Commit c7590af

Browse files
committed
Add example repo
1 parent 1e3c4e2 commit c7590af

File tree

9 files changed

+1101
-1
lines changed

9 files changed

+1101
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Release and Upload SBOM to Balena
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
env:
10+
FLEET_SLUG: org3/test
11+
12+
jobs:
13+
build-and-release:
14+
if: github.event.pull_request.merged == true
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20'
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Generate SBOM using Syft
30+
run: |
31+
# Install Syft for SBOM generation
32+
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /tmp
33+
34+
# Generate SBOM in multiple formats
35+
echo "Generating SBOM in SPDX JSON format..."
36+
/tmp/syft . -o spdx-json=sbom-spdx.json
37+
38+
echo "Generating SBOM in CycloneDX JSON format..."
39+
/tmp/syft . -o cyclonedx-json=sbom-cyclonedx.json
40+
41+
echo "Generating SBOM in Syft JSON format..."
42+
/tmp/syft . -o syft-json=sbom-syft.json
43+
44+
# Create a tarball of all SBOMs
45+
tar -czf sboms.tar.gz sbom-*.json
46+
47+
echo "SBOM files generated:"
48+
ls -la sbom-*.json sboms.tar.gz
49+
50+
- name: balena CLI Action
51+
uses: balena-io-experimental/[email protected]
52+
with:
53+
balena_token: ${{secrets.BALENA_API_TOKEN}}
54+
55+
- name: Create Balena Release
56+
id: create-release
57+
run: |
58+
# Push to Balena and create a release
59+
echo "Creating release for fleet: ${{ env.FLEET_SLUG }}"
60+
61+
# Build and push the release
62+
balena push ${{ env.FLEET_SLUG }} --release-tag version=${{ github.ref_name || 'latest' }}
63+
64+
# Get the latest release ID
65+
RELEASE_ID=$(balena releases ${{ env.FLEET_SLUG }} --json | jq -r '.[0].id')
66+
echo "Release ID: $RELEASE_ID"
67+
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
68+
69+
70+
- name: Upload All SBOM Assets
71+
uses: balena-io/upload-balena-release-asset@main
72+
with:
73+
balena-token: ${{ secrets.BALENA_API_TOKEN }}
74+
release-id: ${{ steps.create-release.outputs.release_id }}
75+
path: |
76+
sbom-spdx.json
77+
sbom-cyclonedx.json
78+
sbom-syft.json
79+
sboms.tar.gz

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
npm-debug.log*
3+
.DS_Store
4+
*.log
5+
.env
6+
.env.local
7+
sbom-*.json
8+
sboms.tar.gz

Dockerfile.template

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM node:22-bookworm-slim AS build
2+
3+
# Defines our working directory in container
4+
WORKDIR /build
5+
6+
# Copies the package.json first for better cache on later pushes
7+
COPY package*.json ./
8+
9+
# Install npm dependencies
10+
RUN JOBS=MAX npm ci --omit=dev
11+
12+
# This will copy all files in our root to the working directory in the container
13+
COPY . ./
14+
15+
# Image that will be used to run the application
16+
FROM node:22-bookworm-slim
17+
18+
ENV NODE_ENV=production
19+
WORKDIR /usr/src/app
20+
21+
COPY --from=build /build .
22+
23+
# Use node user instead of root for security
24+
USER node
25+
26+
# Use exec form for better signal handling
27+
CMD ["node", "src/server.js"]

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# release-assets-hello-world
1+
# Balena Hello World with SBOM Upload Example
2+
3+
This repository demonstrates how to set up a GitHub Action workflow that:
4+
1. Creates a balena release
5+
2. Generates Software Bill of Materials (SBOM) in multiple formats
6+
3. Uploads SBOM files as balena release assets using the `balena-io/upload-balena-release-asset` action
7+
8+
## Features
9+
10+
- Simple Node.js Express application
11+
- Multi-architecture support via balena
12+
- Automated SBOM generation using Syft
13+
- SBOM upload to balena releases
14+
- GitHub release creation with SBOM artifacts

balena.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: balena-hello-world-sbom
2+
type: sw.application
3+
description: >-
4+
A simple hello world application demonstrating SBOM generation and upload
5+
using GitHub Actions and balena release assets.

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '2'
2+
services:
3+
hello-world:
4+
build: .
5+
ports:
6+
- "80:80"
7+
restart: always
8+
labels:
9+
io.balena.features.supervisor-api: '1'
10+
environment:
11+
- PORT=80

0 commit comments

Comments
 (0)