Skip to content

Commit 890227d

Browse files
committed
Speed up DevSH FOSS image builds
1 parent 457473f commit 890227d

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

.github/workflows/devsh-foss-image.yml

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ permissions:
1919

2020
concurrency:
2121
group: devsh-foss-image-${{ github.ref }}
22-
cancel-in-progress: false
22+
cancel-in-progress: true
2323

2424
env:
2525
IMAGE: ghcr.io/devsh-graphics-programming/rocketchat-foss
@@ -50,6 +50,22 @@ jobs:
5050
echo "IMAGE_TAG=${image_tag}" >> "${GITHUB_ENV}"
5151
echo "Publishing ${IMAGE}:${image_tag}"
5252
53+
- name: Resolve source cache key
54+
id: source
55+
run: |
56+
set -euo pipefail
57+
SOURCE_HASH=$(
58+
git ls-files \
59+
':(exclude).github/**' \
60+
':(exclude)**/*.md' \
61+
| sort \
62+
| while IFS= read -r file; do sha256sum "$file"; done \
63+
| sha256sum \
64+
| awk '{ print $1 }'
65+
)
66+
echo "hash=${SOURCE_HASH}" >> "${GITHUB_OUTPUT}"
67+
echo "Source cache key: ${SOURCE_HASH}"
68+
5369
- name: Free runner disk space
5470
run: |
5571
set -euo pipefail
@@ -58,7 +74,23 @@ jobs:
5874
docker system prune -af || true
5975
df -h
6076
77+
- name: Cache Meteor bundle
78+
id: cache-bundle
79+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
80+
with:
81+
path: /tmp/Rocket.Chat.tar.gz
82+
key: ${{ runner.os }}-${{ runner.arch }}-devsh-foss-bundle-${{ steps.source.outputs.hash }}
83+
84+
- name: Restore cached Meteor bundle
85+
if: steps.cache-bundle.outputs.cache-hit == 'true'
86+
run: |
87+
set -euo pipefail
88+
mkdir -p /tmp/dist
89+
tar -xzf /tmp/Rocket.Chat.tar.gz -C /tmp/dist
90+
du -sh /tmp/dist/bundle
91+
6192
- name: Add swap
93+
if: steps.cache-bundle.outputs.cache-hit != 'true'
6294
run: |
6395
set -euo pipefail
6496
sudo fallocate -l 8G /swapfile || sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
@@ -67,7 +99,35 @@ jobs:
6799
sudo swapon /swapfile
68100
free -h
69101
102+
- name: Cache Vite
103+
if: steps.cache-bundle.outputs.cache-hit != 'true'
104+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
105+
with:
106+
path: ./node_modules/.vite
107+
key: vite-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json') }}
108+
restore-keys: |
109+
vite-${{ runner.os }}-${{ runner.arch }}-
110+
111+
- name: Cache Meteor
112+
if: steps.cache-bundle.outputs.cache-hit != 'true'
113+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
114+
with:
115+
path: ~/.meteor
116+
key: meteor-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('apps/meteor/.meteor/release') }}
117+
restore-keys: |
118+
meteor-${{ runner.os }}-${{ runner.arch }}-
119+
120+
- name: Cache Meteor local
121+
if: steps.cache-bundle.outputs.cache-hit != 'true'
122+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
123+
with:
124+
path: ./apps/meteor/.meteor/local
125+
key: meteor-local-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('apps/meteor/.meteor/versions') }}
126+
restore-keys: |
127+
meteor-local-${{ runner.os }}-${{ runner.arch }}-
128+
70129
- name: Setup NodeJS
130+
if: steps.cache-bundle.outputs.cache-hit != 'true'
71131
uses: ./.github/actions/setup-node
72132
with:
73133
cache-modules: true
@@ -76,33 +136,63 @@ jobs:
76136
HARDENED_MODE: "0"
77137

78138
- name: Install Meteor
139+
if: steps.cache-bundle.outputs.cache-hit != 'true'
79140
run: |
80141
set -euo pipefail
142+
set +e
143+
METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor)
144+
METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET")
145+
set -e
146+
LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor
147+
if [ -e "$LAUNCHER" ]; then
148+
sudo cp "$LAUNCHER" /usr/local/bin/meteor
149+
fi
81150
command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh
82151
meteor --version
83152
153+
- name: Cache Turbo
154+
if: steps.cache-bundle.outputs.cache-hit != 'true'
155+
uses: rharkor/caching-for-turbo@00a0515f175df9fd2e15c4560144ad5fdbebb0c7 # v2.3.13
156+
84157
- name: Build shared packages
158+
if: steps.cache-bundle.outputs.cache-hit != 'true'
85159
run: yarn build
86160

87161
- name: Convert checkout to FOSS build
162+
if: steps.cache-bundle.outputs.cache-hit != 'true'
88163
run: printf 'y\n' | yarn fossify
89164

90165
- name: Build Meteor bundle
166+
if: steps.cache-bundle.outputs.cache-hit != 'true'
91167
run: yarn workspace @rocket.chat/meteor build:ci
92168

93169
- name: Reduce bundle size
170+
if: steps.cache-bundle.outputs.cache-hit != 'true'
94171
run: |
95172
set -euo pipefail
96173
find /tmp/dist/bundle -type f -name "*.d.ts" -delete
97174
find /tmp/dist/bundle/programs/server/npm/node_modules -type f -name "*.map" -delete || true
98175
find /tmp/dist/bundle/programs/web.browser -type f -name "*.map" -delete || true
99176
du -sh /tmp/dist/bundle
100177
178+
- name: Store Meteor bundle cache artifact
179+
if: steps.cache-bundle.outputs.cache-hit != 'true'
180+
run: |
181+
set -euo pipefail
182+
cd /tmp/dist
183+
tar -czf /tmp/Rocket.Chat.tar.gz bundle
184+
ls -lh /tmp/Rocket.Chat.tar.gz
185+
186+
- name: Set up Docker Buildx
187+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
188+
101189
- name: Build Docker image
102190
run: |
103191
set -euo pipefail
104192
docker buildx build \
105193
--load \
194+
--cache-from type=gha \
195+
--cache-to type=gha,mode=max \
106196
--label "org.opencontainers.image.source=https://github.com/Devsh-Graphics-Programming/Rocket.Chat" \
107197
--label "org.opencontainers.image.revision=${GITHUB_SHA}" \
108198
--tag "${IMAGE}:${IMAGE_TAG}" \

0 commit comments

Comments
 (0)