Skip to content

Commit d71280d

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

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

.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)