Skip to content

Commit ae99e69

Browse files
use custom docker image for building gems
1 parent a2bfe8f commit ae99e69

5 files changed

Lines changed: 71 additions & 25 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ARG BASE_IMAGE
2+
FROM --platform=$BUILDPLATFORM debian:bookworm-slim AS protoc
3+
4+
ARG TARGETARCH
5+
ARG PROTOC_VERSION
6+
7+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl unzip && rm -rf /var/lib/apt/lists/*
8+
9+
RUN case "$TARGETARCH" in \
10+
amd64) protoc_arch='x86_64' ;; \
11+
arm64) protoc_arch='aarch_64' ;; \
12+
*) echo "Unsupported TARGETARCH: $TARGETARCH" >&2; exit 1 ;; \
13+
esac && \
14+
curl -fsSL -o /tmp/protoc.zip "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${protoc_arch}.zip" && \
15+
unzip /tmp/protoc.zip -d /opt/protoc && \
16+
rm /tmp/protoc.zip
17+
18+
FROM ${BASE_IMAGE}
19+
20+
COPY --from=protoc /opt/protoc/bin/protoc /usr/local/bin/protoc
21+
COPY --from=protoc /opt/protoc/include /opt/protoc/include
22+
23+
ENV PROTOC=/usr/local/bin/protoc
24+
ENV PROTOC_INCLUDE=/opt/protoc/include

.github/workflows/build-gems.yml

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,29 @@ jobs:
1818
matrix:
1919
# TODO(cretz): Enable x64-mingw-ucrt if we can figure out Windows issue, see
2020
# https://github.com/temporalio/sdk-ruby/issues/172
21-
rubyPlatform: ["aarch64-linux", "aarch64-linux-musl", "x86_64-linux", "x86_64-linux-musl", "arm64-darwin", "x86_64-darwin"]
21+
include:
22+
- rubyPlatform: aarch64-linux
23+
dockerPlatform: linux/arm64/v8
24+
- rubyPlatform: aarch64-linux-musl
25+
dockerPlatform: linux/arm64/v8
26+
- rubyPlatform: x86_64-linux
27+
dockerPlatform: linux/amd64
28+
- rubyPlatform: x86_64-linux-musl
29+
dockerPlatform: linux/amd64
30+
- rubyPlatform: arm64-darwin
31+
dockerPlatform: linux/arm64/v8
32+
- rubyPlatform: x86_64-darwin
33+
dockerPlatform: linux/amd64
2234
steps:
2335
- name: Checkout repository
2436
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2537
with:
2638
submodules: recursive
2739

40+
- name: Read protoc version
41+
shell: bash
42+
run: echo "PROTOC_VERSION=$(tr -d '\n' < .protoc-version)" >> "$GITHUB_ENV"
43+
2844
- name: Setup Ruby and Rust
2945
uses: oxidize-rb/actions/setup-ruby-and-rust@e5f9a49a7812a078584072f6e3f657ad247c8771 # v1
3046
with:
@@ -35,19 +51,23 @@ jobs:
3551
working-directory: ./temporalio
3652
cache-version: v1-${{ matrix.rubyPlatform }}
3753

38-
- name: Install protoc
39-
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3
40-
with:
41-
version: "34.x"
42-
repo-token: ${{ secrets.GITHUB_TOKEN }}
43-
44-
- name: Export protoc paths
45-
shell: bash
54+
# rb-sys-dock runs the native gem build inside a Docker container and does
55+
# not inherit arbitrary host tools, so we derive a pinned image with the
56+
# exact protoc version baked in for release builds.
57+
- name: Build rb-sys-dock image
58+
id: build-rb-sys-dock-image
59+
working-directory: ./temporalio
4660
run: |
47-
protoc_bin="$(command -v protoc)"
48-
protoc_root="$(cd "$(dirname "$protoc_bin")/.." && pwd)"
49-
echo "PROTOC=$protoc_bin" >> "$GITHUB_ENV"
50-
echo "PROTOC_INCLUDE=$protoc_root/include" >> "$GITHUB_ENV"
61+
rb_sys_version="$(ruby -e 'require \"rb_sys/version\"; puts RbSys::VERSION')"
62+
custom_image="temporalio-rbsys/${{ matrix.rubyPlatform }}:${rb_sys_version}-protoc-${PROTOC_VERSION}"
63+
docker build \
64+
--platform "${{ matrix.dockerPlatform }}" \
65+
--build-arg BASE_IMAGE="rbsys/${{ matrix.rubyPlatform }}:${rb_sys_version}" \
66+
--build-arg PROTOC_VERSION="${PROTOC_VERSION}" \
67+
-t "$custom_image" \
68+
-f ../.github/docker/rb-sys-protoc.Dockerfile \
69+
..
70+
echo "image=$custom_image" >> $GITHUB_OUTPUT
5171
5272
# Cannot use oxidize-rb/actions/cross-gem because it has older Rust and we
5373
# need --mount-toolchains to get latest Rust, see
@@ -57,7 +77,7 @@ jobs:
5777
working-directory: ./temporalio
5878
run: |
5979
gem install rb_sys --no-document
60-
rb-sys-dock --platform ${{ matrix.rubyPlatform }} --ruby-versions "3.3,3.4,4.0" --mount-toolchains --build
80+
RCD_IMAGE="${{ steps.build-rb-sys-dock-image.outputs.image }}" rb-sys-dock --platform ${{ matrix.rubyPlatform }} --ruby-versions "3.3,3.4,4.0" --mount-toolchains --build
6181
echo "gem-path=$(find pkg -name '*-${{ matrix.rubyPlatform }}.gem')" >> $GITHUB_OUTPUT
6282
6383
- name: Upload gem
@@ -75,6 +95,10 @@ jobs:
7595
with:
7696
submodules: recursive
7797

98+
- name: Read protoc version
99+
shell: bash
100+
run: echo "PROTOC_VERSION=$(tr -d '\n' < .protoc-version)" >> "$GITHUB_ENV"
101+
78102
- name: Setup Ruby and Rust
79103
uses: oxidize-rb/actions/setup-ruby-and-rust@e5f9a49a7812a078584072f6e3f657ad247c8771 # v1
80104
with:
@@ -86,17 +110,9 @@ jobs:
86110
- name: Install protoc
87111
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3
88112
with:
89-
version: "34.x"
113+
version: ${{ env.PROTOC_VERSION }}
90114
repo-token: ${{ secrets.GITHUB_TOKEN }}
91115

92-
- name: Export protoc paths
93-
shell: bash
94-
run: |
95-
protoc_bin="$(command -v protoc)"
96-
protoc_root="$(cd "$(dirname "$protoc_bin")/.." && pwd)"
97-
echo "PROTOC=$protoc_bin" >> "$GITHUB_ENV"
98-
echo "PROTOC_INCLUDE=$protoc_root/include" >> "$GITHUB_ENV"
99-
100116
- name: Fix gem directory permissions
101117
run: chmod -R o-w "$RUNNER_TOOL_CACHE/Ruby" || true
102118

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
with:
3636
submodules: recursive
3737

38+
- name: Read protoc version
39+
shell: bash
40+
run: echo "PROTOC_VERSION=$(tr -d '\n' < .protoc-version)" >> "$GITHUB_ENV"
41+
3842
# This is a temporary fix until Ruby 3.4.8 comes out.
3943
#
4044
# Per https://github.com/ruby/openssl/issues/949 (by way of
@@ -62,7 +66,7 @@ jobs:
6266
- name: Install protoc
6367
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3
6468
with:
65-
version: "34.x"
69+
version: ${{ env.PROTOC_VERSION }}
6670
repo-token: ${{ secrets.GITHUB_TOKEN }}
6771

6872
- name: Install bundle

.protoc-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34.0

temporalio/extra/proto_gen.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
# Generator for the proto files.
88
class ProtoGen
9-
MINIMUM_PROTOC_VERSION = Gem::Version.new('34.0')
9+
PROTOC_VERSION_FILE = File.expand_path('../../.protoc-version', __dir__)
10+
MINIMUM_PROTOC_VERSION = Gem::Version.new(File.read(PROTOC_VERSION_FILE).strip)
1011
SERVICE_DEFINITIONS = [
1112
{
1213
require_path: './lib/temporalio/api/workflowservice/v1/service',

0 commit comments

Comments
 (0)