Skip to content

Commit 1a89e70

Browse files
FEATURE: print out compressed image sizes for amd64
remove jobs from pushing on forks. Remove jobs from scheduled jobs from running on forks longer timeout on non discourse_docker repos
1 parent 3792f71 commit 1a89e70

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222

2323
jobs:
2424
timestamp:
25+
if: (github.event_name != 'schedule' || github.event.repo.name == 'discourse/discourse_docker')
2526
runs-on: ubuntu-latest
2627
outputs:
2728
timestamp: ${{ steps.timestamp.outputs.timestamp }}
@@ -33,15 +34,20 @@ jobs:
3334
echo "timestamp=$timestamp" >> $GITHUB_OUTPUT
3435
3536
base:
37+
if: (github.event_name != 'schedule' || github.event.repo.name == 'discourse/discourse_docker')
3638
# `unbuntu-22.04-8core` for arch amd64 non-scheduled builds
3739
# `unbuntu-22.04` for arch amd64 scheduled builds
3840
# `unbuntu-22.04-8core-arm` for arch arm64 non-scheduled builds
3941
# `unbuntu-22.04-2core-arm` for arch arm64 scheduled builds
40-
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule') && '-8core') || (( matrix.arch == 'arm64' && '-2core' ) || '') }}${{ (matrix.arch == 'arm64') && '-arm' || '' }}
42+
# `unbuntu-22.04` for forks
43+
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule' && github.event.repo.name == 'discourse/discourse_docker') && '-8core') || (( matrix.arch == 'arm64' && '-2core' ) || '') }}${{ (matrix.arch == 'arm64') && '-arm' || '' }}
4144
strategy:
4245
matrix:
4346
arch: [amd64, arm64]
44-
timeout-minutes: ${{ (github.event_name == 'schedule' && 90) || ((matrix.arch == 'arm64' && 45) || 30) }}
47+
# Do not run arm64 on forks
48+
exclude:
49+
- arch: ${{ (github.event.repo.name != 'discourse/discourse_docker') && 'arm64' }}
50+
timeout-minutes: ${{ ((github.event.repo.name != 'discourse/discourse_docker' || github.event_name == 'schedule') && 90) || ((matrix.arch == 'arm64' && 45) || 30) }}
4551
needs: timestamp
4652
env:
4753
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
@@ -103,8 +109,25 @@ jobs:
103109
run: |
104110
docker images discourse/base
105111
112+
- name: Print compressed summary
113+
if: github.event_name == 'pull_request' && matrix.arch == 'amd64'
114+
run: |
115+
# Push to local repo to compare sizes
116+
docker run --quiet -d --rm -p 5002:5000 registry:2
117+
sleep 5
118+
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} localhost:5002/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
119+
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} localhost:5002/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
120+
docker push --quiet localhost:5002/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
121+
docker push --quiet localhost:5002/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
122+
# multiarch manifest is an array of schemas - [0] is amd64, [1] is arch64: Compare amd64.
123+
CURRENT_SLIM=$(docker manifest inspect -v discourse/base:slim | jq -r '.[0].SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
124+
CURRENT_RELEASE=$(docker manifest inspect -v discourse/base:release | jq -r '.[0].SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
125+
NEW_SLIM=$(docker manifest inspect -v --insecure localhost:5002/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} | jq -r '.SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
126+
NEW_RELEASE=$(docker manifest inspect -v --insecure localhost:5002/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} | jq -r '.SchemaV2Manifest.layers[] | .size / 1024 / 1024 | .*100 | round/100' | awk '{print $0; sum+= $0}; END {print sum}' | tail -n 1)
127+
echo "current slim: ${CURRENT_SLIM} release: ${CURRENT_RELEASE}. new slim: ${NEW_SLIM} release: ${NEW_RELEASE}"
128+
106129
- name: push to dockerhub
107-
if: github.ref == 'refs/heads/main'
130+
if: github.ref == 'refs/heads/main' && github.event.repo.name == 'discourse/discourse_docker'
108131
env:
109132
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
110133
run: |
@@ -125,7 +148,7 @@ jobs:
125148
needs: [base, timestamp]
126149
env:
127150
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
128-
if: github.ref == 'refs/heads/main'
151+
if: github.ref == 'refs/heads/main' && github.event.repo.name == 'discourse/discourse_docker'
129152
steps:
130153
- name: create and push multiarch manifests
131154
run: |
@@ -180,6 +203,7 @@ jobs:
180203
docker manifest push discourse/discourse_dev:${{ env.TIMESTAMP }}
181204
docker manifest push discourse/discourse_dev:release
182205
test:
206+
if: github.event.repo.name == 'discourse/discourse_docker'
183207
runs-on: ubuntu-22.04${{ ((github.event_name != 'schedule') && '-8core') || '' }}
184208
timeout-minutes: 30
185209
needs: base

0 commit comments

Comments
 (0)