Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 68 additions & 20 deletions .github/workflows/PRBuild.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,97 @@
name: Build PR with goreleaser
# Copyright © 2025 OpenCHAMI a Series of LF Projects, LLC
#
# SPDX-License-Identifier: MIT

name: Build each PR for testing and validation

on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened, edited]
workflow_dispatch:

inputs:
pr_number:
description: 'PR Number to build (optional, for manual PR builds)'
required: false
type: string

permissions: write-all # Necessary for the generate-build-provenance action with containers

jobs:
prbuild:

build:


runs-on: ubuntu-latest
steps:
- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

steps:
- name: Set up latest stable Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6.4.0
with:
go-version: stable
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
driver-opts: |
image=moby/buildkit:master
network=host
- name: Docker Login
uses: docker/login-action@v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6.0.2
with:
fetch-tags: 1
fetch-depth: 1

fetch-depth: 0
# Set environment variables required by GoReleaser
- name: Set build environment variables
run: |
echo "GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" >> $GITHUB_ENV
echo "BUILD_HOST=$(hostname)" >> $GITHUB_ENV
echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV
echo "BUILD_USER=$(whoami)" >> $GITHUB_ENV
echo "CGO_ENABLED=1" >> $GITHUB_ENV
echo "CGO_ENABLED=0" >> $GITHUB_ENV
echo "IS_PR_BUILD=true" >> $GITHUB_ENV

- name: Docker Login
uses: docker/login-action@v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create Tag for PR
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.pr_number != '')
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
PR_NUM="${{ github.event.number }}"
if [[ "${{ inputs.pr_number }}" != "" ]]; then
PR_NUM="${{ inputs.pr_number }}"
fi
git tag -f -a pr-${PR_NUM} -m "PR Release"

- name: Build with goreleaser
uses: goreleaser/goreleaser-action@v6
- name: Build/Push container with goreleaser
uses: goreleaser/goreleaser-action@v7
env:
GITHUB_TOKEN: ${{ github.token }}
with:
version: '~> v2'
args: build --clean --snapshot
id: goreleaser
version: '~> 2'
args: release --clean --skip=announce,validate,archive
id: goreleaser
- name: Process goreleaser output
id: process_goreleaser_output
run: |
echo "const fs = require('fs');" > process.js
echo 'const artifacts = ${{ steps.goreleaser.outputs.artifacts }}' >> process.js
echo "const firstNonNullDigest = artifacts.find(artifact => artifact.extra && artifact.extra.Digest != null)?.extra.Digest;" >> process.js
echo "console.log(firstNonNullDigest);" >> process.js
echo "fs.writeFileSync('digest.txt', firstNonNullDigest);" >> process.js
node process.js
echo "digest=$(cat digest.txt)" >> $GITHUB_OUTPUT
81 changes: 25 additions & 56 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
version: 2.4
version: 2
project_name: smd
before:
hooks:
# You may remove this if you don't use go modules.
- go mod download
- go mod tidy

builds:
Expand Down Expand Up @@ -90,66 +91,34 @@ builds:
env:
- CGO_ENABLED=0

dockers:
- image_templates:
- &amd64_linux_image ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}-amd64
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-amd64
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-amd64
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
goarch: amd64
goamd64: v3

extra_files:
- LICENSE
- CHANGELOG.md
- README.md
- migrations/
- image_templates:
- &arm64v8_linux_image ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}-arm64
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-arm64
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-arm64
use: buildx
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
dockers_v2:
- id: smd
ids:
- smd
- smd-init
- smd-loader
images:
- ghcr.io/openchami/{{.ProjectName}}
tags:
- latest
- "{{ .Tag }}"
- "{{ .Major }}"
- "{{ .Major }}.{{ .Minor }}"
labels:
org.opencontainers.image.created: "{{.Date}}"
org.opencontainers.image.title: "{{.ProjectName}}"
org.opencontainers.image.revision: "{{.FullCommit}}"
org.opencontainers.image.version: "{{.Version}}"
platforms:
- linux/amd64
- linux/arm64
flags:
- --pull
extra_files:
- LICENSE
- CHANGELOG.md
- README.md
- migrations/
goarch: arm64

docker_manifests:
- name_template: "ghcr.io/openchami/{{.ProjectName}}:latest"
image_templates:
- *amd64_linux_image
- *arm64v8_linux_image

- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}"
image_templates:
- *amd64_linux_image
- *arm64v8_linux_image

- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}"
image_templates:
- *amd64_linux_image
- *arm64v8_linux_image

- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}"
image_templates:
- *amd64_linux_image
- *arm64v8_linux_image

archives:
- format: tar.gz
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ RUN set -ex \
&& rm -rf /var/cache/apk/* \
&& rm -rf /tmp/*

COPY smd /
COPY smd-loader /
COPY smd-init /
ARG TARGETPLATFORM
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly change to the following where the current directory is the default value

ARG TARGETPLATFORM=.

This allows me to run

make binaries image

Alternately tell me how you build smd.


COPY $TARGETPLATFORM/smd /
COPY $TARGETPLATFORM/smd-loader /
COPY $TARGETPLATFORM/smd-init /
RUN mkdir /persistent_migrations
COPY migrations/* /persistent_migrations/

Expand Down
Loading
Loading