Custom run image with corrected HOME #968
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Test, Publish | |
on: | |
pull_request: | |
push: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
defaults: | |
run: | |
# Setting an explicit bash shell ensures GitHub Actions enables pipefail mode too, rather | |
# than only error on exit. This is important for UX since this workflow uses pipes. See: | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell | |
shell: bash | |
jobs: | |
create: | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
builder: ["buildpacks-20", "builder-classic-22"] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Pack CLI | |
uses: buildpacks/github-actions/[email protected] | |
- run: docker build --file base-images/20/Dockerfile.run -t test-heroku-20-run base-images/20/ | |
- run: docker build --file base-images/22/Dockerfile.run -t test-heroku-22-run base-images/22/ | |
- name: Create builder image | |
run: pack builder create ${{ matrix.builder }} --config ${{ matrix.builder }}/builder.toml --pull-policy if-not-present | |
# We export the run image too (and not just the generated builder image), since it adds virtually | |
# no size to the archive (since the layers are mostly duplicates), and it ends up being quicker | |
# than docker pulling the run image in the jobs that perform the pack build. | |
# We manually compress the archive rather than relying upon actions/cache's compression, since | |
# it ends up being faster both in this job and also later when the images are consumed. | |
- name: Export Docker images from the Docker daemon | |
# Using sed rather than yq until this yq bug is fixed: | |
# https://github.com/mikefarah/yq/issues/1758 | |
run: | | |
RUN_IMAGE_TAG=$(sed --quiet --regexp-extended --expression 's/run-image\s*=\s*"(.+)"/\1/p' ${{ matrix.builder }}/builder.toml) | |
docker save ${{ matrix.builder }} ${RUN_IMAGE_TAG} | zstd -T0 --long=31 -o images.tar.zst | |
# We use a cache here rather than artifacts because it's 4x faster and we | |
# don't need the builder archive outside of this workflow run anyway. | |
- name: Save Docker images to the cache | |
uses: actions/cache/save@v4 | |
with: | |
key: ${{ github.run_id}}-${{ matrix.builder }} | |
path: images.tar.zst | |
test-guides: | |
runs-on: ubuntu-22.04 | |
needs: create | |
strategy: | |
fail-fast: false | |
matrix: | |
builder: ["buildpacks-20", "builder-classic-22"] | |
language: ["go", "gradle", "java", "node-js", "php", "python", "ruby", "scala"] | |
include: | |
- builder: builder-classic-22 | |
language: clojure | |
steps: | |
- name: Checkout getting started guide | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
repository: heroku/${{ matrix.language }}-getting-started.git | |
- name: Install Pack CLI | |
uses: buildpacks/github-actions/[email protected] | |
with: | |
# Work around https://github.com/buildpacks/pack/issues/2078 | |
pack-version: '0.32.1' | |
- name: Restore Docker images from the cache | |
uses: actions/cache/restore@v4 | |
with: | |
fail-on-cache-miss: true | |
key: ${{ github.run_id}}-${{ matrix.builder }} | |
path: images.tar.zst | |
env: | |
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1 | |
- name: Load Docker images into the Docker daemon | |
run: zstd -dc --long=31 images.tar.zst | docker load | |
- name: Build getting started guide image | |
run: pack build getting-started --builder ${{ matrix.builder }} --trust-builder --pull-policy never --env ALLOW_EOL_SHIMMED_BUILDER=1 | |
- name: Start getting started guide image | |
# The `DYNO` env var is set to more accurately reflect the Heroku environment, since some of the getting | |
# started guides use the presence of `DYNO` to determine whether to enable production mode or not. | |
run: docker run --name getting-started --detach -p 8080:8080 --env PORT=8080 --env DYNO=web.1 getting-started | |
- name: Test getting started web server response | |
run: | | |
if curl -sSf --retry 10 --retry-delay 1 --retry-all-errors --connect-timeout 3 http://localhost:8080 -o response.txt; then | |
echo "Successful response from server" | |
else | |
echo "Server did not respond successfully" | |
docker logs getting-started | |
[[ -f response.txt ]] && cat response.txt | |
exit 1 | |
fi |