Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexlovelltroy/build improvements #48

Merged
merged 9 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
49 changes: 49 additions & 0 deletions .github/workflows/PRBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build PR with goreleaser

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


jobs:
prbuild:
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

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

- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: 1
fetch-depth: 1

# 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


- name: Build with goreleaser
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ github.token }}
with:
version: '~> v2'
args: build --clean --snapshot
id: goreleaser
71 changes: 45 additions & 26 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Release with goreleaser

on:
push:
tags:
- v*
permissions: write-all # Necessary for creating containers

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

jobs:

build:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.21
- name: Install cross-compilation tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

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

- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: 1
fetch-depth: 1

# 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

- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: 1
fetch-depth: 1
- name: Set version in .version file
run: make version
- name: Unit Tests
run: go test -v ./...
- name: Release with goreleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ github.token }}
with:
version: latest
version: '~> v2'
args: release --clean
id: goreleaser

- name: Process goreleaser output
id: process_goreleaser_output
run: |
Expand All @@ -54,16 +62,27 @@ jobs:
echo "fs.writeFileSync('digest.txt', firstNonNullDigest);" >> process.js
node process.js
echo "digest=$(cat digest.txt)" >> $GITHUB_OUTPUT
- name: Attest boot-script-service binary
uses: github-early-access/generate-build-provenance@main

- name: Attest boot-script-service binary amd64
uses: actions/attest-build-provenance@v1
with:
subject-path: dist/bss_linux_amd64_v4/boot-script-service
- name: Attest boot-script-service binary arm64
synackd marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/attest-build-provenance@v1
with:
subject-path: dist/boot-script-service
- name: Attest bss-init binary
uses: github-early-access/generate-build-provenance@main
subject-path: dist/bss_linux_arm64_v8.0/boot-script-service
- name: Attest bss-init binary amd64
uses: actions/attest-build-provenance@v1
with:
subject-path: dist/bss-init
subject-path: dist/bss-init_linux_amd64_v4/bss-init
- name: Attest bss-init binary arm64
uses: actions/attest-build-provenance@v1
with:
subject-path: dist/bss-init_linux_arm64_v8.0/bss-init


- name: generate build provenance
uses: github-early-access/generate-build-provenance@main
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/openchami/bss
subject-digest: ${{ steps.process_goreleaser_output.outputs.digest }}
Expand Down
38 changes: 32 additions & 6 deletions .github/workflows/unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,40 @@
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
- name: Checkout
uses: actions/checkout@v4
with:
go-version: '1.21.x'
fetch-tags: 1
fetch-depth: 1

- name: Set up latest stable Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Install dependencies
run: go get ./boot-script-service ./bss-init
- name: Generate .version
run: make -C ../ version

- name: Test with the Go CLI
run: go test ./boot-script-service ./bss-init

# 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


- name: Build with goreleaser
uses: goreleaser/goreleaser-action@v6
with:
version: '~> v2'
args: build --clean --snapshot
id: goreleaser


5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
kubernetes/.packaged/
.idea/
*.swp
.version

# Binaries
boot-script-service
alexlovelltroy marked this conversation as resolved.
Show resolved Hide resolved
bss-init

# Prevent certificates from getting checked in
*.ca
Expand Down
119 changes: 103 additions & 16 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
version: 2.4

project_name: bss
before:
Expand All @@ -13,42 +12,110 @@ builds:
binary: boot-script-service
goos:
- linux
- darwin
goarch:
- amd64
no_unique_dist_dir: true
tags:
- dynamic
- arm64
goamd64:
- v4
env:
- CGO_ENABLED=0
ldflags:
- "-s -w -X main.GitCommit={{.Commit}} \
-X main.BuildTime={{.Timestamp}} \
-X main.Version={{.Version}} \
-X main.GitBranch={{.Branch}} \
-X main.GitTag={{.Tag}} \
-X main.GitState={{ .Env.GIT_STATE }} \
-X main.BuildHost={{ .Env.BUILD_HOST }} \
-X main.GoVersion={{ .Env.GO_VERSION }} \
-X main.BuildUser={{ .Env.BUILD_USER }} "

- id: bss-init
main: ./cmd/bss-init
binary: bss-init
goos:
- linux
- darwin
goarch:
- amd64
no_unique_dist_dir: true
tags:
- dynamic
- arm64
goamd64:
- v4
env:
synackd marked this conversation as resolved.
Show resolved Hide resolved
- CGO_ENABLED=0
ldflags:
- "-s -w -X main.GitCommit={{.Commit}} \
-X main.BuildTime={{.Timestamp}} \
-X main.Version={{.Version}} \
-X main.GitBranch={{.Branch}} \
-X main.GitTag={{.Tag}} \
-X main.GitState={{ .Env.GIT_STATE }} \
-X main.BuildHost={{ .Env.BUILD_HOST }} \
-X main.GoVersion={{ .Env.GO_VERSION }} \
-X main.BuildUser={{ .Env.BUILD_USER }} "

dockers:
-
image_templates:
- ghcr.io/openchami/{{.ProjectName}}:latest
- ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}
- 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: v4
extra_files:
- LICENSE
- CHANGELOG.md
- README.md
- .version
- 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}}"
goarch: arm64
extra_files:
- LICENSE
- CHANGELOG.md
- README.md
- migrations/

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
# this name template makes the OS and Arch compatible with the results of uname.
Expand All @@ -65,10 +132,30 @@ archives:
- README.md



nfpms:
- id: bss
formats:
- deb
- rpm
- apk
maintainer: "Alex Lovell-Troy <alovelltroy@lanl.gov>"
description: "BSS is a tool for managing the bootscripts of an HPC system. Read more at https://www.openchami.org"
homepage: "https://www.openchami.org"
license: MIT
section: utils
priority: optional
contents:
- src: dist/bss_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else if eq .Arch "arm64" }}{{ .Arch }}_{{ .Arm64 }}{{ else }}{{ .Arch }}{{ end }}/boot-script-service
dst: /usr/local/bin/bss
- src: dist/bss-init_{{ .Os }}_{{ if eq .Arch "amd64" }}{{ .Arch }}_{{ .Amd64 }}{{ else if eq .Arch "arm64" }}{{ .Arch }}_{{ .Arm64 }}{{ else }}{{ .Arch }}{{ end }}/bss-init
dst: /usr/local/bin/bss-init


checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ RUN set -ex \
COPY boot-script-service /usr/local/bin/
COPY bss-init /usr/local/bin/
COPY migrations/* /migrations/
COPY .version /

# nobody 65534:65534
USER 65534:65534
Expand Down
Loading
Loading