Skip to content

Commit 2024422

Browse files
Merge pull request #44 from joshrotenberg/fix/docker-multi-arch
fix: Docker multi-arch build using pre-built binaries
2 parents ceca2b6 + 4c9e7dd commit 2024422

File tree

4 files changed

+86
-71
lines changed

4 files changed

+86
-71
lines changed

.github/workflows/docker-publish.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Docker Publish
22

33
on:
44
push:
5-
tags:
6-
- 'redisctl-v*'
75
branches:
86
- main
7+
release:
8+
types: [published]
99
workflow_dispatch:
1010

1111
env:
@@ -46,19 +46,34 @@ jobs:
4646
type=sha,prefix=sha-
4747
type=raw,value=latest,enable={{is_default_branch}}
4848
49+
- name: Set build parameters
50+
id: build-params
51+
run: |
52+
if [[ "${{ github.event_name }}" == "release" ]]; then
53+
VERSION="${{ github.event.release.tag_name }}"
54+
VERSION="${VERSION#redisctl-v}"
55+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
56+
echo "DOCKERFILE=./Dockerfile" >> $GITHUB_OUTPUT
57+
echo "PLATFORMS=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
58+
else
59+
echo "VERSION=dev" >> $GITHUB_OUTPUT
60+
echo "DOCKERFILE=./Dockerfile.dev" >> $GITHUB_OUTPUT
61+
echo "PLATFORMS=linux/amd64" >> $GITHUB_OUTPUT
62+
fi
63+
4964
- name: Build and push Docker image
5065
uses: docker/build-push-action@v5
5166
with:
5267
context: .
53-
file: ./Dockerfile.publish
54-
platforms: linux/amd64,linux/arm64
68+
file: ${{ steps.build-params.outputs.DOCKERFILE }}
69+
platforms: ${{ steps.build-params.outputs.PLATFORMS }}
5570
push: true
5671
tags: ${{ steps.meta.outputs.tags }}
5772
labels: ${{ steps.meta.outputs.labels }}
5873
cache-from: type=gha
5974
cache-to: type=gha,mode=max
6075
build-args: |
61-
RUST_VERSION=1.89
76+
VERSION=${{ steps.build-params.outputs.VERSION }}
6277
6378
- name: Update Docker Hub Description
6479
uses: peter-evans/dockerhub-description@v4

Dockerfile

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
# Redis CLI Docker Image
2-
# Multi-stage build for optimal size
2+
# Uses pre-built binaries from GitHub releases for faster multi-arch builds
33

4-
FROM rust:1.89 AS builder
5-
6-
WORKDIR /build
7-
8-
# Copy workspace files
9-
COPY Cargo.toml ./
10-
COPY crates/ ./crates/
11-
12-
# Build release binary
13-
RUN cargo build --release --bin redisctl
14-
15-
# Runtime stage - Ubuntu for newer GLIBC
164
FROM ubuntu:24.04
175

186
# Install runtime dependencies
197
RUN apt-get update && apt-get install -y \
208
ca-certificates \
219
curl \
10+
xz-utils \
2211
&& rm -rf /var/lib/apt/lists/*
2312

24-
# Copy binary from builder
25-
COPY --from=builder /build/target/release/redisctl /usr/local/bin/redisctl
13+
# Set the version to install
14+
ARG VERSION=0.2.0
15+
ARG TARGETPLATFORM
16+
17+
# Download the appropriate binary based on platform
18+
RUN case "$TARGETPLATFORM" in \
19+
"linux/amd64") \
20+
ARCH="x86_64-unknown-linux-gnu" \
21+
;; \
22+
"linux/arm64") \
23+
ARCH="aarch64-unknown-linux-gnu" \
24+
;; \
25+
*) \
26+
echo "Unsupported platform: $TARGETPLATFORM" && exit 1 \
27+
;; \
28+
esac && \
29+
curl -L "https://github.com/joshrotenberg/redisctl/releases/download/redisctl-v${VERSION}/redisctl-${ARCH}.tar.xz" | \
30+
tar -xJ --strip-components=1 -C /tmp && \
31+
mv /tmp/redisctl /usr/local/bin/redisctl && \
32+
chmod +x /usr/local/bin/redisctl && \
33+
rm -rf /tmp/*
2634

2735
# Create non-root user
2836
RUN useradd -m redis && \
@@ -37,7 +45,7 @@ ENV REDIS_ENTERPRISE_URL=""
3745
ENV REDIS_ENTERPRISE_USER=""
3846
ENV REDIS_ENTERPRISE_PASSWORD=""
3947
ENV REDIS_CLOUD_API_KEY=""
40-
ENV REDIS_CLOUD_SECRET_KEY=""
48+
ENV REDIS_CLOUD_API_SECRET=""
4149

4250
ENTRYPOINT ["redisctl"]
4351
CMD ["--help"]

Dockerfile.dev

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Development Docker Image
2+
# Builds from source for main branch pushes
3+
4+
FROM rust:1.89 AS builder
5+
6+
WORKDIR /build
7+
8+
# Copy workspace files
9+
COPY Cargo.toml ./
10+
COPY crates/ ./crates/
11+
12+
# Build release binary
13+
RUN cargo build --release --bin redisctl
14+
15+
# Runtime stage - Ubuntu for newer GLIBC
16+
FROM ubuntu:24.04
17+
18+
# Install runtime dependencies
19+
RUN apt-get update && apt-get install -y \
20+
ca-certificates \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Copy binary from builder
24+
COPY --from=builder /build/target/release/redisctl /usr/local/bin/redisctl
25+
26+
# Create non-root user
27+
RUN useradd -m redis && \
28+
mkdir -p /home/redis/.config/redisctl && \
29+
chown -R redis:redis /home/redis
30+
31+
USER redis
32+
WORKDIR /home/redis
33+
34+
# Default environment variables
35+
ENV REDIS_ENTERPRISE_URL=""
36+
ENV REDIS_ENTERPRISE_USER=""
37+
ENV REDIS_ENTERPRISE_PASSWORD=""
38+
ENV REDIS_CLOUD_API_KEY=""
39+
ENV REDIS_CLOUD_API_SECRET=""
40+
41+
ENTRYPOINT ["redisctl"]
42+
CMD ["--help"]

Dockerfile.publish

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

0 commit comments

Comments
 (0)