Skip to content

Commit 0f89f96

Browse files
author
Christopher Skene
committed
Unify workflows and docker stuff
1 parent ccce327 commit 0f89f96

5 files changed

Lines changed: 133 additions & 93 deletions

File tree

.github/workflows/build.yml

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
# .github/workflows/release.yml
12
name: Release Harmony
23

34
on:
45
push:
56
tags:
6-
- 'v*' # production releases
7+
- 'v*'
78
workflow_dispatch:
89

910
env:
1011
CARGO_TERM_COLOR: always
11-
REGISTRY: ghcr.io
12-
IMAGE_NAME: ${{ github.repository }}
12+
REGISTRY_GHCR: ghcr.io/aurabx/harmony
13+
REGISTRY_DOCKERHUB: aurabx/harmony
14+
IMAGE_NAME: harmony
1315

1416
jobs:
17+
# ---------- 1. Build binaries ----------
1518
build-binaries:
16-
name: Build Rust binaries (cross/native)
19+
name: Build Harmony binaries (cross/native)
1720
strategy:
1821
matrix:
1922
include:
@@ -38,22 +41,18 @@ jobs:
3841
with:
3942
targets: ${{ matrix.target }}
4043

41-
# Linux builds (use cross)
44+
# Linux builds use cross
4245
- name: Build Harmony (Linux cross)
4346
if: runner.os == 'Linux'
4447
shell: bash
4548
run: |
46-
echo "Detected Linux runner. Installing musl dependencies and using cross."
4749
cargo install cross --git https://github.com/cross-rs/cross
48-
# Build for the target
4950
cross build --release --target ${{ matrix.target }}
5051
51-
# Non-Linux builds (macOS + Windows)
52+
# Non-Linux builds are native
5253
- name: Build Harmony (native)
5354
if: runner.os != 'Linux'
54-
run: |
55-
echo "Detected non-Linux runner. Building natively."
56-
cargo build --release --target ${{ matrix.target }}
55+
run: cargo build --release --target ${{ matrix.target }}
5756

5857
- name: Package artefacts
5958
shell: bash
@@ -82,8 +81,9 @@ jobs:
8281
name: harmony-${{ matrix.target }}
8382
path: release/
8483

84+
# ---------- 2. Build and push Docker images ----------
8585
docker:
86-
name: Build and push multi-arch Docker image
86+
name: Build and push multi-arch Docker images
8787
runs-on: ubuntu-latest
8888
needs: build-binaries
8989
permissions:
@@ -92,61 +92,77 @@ jobs:
9292
id-token: write
9393

9494
steps:
95-
- name: Checkout
96-
uses: actions/checkout@v4
95+
- uses: actions/checkout@v4
96+
- uses: actions/download-artifact@v4
97+
with:
98+
path: ./binaries
9799

98-
- name: Set up Buildx
99-
uses: docker/setup-buildx-action@v3
100+
- name: Prepare Linux binaries
101+
run: |
102+
mv binaries/harmony-x86_64-unknown-linux-musl/harmony harmony-amd64 || true
103+
mv binaries/harmony-aarch64-unknown-linux-musl/harmony harmony-arm64 || true
104+
105+
- uses: docker/setup-buildx-action@v3
106+
107+
- name: Log in to Docker Hub
108+
uses: docker/login-action@v3
109+
with:
110+
username: ${{ secrets.DOCKERHUB_USERNAME }}
111+
password: ${{ secrets.DOCKERHUB_TOKEN }}
100112

101-
- name: Login to GHCR
113+
- name: Log in to GHCR
102114
uses: docker/login-action@v3
103115
with:
104-
registry: ${{ env.REGISTRY }}
116+
registry: ghcr.io
105117
username: ${{ github.actor }}
106118
password: ${{ secrets.GITHUB_TOKEN }}
107119

108120
- name: Compute image tags
109121
id: meta
110-
shell: bash
111122
run: |
112-
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
113-
echo "Detected release tag ${GITHUB_REF_NAME}"
114-
echo "tags=${REGISTRY}/${IMAGE_NAME}:${GITHUB_REF_NAME},${REGISTRY}/${IMAGE_NAME}:latest" >> $GITHUB_OUTPUT
115-
else
116-
SHORT_SHA="${GITHUB_SHA::7}"
117-
SAFE_BRANCH="${GITHUB_REF_NAME//\//-}"
118-
echo "tags=${REGISTRY}/${IMAGE_NAME}:${SAFE_BRANCH}-${SHORT_SHA}" >> $GITHUB_OUTPUT
119-
fi
120-
env:
121-
REGISTRY: ${{ env.REGISTRY }}
122-
IMAGE_NAME: ${{ env.IMAGE_NAME }}
123+
TAG=${GITHUB_REF_NAME}
124+
echo "tags=${{ env.REGISTRY_DOCKERHUB }}:${TAG},${{ env.REGISTRY_DOCKERHUB }}:latest,${{ env.REGISTRY_GHCR }}:${TAG},${{ env.REGISTRY_GHCR }}:latest" >> $GITHUB_OUTPUT
123125
124126
- name: Build and push
125127
uses: docker/build-push-action@v6
126128
with:
127129
context: .
130+
file: Dockerfile
128131
push: true
129132
platforms: linux/amd64,linux/arm64
130133
tags: ${{ steps.meta.outputs.tags }}
131134
cache-from: type=gha
132135
cache-to: type=gha,mode=max
133136

137+
# ---------- 3. Publish GitHub Release ----------
134138
release:
135139
name: Publish GitHub Release
136140
runs-on: ubuntu-latest
137141
needs: [build-binaries, docker]
138142
if: startsWith(github.ref, 'refs/tags/v')
143+
permissions:
144+
contents: write
145+
139146
steps:
140147
- name: Download artefacts
141148
uses: actions/download-artifact@v4
142149
with:
143150
path: ./artifacts
144151

152+
# Combine all SHA256 files into one manifest
153+
- name: Generate combined checksums manifest
154+
shell: bash
155+
run: |
156+
cd artifacts
157+
find . -type f -name "*.sha256" -exec cat {} \; > checksums.txt
158+
echo "Combined checksums:"
159+
cat checksums.txt
160+
145161
- name: Create GitHub Release
146162
uses: softprops/action-gh-release@v2
147163
with:
148164
tag_name: ${{ github.ref_name }}
149165
name: Harmony ${{ github.ref_name }}
150166
files: ./artifacts/**/*
151167
env:
152-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

Dockerfile

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
1-
# Build stage
2-
FROM rust:1.87-bookworm AS builder
3-
4-
WORKDIR /app
5-
6-
# Copy Cargo files first for better layer caching
7-
COPY Cargo.toml Cargo.lock ./
8-
COPY crates/ ./crates/
9-
10-
# Copy source code
11-
COPY src/ ./src/
12-
13-
# Build release binary
14-
RUN cargo build --release --bin harmony
15-
16-
# Runtime stage
1+
# syntax=docker/dockerfile:1
172
FROM debian:bookworm-slim
183

19-
# Install minimal dependencies
20-
RUN apt-get update && \
21-
apt-get install -y ca-certificates && \
22-
rm -rf /var/lib/apt/lists/*
23-
24-
# Create directories
4+
WORKDIR /app
5+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
256
RUN mkdir -p /etc/harmony /var/log/harmony /tmp/harmony
267

27-
# Copy binary from builder
28-
COPY --from=builder /app/target/release/harmony /usr/local/bin/harmony
8+
# Copy in prebuilt binary (for CI or local use)
9+
ARG TARGETARCH
10+
COPY harmony-${TARGETARCH} /usr/local/bin/harmony
2911

30-
# Expose ports
3112
EXPOSE 8080 9090
32-
33-
# Default command
34-
CMD ["harmony", "--config", "/etc/harmony/config.toml"]
13+
CMD ["harmony", "--config", "/etc/harmony/config.toml"]

Dockerfile.build

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Build stage
2+
FROM rust:1.87-bookworm AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy Cargo files first for better layer caching
7+
COPY Cargo.toml Cargo.lock ./
8+
COPY crates/ ./crates/
9+
10+
# Copy source code
11+
COPY src/ ./src/
12+
13+
# Build release binary
14+
RUN cargo build --release --bin harmony
15+
16+
# Runtime stage
17+
FROM debian:bookworm-slim
18+
19+
# Install minimal dependencies
20+
RUN apt-get update && \
21+
apt-get install -y ca-certificates && \
22+
rm -rf /var/lib/apt/lists/*
23+
24+
# Create directories
25+
RUN mkdir -p /etc/harmony /var/log/harmony /tmp/harmony
26+
27+
# Copy binary from builder
28+
COPY --from=builder /app/target/release/harmony /usr/local/bin/harmony
29+
30+
# Expose ports
31+
EXPOSE 8080 9090
32+
33+
# Default command
34+
CMD ["harmony", "--config", "/etc/harmony/config.toml"]

readme.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,36 @@ If configured, you should receive an echoed response from the sample backend. Ex
5757

5858
### Docker
5959

60-
Run with Docker Compose:
60+
#### Option 1 – Run with Docker Compose (recommended)
61+
62+
For local development or quick testing:
6163

6264
```bash
63-
# Build and run
64-
docker-compose up
65+
# Build and start containers
66+
docker compose up
6567

66-
# Alternatively, to force a rebuild
68+
# Alternatively, to rebuild and restart cleanly
6769
docker compose up --build --force-recreate -d
6870

6971
# Test the service
7072
curl -i http://localhost:8080/echo
7173
```
7274

73-
Or build and run manually:
75+
Compose uses the included `Dockerfile.build` so everything builds from source inside Docker—no Rust toolchain required on the host.
76+
77+
**Ports**
78+
79+
* **8080** – Main service endpoints
80+
* **9090** – Management API (if enabled)
81+
82+
---
83+
84+
#### Option 2 – Build and run manually (from prebuilt or local binaries)
85+
86+
If you have prebuilt binaries or are running from CI output, use the lean runtime image (`Dockerfile`):
7487

7588
```bash
76-
# Build image
89+
# Build image from prebuilt binaries (fast path)
7790
docker build -t harmony-proxy .
7891

7992
# Run with default config
@@ -87,9 +100,32 @@ docker run -p 8080:8080 \
87100
harmony-proxy --config /examples/basic-echo/config.toml
88101
```
89102

90-
Ports:
91-
- 8080: Main service endpoints
92-
- 9090: Management API (if enabled)
103+
If you’d rather build everything from scratch (no prebuilt binaries), specify the full build image explicitly:
104+
105+
```bash
106+
docker build -f Dockerfile.build -t harmony-proxy .
107+
docker run -p 8080:8080 harmony-proxy
108+
```
109+
110+
---
111+
112+
#### Option 3 – Use the published image
113+
114+
Once your CI workflow pushes to GHCR:
115+
116+
```bash
117+
docker pull ghcr.io/aurabx/harmony:latest
118+
docker run -p 8080:8080 -p 9090:9090 ghcr.io/aurabx/harmony:latest
119+
```
120+
121+
---
122+
123+
This layout clarifies:
124+
125+
* **Compose / Dockerfile.build** → full source build (developer-friendly)
126+
* **Dockerfile** → prebuilt-binary runtime (used by CI and GHCR images)
127+
* **Published image** → fastest start for end-users
128+
93129

94130
## Configuration
95131
Harmony's configuration is file-based (TOML) and can include additional pipeline/transform files from a directory.

0 commit comments

Comments
 (0)