Skip to content

Commit 1323206

Browse files
authored
Merge pull request #657 from oasisprotocol/ptrus/feature/builder-artefact-default
Configure builder by default
2 parents fecb52b + 3cbaa26 commit 1323206

File tree

16 files changed

+716
-363
lines changed

16 files changed

+716
-363
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: docker-rofl-container-builder
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- docker/rofl-container-builder/**
9+
- .github/workflows/docker-rofl-container-builder.yml
10+
tags:
11+
- 'rofl-container-builder/v[0-9]+.[0-9]+*'
12+
pull_request:
13+
paths:
14+
- docker/rofl-container-builder/**
15+
- .github/workflows/docker-rofl-container-builder.yml
16+
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
jobs:
22+
build-rofl-container-builder:
23+
name: build-rofl-container-builder
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Determine tag name
30+
id: determine-tag
31+
shell: bash
32+
run: |
33+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
34+
echo "tag=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
35+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
36+
# Trim rofl-container-builder/v prefix from tag
37+
TAG="${{ github.ref_name }}"
38+
TAG="${TAG#rofl-container-builder/v}"
39+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "tag=latest" >> "$GITHUB_OUTPUT"
42+
fi
43+
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v3
47+
48+
- name: Login to ghcr.io
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: "Build and push oasisprotocol/rofl-container-builder:${{ steps.determine-tag.outputs.tag }}"
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: docker/rofl-container-builder
59+
file: docker/rofl-container-builder/Dockerfile
60+
tags: ghcr.io/oasisprotocol/rofl-container-builder:${{ steps.determine-tag.outputs.tag }}
61+
pull: true
62+
push: true
63+
labels: |
64+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
65+
org.opencontainers.image.created=${{ steps.determine-tag.outputs.created }}
66+
org.opencontainers.image.revision=${{ github.sha }}
67+
68+
prune-old-images:
69+
name: prune-old-images
70+
if: ${{ always() }}
71+
needs: [build-rofl-container-builder]
72+
runs-on: ubuntu-latest
73+
steps:
74+
- name: Prune old ghcr.io/oasisprotocol/rofl-container-builder images
75+
uses: vlaurin/[email protected]
76+
with:
77+
token: ${{ secrets.GITHUB_TOKEN }}
78+
organization: oasisprotocol
79+
container: rofl-container-builder
80+
keep-younger-than: 7
81+
keep-last: 2
82+
prune-tags-regexes: ^pr-

build/env/env.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77
"path/filepath"
88
"strings"
9+
"sync"
910

1011
"github.com/oasisprotocol/cli/cmd/common"
1112
)
@@ -86,6 +87,10 @@ type ContainerEnv struct {
8687
}
8788

8889
var containerCmds = []string{"docker", "podman"}
90+
var (
91+
containerCmdPath string
92+
containerCmdOnce sync.Once
93+
)
8994

9095
// NewContainerEnv creates a new Docker or Podman-based execution environment.
9196
func NewContainerEnv(image, baseDir, dirMount string) *ContainerEnv {
@@ -213,12 +218,20 @@ func (de *ContainerEnv) HasBinary(string) bool {
213218

214219
// getContainerCmd finds a working docker or podman command and returns its path.
215220
func getContainerCmd() string {
216-
for _, cmd := range containerCmds {
217-
if path, err := exec.LookPath(cmd); err == nil && path != "" {
218-
return path
221+
containerCmdOnce.Do(func() {
222+
for _, cmd := range containerCmds {
223+
if path, err := exec.LookPath(cmd); err == nil && path != "" {
224+
containerCmdPath = path
225+
return
226+
}
219227
}
220-
}
221-
return ""
228+
})
229+
return containerCmdPath
230+
}
231+
232+
// IsContainerRuntimeAvailable returns true if a container runtime (docker or podman) is available.
233+
func IsContainerRuntimeAvailable() bool {
234+
return getContainerCmd() != ""
222235
}
223236

224237
// IsAvailable implements ExecEnv.

build/rofl/artifacts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package rofl
22

3+
// Builder images for different app kinds.
4+
const (
5+
// LatestBuilderImage is the full builder with Rust toolchain for raw apps.
6+
LatestBuilderImage = "ghcr.io/oasisprotocol/rofl-dev:v0.5.0@sha256:31573686552abeb0edebc450f6872831f0006a6cf38220cef7e0789d4376c2c1"
7+
// LatestContainerBuilderImage is the minimal builder for container apps.
8+
LatestContainerBuilderImage = "ghcr.io/oasisprotocol/rofl-container-builder:0.0.1@sha256:913ef97ab07dde31f08ce873f825bf3d4f32ad4102ff5797d7c3050c121c4dce"
9+
)
10+
311
// LatestBasicArtifacts are the latest TDX ROFL basic app artifacts.
412
var LatestBasicArtifacts = ArtifactsConfig{
513
Firmware: "https://github.com/oasisprotocol/oasis-boot/releases/download/v0.6.2/ovmf.tdx.fd#db47100a7d6a0c1f6983be224137c3f8d7cb09b63bb1c7a5ee7829d8e994a42f",

build/rofl/manifest.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,19 @@ type Manifest struct {
7676
// Scripts are custom scripts that are executed by the build system at specific stages.
7777
Scripts map[string]string `yaml:"scripts,omitempty" json:"scripts,omitempty"`
7878

79+
// Tooling contains information about the tooling used to generate/update the manifest.
80+
Tooling *ToolingConfig `yaml:"tooling,omitempty" json:"tooling,omitempty"`
81+
7982
// sourceFn is the filename from which the manifest has been loaded.
8083
sourceFn string
8184
}
8285

86+
// ToolingConfig contains information about the tooling used to manage the manifest.
87+
type ToolingConfig struct {
88+
// Version is the CLI version that last modified this manifest.
89+
Version string `yaml:"version" json:"version"`
90+
}
91+
8392
// ManifestExists checks whether a manifest file exist. No attempt is made to load, parse or
8493
// validate any of the found manifest files.
8594
func ManifestExists() bool {

build/sgxs/sgxs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
// It requires the `ftxsgx-elf2sgxs` utility to be installed.
1616
func Elf2Sgxs(buildEnv env.ExecEnv, elfSgxPath, sgxsPath string, heapSize, stackSize, threads uint64) (err error) {
1717
if elfSgxPath, err = buildEnv.PathToEnv(elfSgxPath); err != nil {
18-
return
18+
return err
1919
}
2020
if sgxsPath, err = buildEnv.PathToEnv(sgxsPath); err != nil {
21-
return
21+
return err
2222
}
2323

2424
args := []string{
@@ -31,7 +31,7 @@ func Elf2Sgxs(buildEnv env.ExecEnv, elfSgxPath, sgxsPath string, heapSize, stack
3131

3232
cmd := exec.Command("ftxsgx-elf2sgxs", args...)
3333
if err = buildEnv.WrapCommand(cmd); err != nil {
34-
return
34+
return err
3535
}
3636
if common.IsVerbose() {
3737
fmt.Println(cmd)

0 commit comments

Comments
 (0)