Skip to content

Commit 63e5600

Browse files
Merge pull request #86 from OpenCHAMI/feature/tokensmith-auth
Feature/tokensmith auth
2 parents 4a8177b + b73b691 commit 63e5600

13 files changed

Lines changed: 1627 additions & 165 deletions

File tree

.github/workflows/PRBuild.yml

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,97 @@
1-
name: Build PR with goreleaser
1+
# Copyright © 2025 OpenCHAMI a Series of LF Projects, LLC
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
name: Build each PR for testing and validation
26

37
on:
48
pull_request:
59
branches:
610
- main
711
types: [opened, synchronize, reopened, edited]
812
workflow_dispatch:
9-
13+
inputs:
14+
pr_number:
15+
description: 'PR Number to build (optional, for manual PR builds)'
16+
required: false
17+
type: string
18+
19+
permissions: write-all # Necessary for the generate-build-provenance action with containers
1020

1121
jobs:
12-
prbuild:
22+
23+
build:
24+
25+
1326
runs-on: ubuntu-latest
14-
steps:
15-
- name: Install cross-compilation tools
16-
run: |
17-
sudo apt-get update
18-
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
1927

28+
steps:
2029
- name: Set up latest stable Go
21-
uses: actions/setup-go@v5
30+
uses: actions/setup-go@v6.4.0
2231
with:
2332
go-version: stable
2433
- name: Set up QEMU
25-
uses: docker/setup-qemu-action@v3
26-
34+
uses: docker/setup-qemu-action@v4
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v4
37+
with:
38+
driver-opts: |
39+
image=moby/buildkit:master
40+
network=host
41+
- name: Docker Login
42+
uses: docker/login-action@v4.1.0
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
2747
- name: Checkout
28-
uses: actions/checkout@v4
48+
uses: actions/checkout@v6.0.2
2949
with:
3050
fetch-tags: 1
31-
fetch-depth: 1
32-
51+
fetch-depth: 0
3352
# Set environment variables required by GoReleaser
3453
- name: Set build environment variables
3554
run: |
3655
echo "GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" >> $GITHUB_ENV
3756
echo "BUILD_HOST=$(hostname)" >> $GITHUB_ENV
3857
echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV
3958
echo "BUILD_USER=$(whoami)" >> $GITHUB_ENV
40-
echo "CGO_ENABLED=1" >> $GITHUB_ENV
59+
echo "CGO_ENABLED=0" >> $GITHUB_ENV
60+
echo "IS_PR_BUILD=true" >> $GITHUB_ENV
61+
62+
- name: Docker Login
63+
uses: docker/login-action@v4.1.0
64+
with:
65+
registry: ghcr.io
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Create Tag for PR
70+
if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.pr_number != '')
71+
run: |
72+
git config --global user.name "github-actions[bot]"
73+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
74+
PR_NUM="${{ github.event.number }}"
75+
if [[ "${{ inputs.pr_number }}" != "" ]]; then
76+
PR_NUM="${{ inputs.pr_number }}"
77+
fi
78+
git tag -f -a pr-${PR_NUM} -m "PR Release"
4179
42-
- name: Build with goreleaser
43-
uses: goreleaser/goreleaser-action@v6
80+
- name: Build/Push container with goreleaser
81+
uses: goreleaser/goreleaser-action@v7
4482
env:
4583
GITHUB_TOKEN: ${{ github.token }}
4684
with:
47-
version: '~> v2'
48-
args: build --clean --snapshot
49-
id: goreleaser
85+
version: '~> 2'
86+
args: release --clean --skip=announce,validate,archive
87+
id: goreleaser
88+
- name: Process goreleaser output
89+
id: process_goreleaser_output
90+
run: |
91+
echo "const fs = require('fs');" > process.js
92+
echo 'const artifacts = ${{ steps.goreleaser.outputs.artifacts }}' >> process.js
93+
echo "const firstNonNullDigest = artifacts.find(artifact => artifact.extra && artifact.extra.Digest != null)?.extra.Digest;" >> process.js
94+
echo "console.log(firstNonNullDigest);" >> process.js
95+
echo "fs.writeFileSync('digest.txt', firstNonNullDigest);" >> process.js
96+
node process.js
97+
echo "digest=$(cat digest.txt)" >> $GITHUB_OUTPUT

.goreleaser.yaml

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
version: 2.4
1+
version: 2
22
project_name: smd
33
before:
44
hooks:
55
# You may remove this if you don't use go modules.
6+
- go mod download
67
- go mod tidy
78

89
builds:
@@ -90,66 +91,34 @@ builds:
9091
env:
9192
- CGO_ENABLED=0
9293

93-
dockers:
94-
- image_templates:
95-
- &amd64_linux_image ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}-amd64
96-
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-amd64
97-
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-amd64
98-
use: buildx
99-
build_flag_templates:
100-
- "--pull"
101-
- "--platform=linux/amd64"
102-
- "--label=org.opencontainers.image.created={{.Date}}"
103-
- "--label=org.opencontainers.image.title={{.ProjectName}}"
104-
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
105-
- "--label=org.opencontainers.image.version={{.Version}}"
106-
goarch: amd64
107-
goamd64: v3
108-
109-
extra_files:
110-
- LICENSE
111-
- CHANGELOG.md
112-
- README.md
113-
- migrations/
114-
- image_templates:
115-
- &arm64v8_linux_image ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}-arm64
116-
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-arm64
117-
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-arm64
118-
use: buildx
119-
build_flag_templates:
120-
- "--pull"
121-
- "--platform=linux/arm64"
122-
- "--label=org.opencontainers.image.created={{.Date}}"
123-
- "--label=org.opencontainers.image.title={{.ProjectName}}"
124-
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
125-
- "--label=org.opencontainers.image.version={{.Version}}"
94+
dockers_v2:
95+
- id: smd
96+
ids:
97+
- smd
98+
- smd-init
99+
- smd-loader
100+
images:
101+
- ghcr.io/openchami/{{.ProjectName}}
102+
tags:
103+
- latest
104+
- "{{ .Tag }}"
105+
- "{{ .Major }}"
106+
- "{{ .Major }}.{{ .Minor }}"
107+
labels:
108+
org.opencontainers.image.created: "{{.Date}}"
109+
org.opencontainers.image.title: "{{.ProjectName}}"
110+
org.opencontainers.image.revision: "{{.FullCommit}}"
111+
org.opencontainers.image.version: "{{.Version}}"
112+
platforms:
113+
- linux/amd64
114+
- linux/arm64
115+
flags:
116+
- --pull
126117
extra_files:
127118
- LICENSE
128119
- CHANGELOG.md
129120
- README.md
130121
- migrations/
131-
goarch: arm64
132-
133-
docker_manifests:
134-
- name_template: "ghcr.io/openchami/{{.ProjectName}}:latest"
135-
image_templates:
136-
- *amd64_linux_image
137-
- *arm64v8_linux_image
138-
139-
- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}"
140-
image_templates:
141-
- *amd64_linux_image
142-
- *arm64v8_linux_image
143-
144-
- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}"
145-
image_templates:
146-
- *amd64_linux_image
147-
- *arm64v8_linux_image
148-
149-
- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}"
150-
image_templates:
151-
- *amd64_linux_image
152-
- *arm64v8_linux_image
153122

154123
archives:
155124
- format: tar.gz

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ RUN set -ex \
99
&& rm -rf /var/cache/apk/* \
1010
&& rm -rf /tmp/*
1111

12-
COPY smd /
13-
COPY smd-loader /
14-
COPY smd-init /
12+
ARG TARGETPLATFORM
13+
14+
COPY $TARGETPLATFORM/smd /
15+
COPY $TARGETPLATFORM/smd-loader /
16+
COPY $TARGETPLATFORM/smd-init /
1517
RUN mkdir /persistent_migrations
1618
COPY migrations/* /persistent_migrations/
1719

0 commit comments

Comments
 (0)