Skip to content

Commit bc38b9f

Browse files
committed
Merge build workflow
1 parent 6dcc25f commit bc38b9f

File tree

2 files changed

+153
-238
lines changed

2 files changed

+153
-238
lines changed

.github/workflows/build.yml

Lines changed: 153 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,174 @@
1-
name: Build Docker image
1+
name: Build Docker image with multi-arch
22

33
on:
4+
schedule:
5+
- cron: '30 */12 * * *'
6+
47
repository_dispatch:
5-
types:
8+
types:
69
- build
710

811
workflow_dispatch:
912
inputs:
10-
RUBY_VERSION:
11-
description: The version of Ruby to be build
13+
ruby_version:
1214
required: true
1315
default: master
14-
ARCH:
15-
description: Which architecture amd64 or arm64 do you want to build? (The default is amd64)
16-
type: choice
17-
options:
18-
- amd64
19-
- arm64
20-
default: amd64
21-
required: true
22-
LATEST:
23-
description: Whether the latest tag should be created
24-
type: boolean
25-
default: false
26-
required: true
16+
description: '"master" or version nunmber ("3.1.2")'
2717

2818
jobs:
2919
build:
30-
name: ${{ github.event.inputs.RUBY_VERSION || github.event.client_payload.ruby_version }}-${{ matrix.ubuntu_version }}-${{ github.event.inputs.ARCH || github.event.client_payload.arch }}
31-
runs-on: ubuntu-latest
3220
strategy:
3321
fail-fast: false
3422
matrix:
3523
ubuntu_version:
3624
- noble
3725
- jammy
3826
- focal
27+
dev_suffix: [ '', '-dev' ]
28+
arch: ['amd64', 'arm64']
29+
30+
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
31+
32+
env:
33+
nightly: false
34+
push: false
35+
ubuntu_version: "${{ matrix.ubuntu_version }}"
36+
ruby_version: ${{ github.event.inputs.ruby_version || github.event.client_payload.ruby_version || 'master' }}
37+
tag_suffix: "-${{ matrix.arch }}-${{ github.sha }}"
38+
push_tags: ${{ inputs.ruby_version || 'master' }}${{ matrix.dev_suffix }}-${{ matrix.ubuntu_version }}-${{ matrix.arch }}-${{ github.sha }}
39+
dev_suffix: ${{ matrix.dev_suffix }}
40+
41+
steps:
42+
- uses: actions/[email protected]
43+
44+
- uses: docker/login-action@v3
45+
with:
46+
username: ${{ secrets.DOCKER_USER }}
47+
password: ${{ secrets.DOCKER_PASS }}
48+
49+
- uses: docker/login-action@v3
50+
with:
51+
registry: ghcr.io
52+
username: ${{ secrets.GHCR_USER }}
53+
password: ${{ secrets.GHCR_ACCESS_TOKEN }}
54+
55+
- run: |
56+
if [ "${{ env.dev_suffix }}" = "-dev" ]; then
57+
echo "target=development" >> $GITHUB_ENV
58+
echo "latest_tag=false" >> $GITHUB_ENV
59+
else
60+
echo "target=ruby" >> $GITHUB_ENV
61+
echo "latest_tag=true" >> $GITHUB_ENV
62+
fi
63+
64+
- name: Build docker image
65+
run: |-
66+
rake docker:build ruby_version=${{ env.ruby_version }} \
67+
ubuntu_version=${{ env.ubuntu_version }} \
68+
arch=linux/${{ matrix.arch }} \
69+
image_version_suffix=${{ env.dev_suffix }} \
70+
nightly=${{ env.nightly }} \
71+
tag_suffix=${{ env.tag_suffix }} \
72+
target=${{ env.target }} \
73+
latest_tag=${{ env.latest_tag }}
74+
shell: bash
75+
76+
- name: List images
77+
run: docker images
78+
shell: bash
79+
80+
- name: Push docker image to rubylang
81+
if: "${{ env.push_tags }}"
82+
run: |-
83+
push_tags="${{ env.push_tags }}"
84+
for tag in $push_tags; do
85+
docker push rubylang/ruby:$tag
86+
done
87+
shell: bash
88+
89+
- name: Push docker image to ghcr.io/ruby
90+
if: "${{ env.push_tags }}"
91+
run: |-
92+
push_tags="${{ env.push_tags }}"
93+
for tag in $push_tags; do
94+
docker tag rubylang/ruby:$tag ghcr.io/ruby/ruby:$tag
95+
docker push ghcr.io/ruby/ruby:$tag
96+
done
97+
shell: bash
98+
99+
- uses: ruby/[email protected]
100+
with:
101+
payload: |
102+
{
103+
"attachments": [{
104+
"text": "${{ job.status }}: ${{ matrix.arch }} ${{ matrix.dev_suffix }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>",
105+
"color": "danger"
106+
}]
107+
}
108+
env:
109+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
110+
if: failure()
111+
112+
deploy_multiarch:
113+
strategy:
114+
matrix:
115+
registry_name: [ rubylang, ghcr.io/ruby ]
116+
ubuntu_version:
117+
- noble
118+
- jammy
119+
- focal
120+
image_version_suffix: [ '', '-dev' ]
121+
122+
runs-on: ubuntu-latest
123+
124+
needs: build
125+
126+
env:
127+
ruby_version: ${{ github.event.inputs.ruby_version || github.event.client_payload.ruby_version || 'master' }}
39128

40129
steps:
41-
- uses: actions/checkout@v4
42-
43-
- name: Store parameters to environmental variables
44-
run: |
45-
echo "RUBY_VERSION=${{ github.event.inputs.RUBY_VERSION || github.event.client_payload.ruby_version }}" >> $GITHUB_ENV
46-
echo "ARCH=${{ github.event.inputs.ARCH || github.event.client_payload.arch }}" >> $GITHUB_ENV
47-
echo "LATEST=${{ github.event.inputs.LATEST || github.event.client_payload.latest }}" >> $GITHUB_ENV
48-
49-
- name: Show parameters
50-
run: |
51-
echo $RUBY_VERSION
52-
echo $ARCH
53-
echo $LATEST
54-
55-
- name: Build image
56-
run: |
57-
rake docker:build arch=${{ env.ARCH }} ruby_version=${{ env.RUBY_VERSION }} ubuntu_version=${{ matrix.ubuntu_version }} latest_tag=${{ env.LATEST }}
58-
59-
- name: Check image
60-
run: |
61-
docker images
62-
63-
if [[ "${{ env.ARCH }}" != "amd64" ]]; then
64-
ARCH_SUFFIX=-${{ env.ARCH }}
65-
fi
66-
docker run rubylang/ruby:${{ env.RUBY_VERSION }}-${{ matrix.ubuntu_version }}${ARCH_SUFFIX} ruby -v
67-
68-
- name: Login to DockerHub
69-
uses: docker/login-action@v3
70-
with:
71-
username: ${{ secrets.DOCKER_USER }}
72-
password: ${{ secrets.DOCKER_PASS }}
73-
74-
- name: Push images to DockerHub
75-
run: docker push rubylang/ruby --all-tags
76-
77-
- name: Renaming images
78-
run: |
79-
docker images rubylang/ruby --format='docker tag {{.Repository}}:{{.Tag}} ghcr.io/ruby/ruby:{{.Tag}}' | sh -ex
80-
81-
- name: Login GitHub Container Registry
82-
uses: docker/login-action@v3
83-
with:
84-
registry: ghcr.io
85-
username: ${{ secrets.GHCR_USER }}
86-
password: ${{ secrets.GHCR_ACCESS_TOKEN }}
87-
88-
- name: Push image to GitHub Container Registry
89-
run: docker push ghcr.io/${{ github.repository_owner }}/ruby --all-tags
130+
- uses: actions/[email protected]
131+
132+
- uses: docker/login-action@v3
133+
with:
134+
username: ${{ secrets.DOCKER_USER }}
135+
password: ${{ secrets.DOCKER_PASS }}
136+
if: ${{ matrix.registry_name == 'rubylang' }}
137+
138+
- uses: docker/login-action@v3
139+
with:
140+
registry: ghcr.io
141+
username: ${{ secrets.GHCR_USER }}
142+
password: ${{ secrets.GHCR_ACCESS_TOKEN }}
143+
if: ${{ matrix.registry_name == 'ghcr.io/ruby' }}
144+
145+
- name: Create manifest for ${{ matrix.registry_name }}
146+
run: |-
147+
rake docker:manifest:create \
148+
registry_name="${{ matrix.registry_name }}" \
149+
ruby_version="${{ env.ruby_version }}" \
150+
ubuntu_version="${{ matrix.ubuntu_version }}" \
151+
architectures="amd64 arm64" \
152+
manifest_suffix=${{ github.sha }} \
153+
image_version_suffix=${{ matrix.image_version_suffix }}
154+
155+
- name: Push manifest to ${{ matrix.registry_name }}
156+
run: |-
157+
rake docker:manifest:push \
158+
registry_name="${{ matrix.registry_name }}" \
159+
ruby_version="${{ env.ruby_version }}" \
160+
ubuntu_version="${{ matrix.ubuntu_version }}" \
161+
image_version_suffix=${{ matrix.image_version_suffix }}
162+
163+
- uses: ruby/[email protected]
164+
with:
165+
payload: |
166+
{
167+
"attachments": [{
168+
"text": "${{ job.status }}: ${{ matrix.registry_name }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>",
169+
"color": "danger"
170+
}]
171+
}
172+
env:
173+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
174+
if: failure()

0 commit comments

Comments
 (0)