Skip to content

Commit

Permalink
Delete unused/stale internal images
Browse files Browse the repository at this point in the history
  • Loading branch information
edmorley committed Oct 27, 2023
1 parent a968eb3 commit d7aeb38
Showing 1 changed file with 12 additions and 163 deletions.
175 changes: 12 additions & 163 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
name: Build, Test, Publish

on:
pull_request:
push:
branches: ["main"]
schedule:
- cron: "0 0 * * 1-5"
workflow_dispatch:

permissions:
contents: read
Expand All @@ -20,156 +15,12 @@ defaults:

jobs:

create:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
builder: ["buildpacks-20", "builder-classic-22", "builder-20", "builder-22", "salesforce-functions"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Pack CLI
uses: buildpacks/github-actions/[email protected]
- name: Create builder image
run: pack builder create ${{ matrix.builder }} --config ${{ matrix.builder }}/builder.toml --pull-policy always
# 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@v3
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", "builder-20", "builder-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]
- name: Restore Docker images from the cache
uses: actions/cache/restore@v3
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
- 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
test-functions:
runs-on: ubuntu-22.04
needs: create
strategy:
fail-fast: false
matrix:
builder: ["salesforce-functions"]
language: ["java", "javascript", "typescript"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Pack CLI
uses: buildpacks/github-actions/[email protected]
- name: Restore Docker images from the cache
uses: actions/cache/restore@v3
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 example function image
run: pack build example-function --path salesforce-functions/examples/${{ matrix.language }} --builder ${{ matrix.builder }} --trust-builder --pull-policy never
- name: Start example function image
run: docker run --name example-function --detach -p 8080:8080 --env PORT=8080 --env DYNO=web.1 example-function
- name: Test example function web server response
run: |
if curl -sSf --retry 10 --retry-delay 1 --retry-all-errors --connect-timeout 3 -X POST -H 'x-health-check: true' http://localhost:8080 -o response.txt; then
echo "Successful response from function"
else
echo "Function did not respond successfully"
docker logs example-function
[[ -f response.txt ]] && cat response.txt
exit 1
fi
publish:
runs-on: ubuntu-22.04
if: success() && github.ref == 'refs/heads/main'
needs: ["test-guides", "test-functions"]
strategy:
fail-fast: false
matrix:
include:
- builder: buildpacks-20
tag_public: heroku/buildpacks:20
- builder: builder-classic-22
tag_public: heroku/builder-classic:22
- builder: builder-20
tag_public: heroku/builder:20
- builder: builder-22
tag_public: heroku/builder:22
- builder: salesforce-functions
tag_private: heroku-22:builder-functions
steps:
- name: Restore Docker images from the cache
uses: actions/cache/restore@v3
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: Log into Docker Hub
if: matrix.tag_public != ''
run: echo '${{ secrets.DOCKER_HUB_TOKEN }}' | docker login -u '${{ secrets.DOCKER_HUB_USER }}' --password-stdin
- name: Install crane
uses: buildpacks/github-actions/[email protected]
- name: Log into internal registry
if: matrix.tag_private != ''
run: |
REGISTRY_TOKEN=$(
curl -sSf --retry 3 --retry-delay 1 --retry-all-errors --connect-timeout 3 \
Expand All @@ -178,17 +29,15 @@ jobs:
| jq --exit-status -r '.raw_id_token'
)
echo "${REGISTRY_TOKEN}" | docker login '${{ secrets.REGISTRY_HOST }}' -u '${{ secrets.REGISTRY_USER }}' --password-stdin
- name: Tag builder and push to Docker Hub
if: matrix.tag_public != ''
run: |
PUBLIC_IMAGE_URI='${{ matrix.tag_public }}'
set -x
docker tag '${{ matrix.builder }}' "${PUBLIC_IMAGE_URI}"
docker push "${PUBLIC_IMAGE_URI}"
- name: Tag builder and push to internal registry
if: matrix.tag_private != ''
- name: Delete unused internal images
run: |
PRIVATE_IMAGE_URI='${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/${{ matrix.tag_private }}'
set -x
docker tag '${{ matrix.builder }}' "${PRIVATE_IMAGE_URI}"
docker push "${PRIVATE_IMAGE_URI}"
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-18:builder'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-18:build'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-18:run'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-20:builder'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-20:build'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-20:run'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-22:builder'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-22:build'
crane delete '${{ secrets.REGISTRY_HOST }}/s/${{ secrets.SERVICE_TOKEN_USER_NAME }}/heroku-22:run'

0 comments on commit d7aeb38

Please sign in to comment.