Skip to content

Commit 60328e7

Browse files
FEATURE: print out compressed image sizes for amd64
Remove schedule jobs from running on forks, and remove forks from attempting to push on main update
1 parent 3792f71 commit 60328e7

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

.github/workflows/build.yml

Lines changed: 23 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,6 +34,7 @@ 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
@@ -103,8 +105,25 @@ jobs:
103105
run: |
104106
docker images discourse/base
105107
108+
- name: Print compressed summary
109+
if: github.event_name == 'pull_request' && matrix.arch == 'amd64'
110+
run: |
111+
# Push to local repo to compare sizes
112+
docker run --quiet -d --rm -p 5002:5000 registry:2
113+
sleep 5
114+
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }} localhost:5002/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
115+
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} localhost:5002/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
116+
docker push --quiet localhost:5002/base:2.0.${{ env.TIMESTAMP }}-slim-${{ matrix.arch }}
117+
docker push --quiet localhost:5002/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }}
118+
# multiarch manifest is an array of schemas - [0] is amd64, [1] is arch64: Compare amd64.
119+
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)
120+
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)
121+
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)
122+
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)
123+
echo "current slim: ${CURRENT_SLIM} release: ${CURRENT_RELEASE}. new slim: ${NEW_SLIM} release: ${NEW_RELEASE}"
124+
106125
- name: push to dockerhub
107-
if: github.ref == 'refs/heads/main'
126+
if: github.ref == 'refs/heads/main' && github.event.repo.name == 'discourse/discourse_docker'
108127
env:
109128
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
110129
run: |
@@ -115,7 +134,7 @@ jobs:
115134
docker push discourse/discourse_dev:${{ env.TIMESTAMP }}-${{ matrix.arch }}
116135
117136
- name: Push discourse/base:aarch64 image for backwards compatibility
118-
if: (github.ref == 'refs/heads/main') && (matrix.arch == 'arm64')
137+
if: (github.ref == 'refs/heads/main') && (matrix.arch == 'arm64') && (github.event.repo.name == 'discourse/discourse_docker')
119138
run: |
120139
docker tag discourse/base:2.0.${{ env.TIMESTAMP }}-main-${{ matrix.arch }} discourse/base:aarch64
121140
docker push discourse/base:aarch64
@@ -125,7 +144,7 @@ jobs:
125144
needs: [base, timestamp]
126145
env:
127146
TIMESTAMP: ${{ needs.timestamp.outputs.timestamp }}
128-
if: github.ref == 'refs/heads/main'
147+
if: github.ref == 'refs/heads/main' && github.event.repo.name == 'discourse/discourse_docker'
129148
steps:
130149
- name: create and push multiarch manifests
131150
run: |
@@ -212,7 +231,7 @@ jobs:
212231
run: |
213232
docker images discourse/discourse_test
214233
- name: push to dockerhub
215-
if: success() && (github.ref == 'refs/heads/main')
234+
if: success() && (github.ref == 'refs/heads/main') && (github.event.repo.name == 'discourse/discourse_docker')
216235
env:
217236
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
218237
run: |

0 commit comments

Comments
 (0)