Build Docker image with multi-arch #1713
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 * * *' | |
| repository_dispatch: | |
| types: [build] | |
| 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 || github.event.client_payload.ruby_version || 'master' }} | |
| ruby_commit_date_offset: ${{ github.event.inputs.ruby_commit_date_offset || github.event.client_payload.ruby_commit_date_offset || '0' }} | |
| ruby_sha: ${{ github.event.inputs.ruby_sha || github.event.client_payload.ruby_sha || '' }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| jobs: | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| debug_suffix: ['', '-debug'] | |
| dev_suffix: ['', '-dev'] | |
| ubuntu_version: | |
| - resolute | |
| - 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 || github.event.client_payload.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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASS }} | |
| - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.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@d260b61aa817726d5bedd22dd6cc305787fa4cdd # v4.0.0 | |
| 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: | |
| - resolute | |
| - noble | |
| - jammy | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASS }} | |
| if: ${{ matrix.registry_name == 'rubylang' }} | |
| - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.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" ruby -e 'puts RUBY_REVISION')" >> "$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 || github.event.client_payload.ruby_version || 'master') == 'master' && (github.event.inputs.ruby_sha || github.event.client_payload.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@d260b61aa817726d5bedd22dd6cc305787fa4cdd # v4.0.0 | |
| 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() |