ci: try to cache base-platform to avoid docker hub rate limit #198
This file contains hidden or 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: CI | |
| on: [push, pull_request] | |
| jobs: | |
| test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - ballerina | |
| - buildpack | |
| - go | |
| - java | |
| - lua | |
| - nodejs | |
| - perl | |
| - php | |
| - python | |
| - ruby | |
| - scratch | |
| - static | |
| arch: | |
| - amd64 | |
| - arm64 | |
| runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: run tests | |
| run: make test platform=${{ matrix.platform }} | |
| shell: bash | |
| publish: | |
| if: github.repository == 'tsuru/platforms' && github.event_name != 'pull_request' | |
| needs: test | |
| runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - ballerina | |
| - buildpack | |
| - go | |
| - java | |
| - lua | |
| - nodejs | |
| - perl | |
| - php | |
| - python | |
| - ruby | |
| - scratch | |
| - static | |
| arch: | |
| - amd64 | |
| - arm64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: docker/login-action@v3 | |
| if: github.event_name != 'pull_request' | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: Cache Docker base image | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/docker-cache | |
| key: docker-base-platform-24.04-${{ matrix.arch }} | |
| - name: Load cached base image | |
| run: | | |
| if [ -f /tmp/docker-cache/base-platform-24.04.tar ]; then | |
| docker load -i /tmp/docker-cache/base-platform-24.04.tar | |
| echo "Base image loaded from cache" | |
| else | |
| docker pull tsuru/base-platform:24.04 | |
| mkdir -p /tmp/docker-cache | |
| docker save tsuru/base-platform:24.04 -o /tmp/docker-cache/base-platform-24.04.tar | |
| echo "Base image pulled and cached" | |
| fi | |
| shell: bash | |
| - run: | | |
| ref="${GITHUB_REF##*/}" | |
| img="tsuru/${{ matrix.platform }}" | |
| tags="" | |
| if [[ ${ref} == "master" ]] || [[ ${ref} == "main" ]]; then | |
| tags="${img}:latest-${{ matrix.arch }}" | |
| elif [[ ${ref} =~ ^${{ matrix.platform }}-([0-9.]+)$ ]]; then | |
| tags=${img}:${BASH_REMATCH[1]}-${{ matrix.arch }},${img}:latest-${{ matrix.arch }} | |
| fi | |
| echo "tag=${tags}" >> $GITHUB_OUTPUT | |
| if: github.event_name != 'pull_request' | |
| id: tags | |
| shell: bash | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - uses: docker/build-push-action@v5 | |
| if: github.event_name != 'pull_request' && steps.tags.outputs.tag != '' | |
| with: | |
| context: ./${{ matrix.platform }} | |
| push: true | |
| tags: ${{ steps.tags.outputs.tag }} | |
| platforms: linux/${{ matrix.arch }} | |
| manifest: | |
| if: github.repository == 'tsuru/platforms' && github.event_name != 'pull_request' | |
| needs: publish | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - ballerina | |
| - buildpack | |
| - go | |
| - java | |
| - lua | |
| - nodejs | |
| - perl | |
| - php | |
| - python | |
| - ruby | |
| - scratch | |
| - static | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - run: | | |
| ref="${GITHUB_REF##*/}" | |
| img="tsuru/${{ matrix.platform }}" | |
| if [[ ${ref} == "master" ]] || [[ ${ref} == "main" ]]; then | |
| docker buildx imagetools create -t ${img}:latest \ | |
| ${img}:latest-amd64 \ | |
| ${img}:latest-arm64 | |
| elif [[ ${ref} =~ ^${{ matrix.platform }}-([0-9.]+)$ ]]; then | |
| version=${BASH_REMATCH[1]} | |
| docker buildx imagetools create -t ${img}:${version} \ | |
| ${img}:${version}-amd64 \ | |
| ${img}:${version}-arm64 | |
| docker buildx imagetools create -t ${img}:latest \ | |
| ${img}:latest-amd64 \ | |
| ${img}:latest-arm64 | |
| fi | |
| shell: bash |