Skip to content

Commit 2b6620a

Browse files
authored
Merge pull request #95 from rake-compiler/flavorjones-move-to-ghcr.io
change location of docker images to ghcr.io
2 parents ce619f2 + 187e671 commit 2b6620a

File tree

8 files changed

+199
-42
lines changed

8 files changed

+199
-42
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
run: |
6060
docker buildx create --driver docker-container --use
6161
bundle exec rake build:${PLATFORM} RCD_DOCKER_BUILD="docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load"
62+
docker images
6263
6364
- name: Move build cache and remove outdated layers
6465
run: |

.github/workflows/publish-images.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ jobs:
2222
- arm64-darwin
2323
- arm-linux
2424
- aarch64-linux
25-
include:
26-
- platform: jruby
27-
tag: jruby
25+
- jruby
2826
runs-on: ubuntu-latest
2927
steps:
3028
- uses: actions/checkout@v3
@@ -39,11 +37,18 @@ jobs:
3937
with:
4038
ruby-version: "3.1"
4139
bundler-cache: true
42-
- id: rcd_image_version
43-
run: bundle exec ruby -e 'require "rake_compiler_dock"; puts "rcd_image_version=#{RakeCompilerDock::IMAGE_VERSION}"' >> $GITHUB_OUTPUT
40+
- id: rcd_config
41+
run: |
42+
bundle exec ruby -e ' \
43+
require "rake_compiler_dock"; \
44+
print "image_name="; \
45+
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}})); \
46+
print "snapshot_name="; \
47+
puts RakeCompilerDock::Starter.container_image_name(:platform => %q(${{matrix.platform}}), :version => %q(snapshot)); \
48+
' | tee -a $GITHUB_OUTPUT
49+
4450
- name: Build docker image
4551
env:
46-
DOCKERHUB_USER: rake-compiler
4752
RCD_DOCKER_BUILD: docker buildx build --cache-from=type=local,src=tmp/build-cache --cache-to=type=local,dest=tmp/build-cache-new --load
4853
run: |
4954
docker buildx create --driver docker-container --use
@@ -56,10 +61,7 @@ jobs:
5661
registry: ghcr.io
5762
username: ${{github.actor}}
5863
password: ${{secrets.GITHUB_TOKEN}}
59-
- env:
60-
OLD_TAG: rake-compiler/rake-compiler-dock-${{matrix.tag || format('mri-{0}', matrix.platform)}}:${{steps.rcd_image_version.outputs.rcd_image_version}}
61-
NEW_TAG: ghcr.io/rake-compiler/rake-compiler-dock-snapshot:${{matrix.platform}}
62-
run: |
64+
- run: |
6365
docker images
64-
docker tag ${OLD_TAG} ${NEW_TAG}
65-
docker push ${NEW_TAG}
66+
docker tag ${{steps.rcd_config.outputs.image_name}} ${{steps.rcd_config.outputs.snapshot_name}}
67+
docker push ${{steps.rcd_config.outputs.snapshot_name}}

History.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
* Ensure autoconf is installed in the base iamges.
1010
* Start publishing snapshots to ghcr.io
1111
* Bump JRuby to 9.4.0.0
12+
* Move docker images to ghcr.io/rake-compiler:
13+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-jruby`
14+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-aarch64-linux`
15+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-arm-linux`
16+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-arm64-darwin`
17+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x64-mingw-ucrt`
18+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x64-mingw32`
19+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x86-linux`
20+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x86-mingw32`
21+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x86_64-darwin`
22+
* `ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-x86_64-linux`
1223

1324

1425
1.2.2 / 2022-06-27

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
name: "native-gem"
188188
runs-on: ubuntu-latest
189189
container:
190-
image: "larskanis/rake-compiler-dock-mri-x86_64-linux:1.2.1"
190+
image: "ghcr.io/rake-compiler/rake-compiler-dock-image:1.2.2-mri-x86_64-linux"
191191
steps:
192192
- uses: actions/checkout@v2
193193
- run: bundle install && bundle exec rake gem:x86_64-linux:rcd
@@ -221,11 +221,9 @@ For an example of rake tasks that support this style of invocation, visit https:
221221

222222
### Living on the edge: using weekly snapshots
223223

224-
OCI images snapshotted from `master` are published weekly to Github Container Registry:
224+
OCI images snapshotted from `master` are published weekly to Github Container Registry with the string "snapshot" in place of the version number in the tag name, e.g.:
225225

226-
> https://github.com/rake-compiler/rake-compiler-dock/pkgs/container/rake-compiler-dock-snapshot
227-
228-
The images are named `ghcr.io/rake-compiler/rake-compiler-dock-snapshot` and are tagged with the platform name (e.g., `ghcr.io/rake-compiler/rake-compiler-dock-snapshot:x86_64-linux`.
226+
- `ghcr.io/rake-compiler/rake-compiler-dock-image:snapshot-mri-x86_64-linux`
229227

230228
These images are intended for integration testing. They may not work properly and should not be considered production ready.
231229

@@ -242,7 +240,7 @@ The following variables are recognized by rake-compiler-dock:
242240
Must be a space separated list out of `x86-mingw32`, `x64-mingw-ucrt`, `x64-mingw32`, `x86-linux`, `x86_64-linux`, `arm-linux`, `aarch64-linux`, `x86_64-darwin` and `arm64-darwin`.
243241
It is ignored when `rubyvm` is set to `:jruby`.
244242
* `RCD_IMAGE` - The docker image that is downloaded and started.
245-
Defaults to "larskanis/rake-compiler-dock:IMAGE_VERSION" with an image version that is determined by the gem version.
243+
Defaults to "ghcr.io/rake-compiler/rake-compiler-dock-image:IMAGE_VERSION-PLATFORM" with an image version that is determined by the gem version.
246244

247245
The following variables are passed through to the docker container without modification:
248246

Rakefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require_relative "build/parallel_docker_build"
66

77
RakeCompilerDock::GemHelper.install_tasks
88

9-
DOCKERHUB_USER = ENV['DOCKERHUB_USER'] || "larskanis"
109
docker_build_cmd = Shellwords.split(ENV['RCD_DOCKER_BUILD'] || "docker build")
1110

1211
platforms = [
@@ -29,7 +28,8 @@ namespace :build do
2928
desc "Build image for platform #{platform}"
3029
task platform => sdf
3130
task sdf do
32-
sh(*docker_build_cmd, "-t", "#{DOCKERHUB_USER}/rake-compiler-dock-mri-#{platform}:#{RakeCompilerDock::IMAGE_VERSION}", "-f", "Dockerfile.mri.#{platform}", ".")
31+
image_name = RakeCompilerDock::Starter.container_image_name(platform: platform)
32+
sh(*docker_build_cmd, "-t", image_name, "-f", "Dockerfile.mri.#{platform}", ".")
3333
end
3434

3535
df = ERB.new(File.read("Dockerfile.mri.erb"), trim_mode: ">").result(binding)
@@ -40,7 +40,8 @@ namespace :build do
4040
desc "Build image for JRuby"
4141
task :jruby => "Dockerfile.jruby"
4242
task "Dockerfile.jruby" do
43-
sh(*docker_build_cmd, "-t", "#{DOCKERHUB_USER}/rake-compiler-dock-jruby:#{RakeCompilerDock::IMAGE_VERSION}", "-f", "Dockerfile.jruby", ".")
43+
image_name = RakeCompilerDock::Starter.container_image_name(rubyvm: "jruby")
44+
sh(*docker_build_cmd, "-t", image_name, "-f", "Dockerfile.jruby", ".")
4445
end
4546

4647
RakeCompilerDock::ParallelDockerBuild.new(platforms.map{|pl, _| "Dockerfile.mri.#{pl}" } + ["Dockerfile.jruby"], workdir: "tmp/docker", docker_build_cmd: docker_build_cmd)
@@ -57,14 +58,14 @@ task :build => "build:all"
5758
namespace :prepare do
5859
desc "Build cross compiler for x64-mingw-ucrt aka RubyInstaller-3.1+"
5960
task "mingw64-ucrt" do
60-
sh(*docker_build_cmd, "-t", "#{DOCKERHUB_USER}/mingw64-ucrt:20.04", ".",
61+
sh(*docker_build_cmd, "-t", "larskanis/mingw64-ucrt:20.04", ".",
6162
chdir: "mingw64-ucrt")
6263
end
6364
end
6465

6566
desc "Run tests"
6667
task :test do
67-
sh "ruby -w -W2 -I. -Ilib -e \"#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}\" -- -v"
68+
sh %Q{ruby -w -W2 -I. -Ilib -e "#{Dir["test/test_*.rb"].map{|f| "require '#{f}';"}.join}" -- -v #{ENV['TESTOPTS']}}
6869
end
6970

7071
desc "Update predefined_user_group.rb"
@@ -92,12 +93,12 @@ end
9293
namespace :release do
9394
desc "push all docker images"
9495
task :images do
95-
jimg = "#{DOCKERHUB_USER}/rake-compiler-dock-jruby:#{RakeCompilerDock::IMAGE_VERSION}"
96-
sh "docker", "push", jimg
96+
image_name = RakeCompilerDock::Starter.container_image_name(rubyvm: "jruby")
97+
sh("docker", "push", image_name)
9798

9899
platforms.each do |platform, _|
99-
img = "#{DOCKERHUB_USER}/rake-compiler-dock-mri-#{platform}:#{RakeCompilerDock::IMAGE_VERSION}"
100-
sh "docker", "push", img
100+
image_name = RakeCompilerDock::Starter.container_image_name(platform: platform)
101+
sh("docker", "push", image_name)
101102
end
102103
end
103104
end

lib/rake_compiler_dock/starter.rb

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,9 @@ def exec(*args)
4040
end
4141
user = options.fetch(:username){ current_user }
4242
group = options.fetch(:groupname){ current_group }
43-
rubyvm = options.fetch(:rubyvm){ ENV['RCD_RUBYVM'] } || "mri"
44-
jrubyvm = rubyvm.to_s == "jruby"
45-
46-
platforms = options.fetch(:platform){ ENV['RCD_PLATFORM'] } || (jrubyvm ? "jruby" : "x86-mingw32 x64-mingw32")
47-
platforms.split(" ").each do |platform|
48-
image_name = options.fetch(:image) do
49-
platform_postfix = jrubyvm ? "" : "-#{platform}"
50-
ENV['RCD_IMAGE'] ||
51-
ENV['RAKE_COMPILER_DOCK_IMAGE'] ||
52-
"larskanis/rake-compiler-dock-#{rubyvm}#{platform_postfix}:#{IMAGE_VERSION}"
53-
end
43+
44+
platforms(options).split(" ").each do |platform|
45+
image_name = container_image_name(options.merge(platform: platform))
5446

5547
check = check_docker(mountdir) if options.fetch(:check_docker){ true }
5648
docker_opts = options.fetch(:options) do
@@ -166,6 +158,38 @@ def check_docker(pwd)
166158
def sanitize_windows_path(path)
167159
path.gsub(/^([a-z]):/i){ "/#{$1.downcase}" }
168160
end
161+
162+
def container_image_name(options={})
163+
options.fetch(:image) do
164+
image_name = ENV['RCD_IMAGE'] || ENV['RAKE_COMPILER_DOCK_IMAGE']
165+
return image_name unless image_name.nil?
166+
167+
"%s/rake-compiler-dock-image:%s-%s%s" % [
168+
container_registry,
169+
options.fetch(:version) { IMAGE_VERSION },
170+
container_rubyvm(options),
171+
container_jrubyvm?(options) ? "" : "-#{options.fetch(:platform)}",
172+
]
173+
end
174+
end
175+
176+
def container_registry
177+
ENV['CONTAINER_REGISTRY'] || "ghcr.io/rake-compiler"
178+
end
179+
180+
def container_rubyvm(options={})
181+
return "jruby" if options[:platform] == "jruby"
182+
options.fetch(:rubyvm) { ENV['RCD_RUBYVM'] } || "mri"
183+
end
184+
185+
def container_jrubyvm?(options={})
186+
container_rubyvm(options).to_s == "jruby"
187+
end
188+
189+
def platforms(options={})
190+
options.fetch(:platform) { ENV['RCD_PLATFORM'] } ||
191+
(container_jrubyvm?(options) ? "jruby" : "x86-mingw32 x64-mingw32")
192+
end
169193
end
170194
end
171195
end

test/test_environment_variables.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
class TestEnvironmentVariables
1010
module Common
1111
TEST_PLATFORM = ENV["TEST_PLATFORM"] || "x64-mingw-ucrt"
12-
DOCKERHUB_USER = ENV['DOCKERHUB_USER'] || "larskanis"
13-
1412
IS_JRUBY = TEST_PLATFORM.to_s == "jruby"
15-
platform = IS_JRUBY ? "jruby" : "mri-#{TEST_PLATFORM}"
16-
TEST_IMAGE_NAME = "#{DOCKERHUB_USER}/rake-compiler-dock-#{platform}:#{RakeCompilerDock::IMAGE_VERSION}"
13+
TEST_IMAGE_NAME = if IS_JRUBY
14+
RakeCompilerDock::Starter.container_image_name(rubyvm: "jruby")
15+
else
16+
RakeCompilerDock::Starter.container_image_name(platform: TEST_PLATFORM)
17+
end
1718

1819
def rcd_env
1920
self.class.instance_variable_get("@rcd_env") || begin

test/test_starter.rb

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,123 @@ def test_make_valid_group_name
3030
assert_equal "_", Starter.make_valid_group_name(nil)
3131
end
3232

33+
def test_container_image_name
34+
# with env vars
35+
with_env({"RCD_IMAGE" => "env-var-value"}) do
36+
assert_equal("env-var-value", Starter.container_image_name)
37+
end
38+
with_env({"RAKE_COMPILER_DOCK_IMAGE" => "env-var-value"}) do
39+
assert_equal("env-var-value", Starter.container_image_name)
40+
end
41+
42+
# with image option
43+
assert_equal("option-value", Starter.container_image_name({:image => "option-value"}))
44+
45+
# with env var and image option, image option wins
46+
with_env({"RCD_IMAGE" => "env-var-value"}) do
47+
assert_equal("option-value", Starter.container_image_name({:image => "option-value"}))
48+
end
49+
50+
# mri platform arg
51+
assert_equal(
52+
"ghcr.io/rake-compiler/rake-compiler-dock-image:#{IMAGE_VERSION}-mri-platform-option-value",
53+
Starter.container_image_name({:platform => "platform-option-value"}),
54+
)
55+
56+
# jruby rubyvm arg
57+
assert_equal(
58+
"ghcr.io/rake-compiler/rake-compiler-dock-image:#{IMAGE_VERSION}-jruby",
59+
Starter.container_image_name({:rubyvm => "jruby"}),
60+
)
61+
62+
# jruby platform arg
63+
assert_equal(
64+
"ghcr.io/rake-compiler/rake-compiler-dock-image:#{IMAGE_VERSION}-jruby",
65+
Starter.container_image_name({:platform => "jruby"}),
66+
)
67+
68+
# container registry env var
69+
with_env({"CONTAINER_REGISTRY" => "registry-value"}) do
70+
assert_equal(
71+
"registry-value/rake-compiler-dock-image:#{IMAGE_VERSION}-mri-x86_64-darwin",
72+
Starter.container_image_name({:platform => "x86_64-darwin"}),
73+
)
74+
end
75+
76+
# snapshots
77+
assert_equal(
78+
"ghcr.io/rake-compiler/rake-compiler-dock-image:snapshot-mri-x86_64-darwin",
79+
Starter.container_image_name({:platform =>"x86_64-darwin", :version => "snapshot"}),
80+
)
81+
end
82+
83+
def test_container_registry
84+
assert_equal("ghcr.io/rake-compiler", Starter.container_registry)
85+
86+
with_env({"CONTAINER_REGISTRY" => "env-var-value"}) do
87+
assert_equal("env-var-value", Starter.container_registry)
88+
end
89+
end
90+
91+
def test_container_rubyvm
92+
# no args
93+
assert_equal("mri", Starter.container_rubyvm)
94+
95+
# with env var
96+
with_env({"RCD_RUBYVM" => "env-var-value"}) do
97+
assert_equal("env-var-value", Starter.container_rubyvm)
98+
end
99+
100+
# with rubyvm option
101+
assert_equal("option-value", Starter.container_rubyvm({:rubyvm => "option-value"}))
102+
103+
# with rubyvm option and env var, rubyvm option wins
104+
with_env({"RCD_RUBYVM" => "env-var-value"}) do
105+
assert_equal("option-value", Starter.container_rubyvm({:rubyvm => "option-value"}))
106+
end
107+
108+
# with jruby platform option
109+
assert_equal("jruby", Starter.container_rubyvm({:platform => "jruby"}))
110+
end
111+
112+
def test_container_jrubyvm?
113+
assert(Starter.container_jrubyvm?({:rubyvm => "jruby"}))
114+
assert(Starter.container_jrubyvm?({:platform => "jruby"}))
115+
refute(Starter.container_jrubyvm?({:rubyvm => "mri"}))
116+
refute(Starter.container_jrubyvm?({:platform => "x86_64-linux"}))
117+
end
118+
119+
def test_platforms
120+
# no args
121+
assert_equal("x86-mingw32 x64-mingw32", Starter.platforms)
122+
123+
# with env var
124+
with_env({"RCD_PLATFORM" => "env-var-value"}) do
125+
assert_equal("env-var-value", Starter.platforms)
126+
end
127+
128+
# with platform option
129+
assert_equal("option-value", Starter.platforms({:platform => "option-value"}))
130+
131+
# with platform option and env var, platform option wins
132+
with_env({"RCD_PLATFORM" => "arm64-darwin"}) do
133+
assert_equal("option-value", Starter.platforms({:platform => "option-value"}))
134+
end
135+
136+
# when options rubyvm is set to jruby
137+
assert_equal("jruby", Starter.platforms({:rubyvm => "jruby"}))
138+
end
139+
140+
def with_env(env = {})
141+
original_env = {}
142+
env.each do |k, v|
143+
original_env[k] = ENV[k]
144+
ENV[k] = v
145+
end
146+
yield
147+
ensure
148+
original_env.each do |k, v|
149+
ENV[k] = v
150+
end
151+
end
33152
end

0 commit comments

Comments
 (0)