Skip to content

Commit a72d162

Browse files
committed
Initial commit: term-executor service
- Basilica client for instance verification and task execution - Execution engine with queue management - Container lifecycle and cleanup system - HTTP API for validators with Sr25519 authentication - PostgreSQL storage for persistence - Prometheus metrics - Docker images for service and controlled agent environment - CI/CD workflows with Blacksmith runners
0 parents  commit a72d162

37 files changed

+5389
-0
lines changed

.github/workflows/ci.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUSTFLAGS: "-Dwarnings"
12+
13+
jobs:
14+
check:
15+
name: Check
16+
runs-on: blacksmith-4vcpu-ubuntu-2204
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Install Rust toolchain
22+
uses: actions-rust-lang/setup-rust-toolchain@v1
23+
with:
24+
toolchain: stable
25+
components: rustfmt, clippy
26+
27+
- name: Cache cargo
28+
uses: useblacksmith/cache@v5
29+
with:
30+
path: |
31+
~/.cargo/bin/
32+
~/.cargo/registry/index/
33+
~/.cargo/registry/cache/
34+
~/.cargo/git/db/
35+
target/
36+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
37+
restore-keys: |
38+
${{ runner.os }}-cargo-
39+
40+
- name: Check formatting
41+
run: cargo fmt --all -- --check
42+
43+
- name: Clippy
44+
run: cargo clippy --all-targets --all-features -- -D warnings
45+
46+
- name: Check
47+
run: cargo check --all-targets --all-features
48+
49+
test:
50+
name: Test
51+
runs-on: blacksmith-4vcpu-ubuntu-2204
52+
needs: check
53+
services:
54+
postgres:
55+
image: postgres:16-alpine
56+
env:
57+
POSTGRES_USER: postgres
58+
POSTGRES_PASSWORD: postgres
59+
POSTGRES_DB: term_executor_test
60+
ports:
61+
- 5432:5432
62+
options: >-
63+
--health-cmd pg_isready
64+
--health-interval 10s
65+
--health-timeout 5s
66+
--health-retries 5
67+
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v4
71+
72+
- name: Install Rust toolchain
73+
uses: actions-rust-lang/setup-rust-toolchain@v1
74+
with:
75+
toolchain: stable
76+
77+
- name: Cache cargo
78+
uses: useblacksmith/cache@v5
79+
with:
80+
path: |
81+
~/.cargo/bin/
82+
~/.cargo/registry/index/
83+
~/.cargo/registry/cache/
84+
~/.cargo/git/db/
85+
target/
86+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
87+
restore-keys: |
88+
${{ runner.os }}-cargo-test-
89+
${{ runner.os }}-cargo-
90+
91+
- name: Run tests
92+
run: cargo test --all-features
93+
env:
94+
DATABASE_URL: postgres://postgres:postgres@localhost:5432/term_executor_test
95+
96+
build:
97+
name: Build
98+
runs-on: blacksmith-4vcpu-ubuntu-2204
99+
needs: check
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@v4
103+
104+
- name: Install Rust toolchain
105+
uses: actions-rust-lang/setup-rust-toolchain@v1
106+
with:
107+
toolchain: stable
108+
109+
- name: Cache cargo
110+
uses: useblacksmith/cache@v5
111+
with:
112+
path: |
113+
~/.cargo/bin/
114+
~/.cargo/registry/index/
115+
~/.cargo/registry/cache/
116+
~/.cargo/git/db/
117+
target/
118+
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
119+
restore-keys: |
120+
${{ runner.os }}-cargo-build-
121+
${{ runner.os }}-cargo-
122+
123+
- name: Build release
124+
run: cargo build --release
125+
126+
- name: Upload binary
127+
uses: actions/upload-artifact@v4
128+
with:
129+
name: term-executor-linux-amd64
130+
path: target/release/term-executor
131+
retention-days: 7
132+
133+
security:
134+
name: Security Audit
135+
runs-on: blacksmith-2vcpu-ubuntu-2204
136+
steps:
137+
- name: Checkout
138+
uses: actions/checkout@v4
139+
140+
- name: Install Rust toolchain
141+
uses: actions-rust-lang/setup-rust-toolchain@v1
142+
with:
143+
toolchain: stable
144+
145+
- name: Install cargo-audit
146+
run: cargo install cargo-audit --locked || true
147+
148+
- name: Run security audit
149+
run: cargo audit || true
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Docker Publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'docker/**'
8+
- 'src/**'
9+
- 'Cargo.toml'
10+
- 'Cargo.lock'
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
15+
jobs:
16+
build-and-push:
17+
name: Build and Push Docker Images
18+
runs-on: blacksmith-4vcpu-ubuntu-2204
19+
permissions:
20+
contents: read
21+
packages: write
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Log in to Container Registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Build and push term-executor (dev)
38+
uses: docker/build-push-action@v5
39+
with:
40+
context: .
41+
file: docker/Dockerfile
42+
push: true
43+
tags: |
44+
${{ env.REGISTRY }}/platformnetwork/term-executor:dev
45+
${{ env.REGISTRY }}/platformnetwork/term-executor:${{ github.sha }}
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max
48+
49+
- name: Build and push term-agent (dev)
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
file: docker/Dockerfile.agent
54+
push: true
55+
tags: |
56+
${{ env.REGISTRY }}/platformnetwork/term-agent:dev
57+
${{ env.REGISTRY }}/platformnetwork/term-agent:${{ github.sha }}
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max

.github/workflows/release.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-binaries:
15+
name: Build Binaries
16+
runs-on: blacksmith-4vcpu-ubuntu-2204
17+
strategy:
18+
matrix:
19+
include:
20+
- target: x86_64-unknown-linux-gnu
21+
os: ubuntu
22+
ext: ""
23+
- target: x86_64-unknown-linux-musl
24+
os: ubuntu
25+
ext: "-musl"
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Install Rust toolchain
32+
uses: actions-rust-lang/setup-rust-toolchain@v1
33+
with:
34+
toolchain: stable
35+
target: ${{ matrix.target }}
36+
37+
- name: Install musl-tools
38+
if: contains(matrix.target, 'musl')
39+
run: sudo apt-get update && sudo apt-get install -y musl-tools
40+
41+
- name: Cache cargo
42+
uses: useblacksmith/cache@v5
43+
with:
44+
path: |
45+
~/.cargo/bin/
46+
~/.cargo/registry/index/
47+
~/.cargo/registry/cache/
48+
~/.cargo/git/db/
49+
target/
50+
key: ${{ runner.os }}-${{ matrix.target }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
51+
52+
- name: Build release
53+
run: cargo build --release --target ${{ matrix.target }}
54+
55+
- name: Package binary
56+
run: |
57+
mkdir -p dist
58+
cp target/${{ matrix.target }}/release/term-executor dist/term-executor-linux-amd64${{ matrix.ext }}
59+
cp config/default.toml dist/
60+
cp README.md dist/
61+
cd dist && tar -czvf term-executor-linux-amd64${{ matrix.ext }}.tar.gz *
62+
63+
- name: Upload artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: term-executor-linux-amd64${{ matrix.ext }}
67+
path: dist/term-executor-linux-amd64${{ matrix.ext }}.tar.gz
68+
69+
build-docker:
70+
name: Build Docker Images
71+
runs-on: blacksmith-4vcpu-ubuntu-2204
72+
permissions:
73+
contents: read
74+
packages: write
75+
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v4
79+
80+
- name: Set up Docker Buildx
81+
uses: docker/setup-buildx-action@v3
82+
83+
- name: Log in to Container Registry
84+
uses: docker/login-action@v3
85+
with:
86+
registry: ${{ env.REGISTRY }}
87+
username: ${{ github.actor }}
88+
password: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- name: Extract metadata for term-executor
91+
id: meta-executor
92+
uses: docker/metadata-action@v5
93+
with:
94+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
95+
tags: |
96+
type=semver,pattern={{version}}
97+
type=semver,pattern={{major}}.{{minor}}
98+
type=semver,pattern={{major}}
99+
type=sha,prefix=
100+
type=raw,value=latest,enable=${{ github.ref == format('refs/tags/{0}', github.event.release.tag_name) }}
101+
102+
- name: Build and push term-executor
103+
uses: docker/build-push-action@v5
104+
with:
105+
context: .
106+
file: docker/Dockerfile
107+
push: true
108+
tags: ${{ steps.meta-executor.outputs.tags }}
109+
labels: ${{ steps.meta-executor.outputs.labels }}
110+
cache-from: type=gha
111+
cache-to: type=gha,mode=max
112+
113+
- name: Extract metadata for term-agent
114+
id: meta-agent
115+
uses: docker/metadata-action@v5
116+
with:
117+
images: ${{ env.REGISTRY }}/platformnetwork/term-agent
118+
tags: |
119+
type=semver,pattern={{version}}
120+
type=semver,pattern={{major}}.{{minor}}
121+
type=raw,value=latest,enable=${{ github.ref == format('refs/tags/{0}', github.event.release.tag_name) }}
122+
123+
- name: Build and push term-agent
124+
uses: docker/build-push-action@v5
125+
with:
126+
context: .
127+
file: docker/Dockerfile.agent
128+
push: true
129+
tags: ${{ steps.meta-agent.outputs.tags }}
130+
labels: ${{ steps.meta-agent.outputs.labels }}
131+
cache-from: type=gha
132+
cache-to: type=gha,mode=max
133+
134+
create-release:
135+
name: Create Release
136+
runs-on: blacksmith-2vcpu-ubuntu-2204
137+
needs: [build-binaries, build-docker]
138+
permissions:
139+
contents: write
140+
141+
steps:
142+
- name: Checkout
143+
uses: actions/checkout@v4
144+
145+
- name: Download artifacts
146+
uses: actions/download-artifact@v4
147+
with:
148+
path: artifacts
149+
150+
- name: Create Release
151+
uses: softprops/action-gh-release@v1
152+
with:
153+
files: |
154+
artifacts/**/*.tar.gz
155+
generate_release_notes: true
156+
draft: false
157+
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)