Skip to content

Commit 548c07c

Browse files
ci: build and publish pre-compute OCI image to docker-regis (#29)
1 parent 64fffb8 commit 548c07c

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed

.dockerignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Rust
6+
target/
7+
8+
# IDE
9+
.vscode/
10+
.idea/
11+
*.swp
12+
*.swo
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db
17+
18+
# Logs
19+
*.log
20+
21+
# Documentation
22+
README.md
23+
docs/
24+
25+
# Docker
26+
Dockerfile
27+
.dockerignore
28+
29+
# CI/CD
30+
.github/
31+
32+
# Tests
33+
tests/
34+
**/*_test.rs
35+
**/*_tests.rs

.github/workflows/ci.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Rust CI
33
on:
44
pull_request:
55
push:
6+
branches: [main]
7+
workflow_dispatch:
68

79
jobs:
810
build-and-test:
@@ -12,3 +14,55 @@ jobs:
1214
working-directory: "."
1315
enable-cache: true
1416
publish-crates-io: false
17+
18+
prepare:
19+
name: Determine Image Tag
20+
runs-on: ubuntu-latest
21+
needs: build-and-test
22+
if: |
23+
github.ref_name == 'main' ||
24+
startsWith(github.head_ref, 'feature/') ||
25+
startsWith(github.head_ref, 'bugfix/') ||
26+
(github.event_name == 'workflow_dispatch' && (startsWith(github.ref_name, 'feature/') || startsWith(github.ref_name, 'bugfix/')))
27+
outputs:
28+
tag: ${{ steps.determine-tag.outputs.tag }}
29+
steps:
30+
- name: Determine Docker tag based on Git ref
31+
id: determine-tag
32+
run: |
33+
if [ "${{ github.event_name }}" = "pull_request" ]; then
34+
SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)
35+
else
36+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
37+
fi
38+
39+
if [[ "${{ github.ref_name }}" == "main" ]]; then
40+
TAG_NAME="dev-${SHORT_SHA}"
41+
echo "Processing main branch push -> ${TAG_NAME}"
42+
else
43+
# This covers feature/ and bugfix/ branches
44+
TAG_NAME="feature-${SHORT_SHA}"
45+
echo "Processing feature/bugfix branch: ${{ github.head_ref }} -> ${TAG_NAME}"
46+
fi
47+
48+
echo "tag=${TAG_NAME}" >> "$GITHUB_OUTPUT"
49+
echo "Determined image tag: ${TAG_NAME}"
50+
51+
build-and-publish:
52+
name: Build and Publish to Registry
53+
needs: prepare
54+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
55+
with:
56+
image-name: docker-regis.iex.ec/tee-worker-pre-compute-rust
57+
image-tag: ${{ needs.prepare.outputs.tag }}
58+
dockerfile: Dockerfile
59+
context: .
60+
registry: docker-regis.iex.ec
61+
push: true
62+
security-scan: true
63+
security-report: "sarif"
64+
hadolint: true
65+
platforms: linux/amd64
66+
secrets:
67+
username: ${{ secrets.NEXUS_USERNAME }}
68+
password: ${{ secrets.NEXUS_PASSWORD }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and Push Release Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
prepare:
10+
name: Determine Image Tag
11+
runs-on: ubuntu-latest
12+
outputs:
13+
tag: ${{ steps.determine-tag.outputs.tag }}
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Determine Docker tag based on Git ref
21+
id: determine-tag
22+
run: |
23+
# Since this workflow only triggers on tags matching 'v*.*.*' we know we're always dealing with a version tag
24+
TAG_ON_MAIN=$(git branch -r --contains ${{ github.sha }} 'origin/main')
25+
26+
if [[ -n "$TAG_ON_MAIN" ]]; then
27+
TAG_NAME="${{ github.ref_name }}"
28+
TAG_NAME="${TAG_NAME#v}" # Remove 'v' prefix
29+
echo "Processing tag on main branch: ${{ github.ref_name }} -> ${TAG_NAME}"
30+
else
31+
echo "Error: Tag ${{ github.ref_name }} is not on main branch"
32+
echo "Tags must be created on main branch to generate X.Y.Z image tags"
33+
exit 1
34+
fi
35+
36+
echo "tag=${TAG_NAME}" >> "$GITHUB_OUTPUT"
37+
echo "Determined image tag: ${TAG_NAME}"
38+
39+
build-and-publish:
40+
name: Build and Publish to Registry On Tag
41+
needs: prepare
42+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
43+
with:
44+
image-name: docker-regis.iex.ec/tee-worker-pre-compute-rust
45+
image-tag: ${{ needs.prepare.outputs.tag }}
46+
dockerfile: Dockerfile
47+
context: .
48+
registry: docker-regis.iex.ec
49+
push: true
50+
security-scan: true
51+
security-report: "sarif"
52+
hadolint: true
53+
platforms: linux/amd64
54+
secrets:
55+
username: ${{ secrets.NEXUS_USERNAME }}
56+
password: ${{ secrets.NEXUS_PASSWORD }}

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM rust:1.88-alpine3.22 AS builder
2+
3+
# Install build dependencies with pinned versions
4+
RUN apk add --no-cache musl-dev=1.2.5-r10 openssl-dev=3.5.2-r0
5+
6+
WORKDIR /app
7+
8+
# Copy manifest and source files
9+
COPY . .
10+
11+
# Build the application
12+
RUN cargo build --release
13+
14+
FROM alpine:3.22
15+
16+
# Install required runtime dependencies with pinned versions
17+
RUN apk add --no-cache libgcc=14.2.0-r6
18+
19+
# Set working directory
20+
WORKDIR /app
21+
22+
# Copy the binary from builder stage
23+
COPY --from=builder /app/target/release/tee-worker-pre-compute .
24+
25+
# Run the application
26+
ENTRYPOINT ["/app/tee-worker-pre-compute"]

0 commit comments

Comments
 (0)