Skip to content

Commit 1cf53d5

Browse files
authored
Merge pull request #163 from rake-compiler/RCD_IMAGE_VERSION
Add RCD_IMAGE_VERSION env var to easily set image version
2 parents 92301f8 + d7f627d commit 1cf53d5

File tree

5 files changed

+22
-56
lines changed

5 files changed

+22
-56
lines changed

.github/workflows/publish-images.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,10 @@ jobs:
107107
registry: ghcr.io
108108
username: ${{github.actor}}
109109
password: ${{secrets.GITHUB_TOKEN}}
110-
- name: Generate docker image names
111-
id: rcd_config
112-
run: |
113-
bundle exec ruby -e ' \
114-
require "rake_compiler_dock"; \
115-
print "snapshot_name_opt=-t "; \
116-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)); \
117-
if %q(${{matrix.platform}}).end_with?("-gnu"); \
118-
print "generic_linux_snapshot_name_opt=-t "; \
119-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)).chomp("-gnu"); \
120-
end \
121-
' | tee -a $GITHUB_OUTPUT
122110
- name: Use cache and push docker image
123111
env:
124-
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache-X64 --cache-from=type=local,src=tmp/build-cache-ARM64 --cache-to=type=local,dest=tmp/build-cache-new ${{steps.rcd_config.outputs.snapshot_name_opt}} ${{steps.rcd_config.outputs.generic_linux_snapshot_name_opt}}
112+
RCD_IMAGE_VERSION: snapshot
113+
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache-X64 --cache-from=type=local,src=tmp/build-cache-ARM64 --cache-to=type=local,dest=tmp/build-cache-new
125114
run: |
126115
docker buildx create --driver docker-container --use
127116
bundle exec rake release:${{matrix.platform}}

.github/workflows/release-images.yml

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -110,51 +110,14 @@ jobs:
110110
with:
111111
ruby-version: "3.3"
112112
bundler-cache: true
113-
- name: Generate docker image names
114-
id: rcd_config
115-
run: |
116-
bundle exec ruby -e ' \
117-
require "rake_compiler_dock"; \
118-
print "image_name_opt=-t "; \
119-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})); \
120-
print "snapshot_name_opt=-t "; \
121-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)); \
122-
if %q(${{matrix.platform}}).end_with?("-gnu"); \
123-
print "generic_linux_snapshot_name_opt=-t "; \
124-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)).chomp("-gnu"); \
125-
end \
126-
' | tee -a $GITHUB_OUTPUT
127-
128-
129-
bundle exec ruby -e ' \
130-
require "rake_compiler_dock"; \
131-
print "image_name="; \
132-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})); \
133-
if %q(${{matrix.platform}}).end_with?("-gnu"); \
134-
print "generic_linux_image_name="; \
135-
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})).chomp("-gnu"); \
136-
end \
137-
' | tee -a $GITHUB_OUTPUT
138-
- name: Build docker image
139-
env:
140-
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new
141-
run: |
142-
docker buildx create --driver docker-container --use
143-
bundle exec rake build:x86:${{matrix.platform}}
144-
# move build cache and remove outdated layers
145-
rm -rf tmp/build-cache
146-
mv tmp/build-cache-new tmp/build-cache
147113
- uses: docker/login-action@v3
148114
with:
149115
registry: ghcr.io
150116
username: ${{github.actor}}
151117
password: ${{secrets.GITHUB_TOKEN}}
152-
- name: Push the docker image
153-
run: |
154-
docker images
155-
docker push ${{steps.rcd_config.outputs.image_name}}
156-
- name: Push a generic linux image
157-
if: ${{ steps.rcd_config.outputs.generic_linux_image_name }}
118+
- name: Use cache and push docker image
119+
env:
120+
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache-X64 --cache-from=type=local,src=tmp/build-cache-ARM64 --cache-to=type=local,dest=tmp/build-cache-new
158121
run: |
159-
docker tag ${{steps.rcd_config.outputs.image_name}} ${{steps.rcd_config.outputs.generic_linux_image_name}}
160-
docker push ${{steps.rcd_config.outputs.generic_linux_image_name}}
122+
docker buildx create --driver docker-container --use
123+
bundle exec rake release:${{matrix.platform}}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ OCI images snapshotted from `main` are published weekly to Github Container Regi
315315
- `ghcr.io/rake-compiler/rake-compiler-dock-image:snapshot-mri-x86_64-linux-gnu`
316316

317317
These images are intended for integration testing. They may not work properly and should not be considered production ready.
318+
Snapshot images can be used by setting `RCD_IMAGE_VERSION` environment variable.
318319

319320

320321
## Environment Variables
@@ -330,6 +331,9 @@ The following variables are recognized by rake-compiler-dock:
330331
It is ignored when `rubyvm` is set to `:jruby`.
331332
* `RCD_IMAGE` - The docker image that is downloaded and started.
332333
Defaults to "ghcr.io/rake-compiler/rake-compiler-dock-image:IMAGE_VERSION-PLATFORM" with an image version that is determined by the gem version.
334+
* `RCD_IMAGE_VERSION` - The docker image version that is downloaded and started.
335+
Defaults to the version of the rake-compiler-dock gem in use.
336+
Can be set to `snapshot` in order to use the latest images from main branch.
333337

334338
The following variables are passed through to the docker container without modification:
335339

lib/rake_compiler_dock/starter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def container_image_name(options={})
167167

168168
"%s/rake-compiler-dock-image:%s-%s%s" % [
169169
container_registry,
170-
options.fetch(:version) { IMAGE_VERSION },
170+
options.fetch(:version) { image_version },
171171
container_rubyvm(options),
172172
container_jrubyvm?(options) ? "" : "-#{options.fetch(:platform)}",
173173
]
@@ -178,6 +178,10 @@ def container_registry
178178
ENV['CONTAINER_REGISTRY'] || "ghcr.io/rake-compiler"
179179
end
180180

181+
def image_version
182+
ENV['RCD_IMAGE_VERSION'] || IMAGE_VERSION
183+
end
184+
181185
def container_rubyvm(options={})
182186
return "jruby" if options[:platform] == "jruby"
183187
options.fetch(:rubyvm) { ENV['RCD_RUBYVM'] } || "mri"

test/test_starter.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def test_container_image_name
3838
with_env({"RAKE_COMPILER_DOCK_IMAGE" => "env-var-value"}) do
3939
assert_equal("env-var-value", Starter.container_image_name)
4040
end
41+
with_env({"CONTAINER_REGISTRY" => "env-var-value"}) do
42+
assert_match(/env-var-value\//, Starter.container_image_name(platform: "x64-mingw-ucrt"))
43+
end
44+
with_env({"RCD_IMAGE_VERSION" => "env-var-value"}) do
45+
assert_match(/:env-var-value-/, Starter.container_image_name(platform: "x64-mingw-ucrt"))
46+
end
4147

4248
# with image option
4349
assert_equal("option-value", Starter.container_image_name({:image => "option-value"}))

0 commit comments

Comments
 (0)