Skip to content

Commit

Permalink
Move build scripts to bash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schneems committed Mar 26, 2024
1 parent 7508c69 commit b37a98b
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 87 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/build_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
- name: Build Docker image
run: bundle exec rake "generate_image[$STACK]"
run: bin/activate_docker "$STACK"
- name: Generate Ruby Dockerfile
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
- name: Build and package Ruby runtime
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
- name: Build Docker image
run: bundle exec rake "generate_image[$STACK]"
run: bin/activate_docker "$STACK"
- name: Generate Ruby Dockerfile
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
- name: Build and package Ruby runtime
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
- name: Build Docker image
run: bundle exec rake "generate_image[$STACK]"
run: bin/activate_docker "$STACK"
- name: Generate Ruby Dockerfile
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
- name: Build and package Ruby runtime
Expand All @@ -122,16 +122,18 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
- name: Install dependencies
run: bundle install
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
# - name: Set up Ruby
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: '3.2'
# - name: Bootstrap ruby
# run: sudo apt-get update -y; sudo apt-get install --no-install-recommends ruby -y
# - name: Install dependencies
# run: bundle install
# - name: Output CHANGELOG
# run: bundle exec rake "changelog[${{inputs.ruby_version}}]"
- name: Build Docker image
run: bundle exec rake "generate_image[$STACK]"
run: bin/activate_docker "$STACK"
- name: Generate Ruby Dockerfile
run: bundle exec rake "new[${{inputs.ruby_version}},$STACK]"
- name: Build and package Ruby runtime
Expand Down
55 changes: 28 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,52 @@ jobs:
runs-on: pub-hk-ubuntu-22.04-xlarge
strategy:
matrix:
stack: ["heroku-20", "heroku-22", "heroku-24"]
stack: ["heroku-20", "heroku-22"]
version: ["3.1.4"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
- name: Install dependencies
run: bundle install
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{matrix.version}}]"
run: bin/print_changelog "${{matrix.version}}"
- name: Build Docker image
run: bundle exec rake "generate_image[${{matrix.stack}}]"
- name: Generate Ruby Dockerfile
run: bundle exec rake "new[${{matrix.version}},${{matrix.stack}}]"
run: bin/activate_docker "${{matrix.stack}}"
- name: Build and package Ruby runtime
run: bash "rubies/${{matrix.stack}}/ruby-${{matrix.version}}.sh"
run: bin/build_ruby "${{matrix.stack}}" "${{matrix.version}}"
- name: Verify ruby executable and output rubygems version
run: bundle exec rake "rubygems_version[${{matrix.version}},${{matrix.stack}}]"
run: bin/print_gem_version "${{matrix.stack}}" "${{matrix.version}}"

integration_test-arm:
runs-on: pub-hk-ubuntu-22.04-arm-large
integration_test-heroku-24-amd:
runs-on: pub-hk-ubuntu-22.04-xlarge
strategy:
matrix:
stack: ["heroku-24"]
version: ["3.2.3"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
- name: Install dependencies
run: bundle install
- name: Output CHANGELOG
run: bundle exec rake "changelog[${{matrix.version}}]"
run: bin/print_changelog "${{matrix.version}}"
- name: Build Docker image
run: bundle exec rake "generate_image[${{matrix.stack}}]"
- name: Generate Ruby Dockerfile
run: bundle exec rake "new[${{matrix.version}},${{matrix.stack}}]"
run: bin/activate_docker "${{matrix.stack}}"
- name: Build and package Ruby runtime
run: bash "rubies/${{matrix.stack}}/ruby-${{matrix.version}}.sh"
run: bin/build_ruby "${{matrix.stack}}" "${{matrix.version}}"
- name: Verify ruby executable and output rubygems version
run: bundle exec rake "rubygems_version[${{matrix.version}},${{matrix.stack}}]"
run: bin/print_gem_version "${{matrix.stack}}" "${{matrix.version}}" amd64

integration_test-heroku-24-arm:
runs-on: pub-hk-ubuntu-22.04-arm-large
strategy:
matrix:
stack: ["heroku-24"]
version: ["3.2.3"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Output CHANGELOG
run: bin/print_changelog "${{matrix.version}}"
- name: Build Docker image
run: bin/activate_docker "${{matrix.stack}}"
- name: Build and package Ruby runtime
run: bin/build_ruby "${{matrix.stack}}" "${{matrix.version}}"
- name: Verify ruby executable and output rubygems version
run: bin/print_gem_version "${{matrix.stack}}" "${{matrix.version}}" arm64
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM heroku/heroku:24-build

USER root

# setup workspace
RUN rm -rf /tmp/workspace
RUN mkdir -p /tmp/workspace

RUN apt-get update -y; apt-get install ruby -y
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# output dir is mounted

ADD build.rb /tmp/build.rb
COPY lib/ /tmp/lib/
CMD ["ruby", "/tmp/build.rb", "/tmp/workspace", "/tmp/output", "/tmp/cache"]
25 changes: 2 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,9 @@ This build tool supports heroku's multiple stacks. The built rubies will go in t

### Building

First we'll need to generate the docker images needed for building the appropriate stack.

```sh
$ bundle exec rake "generate_image[heroku-22]"
```

Generate a ruby build script:

```sh
$ bundle exec rake "new[3.1.3,heroku-22]"
```

From here, we can now execute a ruby build:

```
$ bash rubies/heroku-22/ruby-3.1.3.sh
```

When it's complete you should now see `builds/heroku-22/ruby-3.1.3.tgz`.

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.

```sh
$ bundle exec rake upload[3.1.3,heroku-22]
$ bin/activate_docker heroku-24
$ bin/build_ruby heroku-24 3.2.3
```

### Building a GIT_URL release
Expand Down
25 changes: 0 additions & 25 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,6 @@ task :upload, [:version, :stack, :staging] do |t, args|
end
end

desc "Build docker image for stack"
task :generate_image, [:stack] do |t, args|
require "fileutils"
stack = args[:stack]
FileUtils.cp("dockerfiles/Dockerfile.#{stack}", "Dockerfile")
image = "hone/ruby-builder:#{stack}"
arguments = ["-t #{image}"]

# rubocop:disable Lint/EmptyWhen
# TODO: Local cross compile story?
# case stack
# when "heroku-24"
# arguments.push("--platform='linux/amd64,linux/arm64'")
# when "heroku-20", "heroku-22"
# else
# raise "Unknown stack: #{stack}"
# end
# rubocop:enable Lint/EmptyWhen

command = "docker build #{arguments.join(" ")} ."
puts "Running: `#{command}`"
system(command)
FileUtils.rm("Dockerfile")
end

desc "Test images"
task :test, [:version, :stack, :staging] do |t, args|
require "hatchet"
Expand Down
14 changes: 14 additions & 0 deletions bin/activate_docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

BASE_IMAGE=$1
if [ -z "$BASE_IMAGE" ]
then
echo "Base image argument is requied i.e. 'heroku-24'"
exit 1
fi

cp "dockerfiles/Dockerfile.$BASE_IMAGE" Dockerfile

docker build -t hone/ruby-builder:$BASE_IMAGE .
25 changes: 25 additions & 0 deletions bin/build_ruby
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -euo pipefail

BASE_IMAGE=$1
VERSION=$2

if [ -z "$BASE_IMAGE" ]
then
echo "Base image argument is requied i.e. 'heroku-24'"
exit 1
fi

if [ -z "$VERSION" ]
then
echo "Version is required i.e. '3.2.3"
exit 1
fi

echo "Building Ruby $VERSION on $BASE_IMAGE"

OUTPUT_DIR=${OUTPUT_DIR:-`pwd`/builds}
CACHE_DIR=${CACHE_DIR:-`pwd`/cache}

docker run -v $OUTPUT_DIR:/tmp/output -v $CACHE_DIR:/tmp/cache -e VERSION="$VERSION" -e STACK=$BASE_IMAGE hone/ruby-builder:$BASE_IMAGE
26 changes: 26 additions & 0 deletions bin/print_changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -euo pipefail
VERSION=$1

if [ -z "$VERSION" ]
then
echo "Version is required i.e. '3.2.3"
exit 1
fi

echo "Add a changelog item: https://devcenter.heroku.com/admin/changelog_items/new"
echo

cat <<EOM
## Ruby version ruby-$VERSION is now available
[Ruby v$VERSION](/articles/ruby-support#ruby-versions) is now available on Heroku. To run
your app using this version of Ruby, add the following \`ruby\` directive to your Gemfile:
\`\`\`ruby
ruby "$VERSION"
\`\`\`
For more information on [Ruby #{parts.download_format}, you can view the release announcement](https://www.ruby-lang.org/en/news/).
EOM
31 changes: 31 additions & 0 deletions bin/print_gem_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -euo pipefail

BASE_IMAGE=$1
VERSION=$2
ARCH=$3

if [ -z "$BASE_IMAGE" ]
then
echo "Base image argument is requied i.e. 'heroku-24'"
exit 1
fi

if [ -z "$VERSION" ]
then
echo "Version is required i.e. '3.2.3"
exit 1
fi

echo "Printing gem version for Ruby $VERSION on $BASE_IMAGE"

if [ -z "$ARCH" ]; then
echo "ARCH is not set"
ruby_tar_file="$BASE_IMAGE/ruby-$VERSION.tgz"
else
echo "Using arch '$ARCH'"
ruby_tar_file="$BASE_IMAGE/$ARCH/ruby-$VERSION.tgz"
fi

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 comments on commit b37a98b

Please sign in to comment.