Skip to content

Commit b37a98b

Browse files
committed
Move build scripts to bash
We shouldn't need Ruby installed on the runner, and again the container just to be able to build Ruby versions. This commit moves functionality that doesn't **need** to be in Ruby to bash. This is needed as ruby/setup-ruby does not currently work with ARM ruby/setup-ruby#577.
1 parent 7508c69 commit b37a98b

File tree

9 files changed

+157
-87
lines changed

9 files changed

+157
-87
lines changed

.github/workflows/build_ruby.yml

+14-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Output CHANGELOG
4141
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
4242
- name: Build Docker image
43-
run: bundle exec rake "generate_image[$STACK]"
43+
run: bin/activate_docker "$STACK"
4444
- name: Generate Ruby Dockerfile
4545
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
4646
- name: Build and package Ruby runtime
@@ -68,7 +68,7 @@ jobs:
6868
- name: Output CHANGELOG
6969
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
7070
- name: Build Docker image
71-
run: bundle exec rake "generate_image[$STACK]"
71+
run: bin/activate_docker "$STACK"
7272
- name: Generate Ruby Dockerfile
7373
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
7474
- name: Build and package Ruby runtime
@@ -97,7 +97,7 @@ jobs:
9797
- name: Output CHANGELOG
9898
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
9999
- name: Build Docker image
100-
run: bundle exec rake "generate_image[$STACK]"
100+
run: bin/activate_docker "$STACK"
101101
- name: Generate Ruby Dockerfile
102102
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
103103
- name: Build and package Ruby runtime
@@ -122,16 +122,18 @@ jobs:
122122
steps:
123123
- name: Checkout
124124
uses: actions/checkout@v3
125-
- name: Set up Ruby
126-
uses: ruby/setup-ruby@v1
127-
with:
128-
ruby-version: '3.2'
129-
- name: Install dependencies
130-
run: bundle install
131-
- name: Output CHANGELOG
132-
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
125+
# - name: Set up Ruby
126+
# uses: ruby/setup-ruby@v1
127+
# with:
128+
# ruby-version: '3.2'
129+
# - name: Bootstrap ruby
130+
# run: sudo apt-get update -y; sudo apt-get install --no-install-recommends ruby -y
131+
# - name: Install dependencies
132+
# run: bundle install
133+
# - name: Output CHANGELOG
134+
# run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
133135
- name: Build Docker image
134-
run: bundle exec rake "generate_image[$STACK]"
136+
run: bin/activate_docker "$STACK"
135137
- name: Generate Ruby Dockerfile
136138
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
137139
- name: Build and package Ruby runtime

.github/workflows/ci.yml

+28-27
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,52 @@ jobs:
3535
runs-on: pub-hk-ubuntu-22.04-xlarge
3636
strategy:
3737
matrix:
38-
stack: ["heroku-20", "heroku-22", "heroku-24"]
38+
stack: ["heroku-20", "heroku-22"]
3939
version: ["3.1.4"]
4040
steps:
4141
- name: Checkout
4242
uses: actions/checkout@v4
43-
- name: Set up Ruby
44-
uses: ruby/setup-ruby@v1
45-
with:
46-
ruby-version: '3.1'
47-
- name: Install dependencies
48-
run: bundle install
4943
- name: Output CHANGELOG
50-
run: bundle exec rake "changelog[${{matrix.version}}]"
44+
run: bin/print_changelog "${{matrix.version}}"
5145
- name: Build Docker image
52-
run: bundle exec rake "generate_image[${{matrix.stack}}]"
53-
- name: Generate Ruby Dockerfile
54-
run: bundle exec rake "new[${{matrix.version}},${{matrix.stack}}]"
46+
run: bin/activate_docker "${{matrix.stack}}"
5547
- name: Build and package Ruby runtime
56-
run: bash "rubies/${{matrix.stack}}/ruby-${{matrix.version}}.sh"
48+
run: bin/build_ruby "${{matrix.stack}}" "${{matrix.version}}"
5749
- name: Verify ruby executable and output rubygems version
58-
run: bundle exec rake "rubygems_version[${{matrix.version}},${{matrix.stack}}]"
50+
run: bin/print_gem_version "${{matrix.stack}}" "${{matrix.version}}"
5951

60-
integration_test-arm:
61-
runs-on: pub-hk-ubuntu-22.04-arm-large
52+
integration_test-heroku-24-amd:
53+
runs-on: pub-hk-ubuntu-22.04-xlarge
6254
strategy:
6355
matrix:
6456
stack: ["heroku-24"]
6557
version: ["3.2.3"]
6658
steps:
6759
- name: Checkout
6860
uses: actions/checkout@v4
69-
- name: Set up Ruby
70-
uses: ruby/setup-ruby@v1
71-
with:
72-
ruby-version: '3.2'
73-
- name: Install dependencies
74-
run: bundle install
7561
- name: Output CHANGELOG
76-
run: bundle exec rake "changelog[${{matrix.version}}]"
62+
run: bin/print_changelog "${{matrix.version}}"
7763
- name: Build Docker image
78-
run: bundle exec rake "generate_image[${{matrix.stack}}]"
79-
- name: Generate Ruby Dockerfile
80-
run: bundle exec rake "new[${{matrix.version}},${{matrix.stack}}]"
64+
run: bin/activate_docker "${{matrix.stack}}"
8165
- name: Build and package Ruby runtime
82-
run: bash "rubies/${{matrix.stack}}/ruby-${{matrix.version}}.sh"
66+
run: bin/build_ruby "${{matrix.stack}}" "${{matrix.version}}"
8367
- name: Verify ruby executable and output rubygems version
84-
run: bundle exec rake "rubygems_version[${{matrix.version}},${{matrix.stack}}]"
68+
run: bin/print_gem_version "${{matrix.stack}}" "${{matrix.version}}" amd64
8569

70+
integration_test-heroku-24-arm:
71+
runs-on: pub-hk-ubuntu-22.04-arm-large
72+
strategy:
73+
matrix:
74+
stack: ["heroku-24"]
75+
version: ["3.2.3"]
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v4
79+
- name: Output CHANGELOG
80+
run: bin/print_changelog "${{matrix.version}}"
81+
- name: Build Docker image
82+
run: bin/activate_docker "${{matrix.stack}}"
83+
- name: Build and package Ruby runtime
84+
run: bin/build_ruby "${{matrix.stack}}" "${{matrix.version}}"
85+
- name: Verify ruby executable and output rubygems version
86+
run: bin/print_gem_version "${{matrix.stack}}" "${{matrix.version}}" arm64

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM heroku/heroku:24-build
2+
3+
USER root
4+
5+
# setup workspace
6+
RUN rm -rf /tmp/workspace
7+
RUN mkdir -p /tmp/workspace
8+
9+
RUN apt-get update -y; apt-get install ruby -y
10+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
11+
ENV PATH="/root/.cargo/bin:${PATH}"
12+
13+
# output dir is mounted
14+
15+
ADD build.rb /tmp/build.rb
16+
COPY lib/ /tmp/lib/
17+
CMD ["ruby", "/tmp/build.rb", "/tmp/workspace", "/tmp/output", "/tmp/cache"]

README.md

+2-23
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,9 @@ This build tool supports heroku's multiple stacks. The built rubies will go in t
5353

5454
### Building
5555

56-
First we'll need to generate the docker images needed for building the appropriate stack.
57-
58-
```sh
59-
$ bundle exec rake "generate_image[heroku-22]"
60-
```
61-
62-
Generate a ruby build script:
63-
64-
```sh
65-
$ bundle exec rake "new[3.1.3,heroku-22]"
6656
```
67-
68-
From here, we can now execute a ruby build:
69-
70-
```
71-
$ bash rubies/heroku-22/ruby-3.1.3.sh
72-
```
73-
74-
When it's complete you should now see `builds/heroku-22/ruby-3.1.3.tgz`.
75-
76-
If you set the env vars `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, you can upload them to s3. By default, we upload to the `heroku-buildpack-ruby` s3 bucket.
77-
78-
```sh
79-
$ bundle exec rake upload[3.1.3,heroku-22]
57+
$ bin/activate_docker heroku-24
58+
$ bin/build_ruby heroku-24 3.2.3
8059
```
8160

8261
### Building a GIT_URL release

Rakefile

-25
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,6 @@ task :upload, [:version, :stack, :staging] do |t, args|
7676
end
7777
end
7878

79-
desc "Build docker image for stack"
80-
task :generate_image, [:stack] do |t, args|
81-
require "fileutils"
82-
stack = args[:stack]
83-
FileUtils.cp("dockerfiles/Dockerfile.#{stack}", "Dockerfile")
84-
image = "hone/ruby-builder:#{stack}"
85-
arguments = ["-t #{image}"]
86-
87-
# rubocop:disable Lint/EmptyWhen
88-
# TODO: Local cross compile story?
89-
# case stack
90-
# when "heroku-24"
91-
# arguments.push("--platform='linux/amd64,linux/arm64'")
92-
# when "heroku-20", "heroku-22"
93-
# else
94-
# raise "Unknown stack: #{stack}"
95-
# end
96-
# rubocop:enable Lint/EmptyWhen
97-
98-
command = "docker build #{arguments.join(" ")} ."
99-
puts "Running: `#{command}`"
100-
system(command)
101-
FileUtils.rm("Dockerfile")
102-
end
103-
10479
desc "Test images"
10580
task :test, [:version, :stack, :staging] do |t, args|
10681
require "hatchet"

bin/activate_docker

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BASE_IMAGE=$1
6+
if [ -z "$BASE_IMAGE" ]
7+
then
8+
echo "Base image argument is requied i.e. 'heroku-24'"
9+
exit 1
10+
fi
11+
12+
cp "dockerfiles/Dockerfile.$BASE_IMAGE" Dockerfile
13+
14+
docker build -t hone/ruby-builder:$BASE_IMAGE .

bin/build_ruby

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BASE_IMAGE=$1
6+
VERSION=$2
7+
8+
if [ -z "$BASE_IMAGE" ]
9+
then
10+
echo "Base image argument is requied i.e. 'heroku-24'"
11+
exit 1
12+
fi
13+
14+
if [ -z "$VERSION" ]
15+
then
16+
echo "Version is required i.e. '3.2.3"
17+
exit 1
18+
fi
19+
20+
echo "Building Ruby $VERSION on $BASE_IMAGE"
21+
22+
OUTPUT_DIR=${OUTPUT_DIR:-`pwd`/builds}
23+
CACHE_DIR=${CACHE_DIR:-`pwd`/cache}
24+
25+
docker run -v $OUTPUT_DIR:/tmp/output -v $CACHE_DIR:/tmp/cache -e VERSION="$VERSION" -e STACK=$BASE_IMAGE hone/ruby-builder:$BASE_IMAGE

bin/print_changelog

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
VERSION=$1
5+
6+
if [ -z "$VERSION" ]
7+
then
8+
echo "Version is required i.e. '3.2.3"
9+
exit 1
10+
fi
11+
12+
echo "Add a changelog item: https://devcenter.heroku.com/admin/changelog_items/new"
13+
echo
14+
15+
cat <<EOM
16+
## Ruby version ruby-$VERSION is now available
17+
18+
[Ruby v$VERSION](/articles/ruby-support#ruby-versions) is now available on Heroku. To run
19+
your app using this version of Ruby, add the following \`ruby\` directive to your Gemfile:
20+
21+
\`\`\`ruby
22+
ruby "$VERSION"
23+
\`\`\`
24+
25+
For more information on [Ruby #{parts.download_format}, you can view the release announcement](https://www.ruby-lang.org/en/news/).
26+
EOM

bin/print_gem_version

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
BASE_IMAGE=$1
6+
VERSION=$2
7+
ARCH=$3
8+
9+
if [ -z "$BASE_IMAGE" ]
10+
then
11+
echo "Base image argument is requied i.e. 'heroku-24'"
12+
exit 1
13+
fi
14+
15+
if [ -z "$VERSION" ]
16+
then
17+
echo "Version is required i.e. '3.2.3"
18+
exit 1
19+
fi
20+
21+
echo "Printing gem version for Ruby $VERSION on $BASE_IMAGE"
22+
23+
if [ -z "$ARCH" ]; then
24+
echo "ARCH is not set"
25+
ruby_tar_file="$BASE_IMAGE/ruby-$VERSION.tgz"
26+
else
27+
echo "Using arch '$ARCH'"
28+
ruby_tar_file="$BASE_IMAGE/$ARCH/ruby-$VERSION.tgz"
29+
fi
30+
31+
docker run -v $(pwd)/builds:/tmp/output hone/ruby-builder:$BASE_IMAGE bash -c "mkdir /tmp/unzipped && tar xzf /tmp/output/$ruby_tar_file -C /tmp/unzipped && echo 'Rubygems version is: ' && /tmp/unzipped/bin/gem -v"

0 commit comments

Comments
 (0)