Skip to content

Commit 7c862a1

Browse files
authored
Merge pull request #830 from ahmed-mekky/docker-img
feat: add official docker img with better caching
2 parents a37f72e + 76ee7dd commit 7c862a1

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,50 @@ jobs:
8383
file: target/${{ matrix.target }}/release-ci/${{ matrix.artifact_name }}
8484
asset_name: ${{ matrix.release_name }}
8585
tag: ${{ github.ref }}
86+
87+
docker:
88+
name: Build and Push Docker Image
89+
runs-on: ubuntu-latest
90+
needs: publish
91+
if: startsWith(github.ref, 'refs/tags/v')
92+
permissions:
93+
contents: read
94+
packages: write
95+
steps:
96+
- uses: actions/checkout@v6
97+
98+
- name: Set up QEMU
99+
uses: docker/setup-qemu-action@v3
100+
101+
- name: Set up Docker Buildx
102+
uses: docker/setup-buildx-action@v3
103+
104+
- name: Login to GitHub Container Registry
105+
if: startsWith(github.ref, 'refs/tags/v')
106+
uses: docker/login-action@v3
107+
with:
108+
registry: ghcr.io
109+
username: ${{ github.actor }}
110+
password: ${{ secrets.GITHUB_TOKEN }}
111+
112+
- name: Extract metadata (tags, labels)
113+
id: meta
114+
uses: docker/metadata-action@v5
115+
with:
116+
images: ghcr.io/${{ github.repository }}
117+
tags: |
118+
type=semver,pattern={{version}}
119+
type=semver,pattern={{major}}.{{minor}}
120+
type=semver,pattern={{major}}
121+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
122+
123+
- name: Build and push
124+
uses: docker/build-push-action@v6
125+
with:
126+
context: .
127+
platforms: linux/amd64,linux/arm64
128+
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
129+
tags: ${{ steps.meta.outputs.tags }}
130+
labels: ${{ steps.meta.outputs.labels }}
131+
cache-from: type=gha
132+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
ARG RUST_VERSION=slim
2-
FROM docker.io/library/rust:${RUST_VERSION} AS build
3-
WORKDIR /app
4-
COPY . /app
2+
FROM docker.io/library/rust:${RUST_VERSION} AS chef
53

4+
RUN cargo install cargo-chef --locked
65
RUN apt-get update && apt-get install -y \
76
cmake \
87
&& apt-get clean \
98
&& rm -rf /var/lib/apt/lists/*
109

11-
RUN cargo install --path .
12-
RUN strip /usr/local/cargo/bin/oha
10+
WORKDIR /app
1311

14-
# Target image
15-
FROM registry.fedoraproject.org/fedora-minimal
16-
USER 65535
12+
FROM chef AS planner
13+
COPY . .
14+
RUN cargo chef prepare --recipe-path recipe.json
1715

18-
COPY --chown=65535:65535 --from=build /usr/local/cargo/bin/oha /bin/
16+
FROM chef AS builder
17+
COPY --from=planner /app/recipe.json recipe.json
1918

19+
RUN cargo chef cook --release --no-default-features --features rustls --recipe-path recipe.json
20+
21+
COPY . .
22+
RUN cargo build --release --no-default-features --features rustls --bin oha
23+
RUN strip /app/target/release/oha
24+
25+
FROM registry.fedoraproject.org/fedora-minimal AS runtime
26+
USER 65535
27+
COPY --chown=65535:65535 --from=builder /app/target/release/oha /bin/
2028
ENTRYPOINT ["/bin/oha"]

0 commit comments

Comments
 (0)