Build Docker image with multi-arch #1108
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: Build Docker image with multi-arch | |
| on: | |
| schedule: | |
| - cron: '15 */8 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| ruby_version: | |
| required: true | |
| default: master | |
| description: '"master" or version nunmber ("3.1.2")' | |
| type: string | |
| ruby_commit_date_offset: | |
| required: false | |
| description: 'Commit date offset in days ("0")' | |
| default: 0 | |
| type: choice | |
| options: | |
| - 0 | |
| - 1 | |
| ruby_sha: | |
| required: false | |
| description: 'SHA for master ruby_version (optional)' | |
| type: string | |
| env: | |
| ruby_version: ${{ github.event.inputs.ruby_version || 'master' }} | |
| ruby_commit_date_offset: ${{ github.event.inputs.ruby_commit_date_offset || '0' }} | |
| ruby_sha: ${{ github.event.inputs.ruby_sha || '' }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| jobs: | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| debug_suffix: ['', '-debug'] | |
| dev_suffix: ['', '-dev'] | |
| ubuntu_version: | |
| - noble | |
| - jammy | |
| arch: ['amd64', 'arm64'] | |
| runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} | |
| env: | |
| push: false | |
| ubuntu_version: "${{ matrix.ubuntu_version }}" | |
| tag_suffix: "-${{ matrix.arch }}-${{ github.run_id }}" | |
| push_tags: ${{ github.event.inputs.ruby_version || 'master' }}${{ matrix.debug_suffix }}${{ matrix.dev_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }}-${{ github.run_id }} | |
| dev_suffix: ${{ matrix.dev_suffix }} | |
| debug_suffix: ${{ matrix.debug_suffix }} | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASS }} | |
| - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ secrets.GHCR_USER }} | |
| password: ${{ secrets.GHCR_ACCESS_TOKEN }} | |
| - run: | | |
| if [ "${{ env.dev_suffix }}" = "-dev" ]; then | |
| echo "target=development" >> $GITHUB_ENV | |
| else | |
| echo "target=ruby" >> $GITHUB_ENV | |
| fi | |
| if [ "${{ env.debug_suffix }}" = "-debug" ]; then | |
| echo "cppflags=-DENABLE_PATH_CHECK=0 -DRUBY_DEBUG=1" >> $GITHUB_ENV | |
| echo "optflags=-O3 -fno-inline" >> $GITHUB_ENV | |
| fi | |
| - name: Build docker image | |
| run: |- | |
| rake docker:build ruby_version=${{ env.ruby_version }} \ | |
| ubuntu_version=${{ env.ubuntu_version }} \ | |
| arch=linux/${{ matrix.arch }} \ | |
| image_version_suffix=${{ env.debug_suffix }}${{ env.dev_suffix }} \ | |
| tag_suffix=${{ env.tag_suffix }} \ | |
| optflags="${{ env.optflags }}" \ | |
| cppflags="${{ env.cppflags }}" \ | |
| target=${{ env.target }} \ | |
| - name: List images | |
| run: docker images | |
| - name: Push docker image to rubylang | |
| if: "${{ env.push_tags }}" | |
| run: |- | |
| push_tags="${{ env.push_tags }}" | |
| for tag in $push_tags; do | |
| docker push rubylang/ruby:$tag | |
| done | |
| - name: Push docker image to ghcr.io/ruby | |
| if: "${{ env.push_tags }}" | |
| run: |- | |
| push_tags="${{ env.push_tags }}" | |
| for tag in $push_tags; do | |
| docker tag rubylang/ruby:$tag ghcr.io/ruby/ruby:$tag | |
| docker push ghcr.io/ruby/ruby:$tag | |
| done | |
| - uses: ruby/action-slack@54175162371f1f7c8eb94d7c8644ee2479fcd375 # v3.2.2 | |
| with: | |
| payload: | | |
| { | |
| "attachments": [{ | |
| "text": "build ${{ job.status }}: ${{ matrix.ubuntu_version }} ${{ matrix.arch }} ${{ matrix.debug_suffix }} ${{ matrix.dev_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>", | |
| "color": "danger" | |
| }] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| if: failure() | |
| deploy_multiarch: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| registry_name: [rubylang, ghcr.io/ruby] | |
| image_version_suffix: ['', '-dev', '-debug', '-debug-dev'] | |
| ubuntu_version: | |
| - noble | |
| - jammy | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASS }} | |
| if: ${{ matrix.registry_name == 'rubylang' }} | |
| - uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ secrets.GHCR_USER }} | |
| password: ${{ secrets.GHCR_ACCESS_TOKEN }} | |
| if: ${{ matrix.registry_name == 'ghcr.io/ruby' }} | |
| # Make sure the sha of "master-{sha}" tags agrees with the RUBY_REVISION in the image | |
| - name: Extract ruby_sha | |
| run: echo "ruby_sha=$(docker run "$docker_image")" >> "$GITHUB_ENV" | |
| env: | |
| # In docker:manifest:create: | |
| # tags = ["master#{version_suffix}", ...] #=> "master${{ matrix.image_version_suffix }}" | |
| # tags.collect! {|t| "#{docker_image_name}:#{t}-#{ubuntu_version(ruby_version)}#{tag_suffix}" } #=> "${{ matrix.registry_name}}/ruby:master${{ matrix.image_version_suffix }}-${{ matrix.ubuntu_version }}" | |
| # manifest_name = "#{tags[0]}-#{arch}" #=> "${{ matrix.registry_name}}/ruby:master${{ matrix.image_version_suffix }}-${{ matrix.ubuntu_version }}-amd64" | |
| # manifest_name = "#{manifest_name}-#{manifest_suffix}" if manifest_suffix #=> "${{ matrix.registry_name}}/ruby:master${{ matrix.image_version_suffix }}-${{ matrix.ubuntu_version }}-amd64-${{ github.run_id }}" | |
| docker_image: ${{ matrix.registry_name}}/ruby:master${{ matrix.image_version_suffix }}-${{ matrix.ubuntu_version }}-amd64-${{ github.run_id }} | |
| if: ${{ (github.event.inputs.ruby_version || 'master') == 'master' && (github.event.inputs.ruby_sha || '') == '' }} | |
| - name: Create manifest for ${{ matrix.registry_name }} | |
| run: |- | |
| rake docker:manifest:create \ | |
| registry_name="${{ matrix.registry_name }}" \ | |
| ruby_version="${{ env.ruby_version }}" \ | |
| ubuntu_version="${{ matrix.ubuntu_version }}" \ | |
| architectures="amd64 arm64" \ | |
| manifest_suffix=${{ github.run_id }} \ | |
| image_version_suffix=${{ matrix.image_version_suffix }} | |
| - name: Push manifest to ${{ matrix.registry_name }} | |
| run: |- | |
| rake docker:manifest:push \ | |
| registry_name="${{ matrix.registry_name }}" \ | |
| ruby_version="${{ env.ruby_version }}" \ | |
| ubuntu_version="${{ matrix.ubuntu_version }}" \ | |
| image_version_suffix=${{ matrix.image_version_suffix }} | |
| - uses: ruby/action-slack@54175162371f1f7c8eb94d7c8644ee2479fcd375 # v3.2.2 | |
| with: | |
| payload: | | |
| { | |
| "attachments": [{ | |
| "text": "deploy_multiarch ${{ job.status }}: ${{ matrix.registry_name }} / ${{ matrix.ubuntu_version }} ${{ matrix.image_version_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>", | |
| "color": "danger" | |
| }] | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
| if: failure() |