Skip to content

Commit 57700e7

Browse files
committed
Speed up CI with pre-built Docker image
Move system dependency installation (Ruby, Node, imagemagick, libvips, audiowaveform, Chrome) into a custom Docker image published to GHCR. Test workflows use this image via the container: directive, eliminating 15+ minutes of setup per job. REDMINE-21261
1 parent 09c2529 commit 57700e7

File tree

3 files changed

+98
-59
lines changed

3 files changed

+98
-59
lines changed

.github/docker/Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV LANG=C.UTF-8
5+
6+
# Build dependencies for Ruby and native gem extensions
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
autoconf bison build-essential ca-certificates curl git gnupg \
9+
libffi-dev libgdbm-dev libmysqlclient-dev libncurses5-dev \
10+
libreadline-dev libssl-dev libyaml-dev software-properties-common \
11+
zlib1g-dev \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Ruby
15+
ARG RUBY_VERSION=3.4.3
16+
RUN curl -fsSL "https://cache.ruby-lang.org/pub/ruby/${RUBY_VERSION%.*}/ruby-${RUBY_VERSION}.tar.gz" | tar xz \
17+
&& cd ruby-${RUBY_VERSION} \
18+
&& ./configure --disable-install-doc \
19+
&& make -j"$(nproc)" \
20+
&& make install \
21+
&& cd .. && rm -rf ruby-${RUBY_VERSION} \
22+
&& gem update --system && gem install bundler
23+
24+
# Node.js 22
25+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
26+
&& apt-get install -y nodejs \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
# Yarn
30+
RUN corepack enable && corepack prepare yarn@1 --activate
31+
32+
# System packages for image processing and tests
33+
RUN apt-get update && apt-get install -y --no-install-recommends \
34+
imagemagick \
35+
libvips-dev \
36+
&& rm -rf /var/lib/apt/lists/*
37+
38+
# audiowaveform via PPA
39+
RUN add-apt-repository -y ppa:chris-needham/ppa \
40+
&& apt-get update \
41+
&& apt-get install -y audiowaveform \
42+
&& rm -rf /var/lib/apt/lists/*
43+
44+
# Google Chrome for JS integration tests
45+
RUN curl -fsSL https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /tmp/chrome.deb \
46+
&& apt-get update && apt-get install -y /tmp/chrome.deb \
47+
&& rm /tmp/chrome.deb && rm -rf /var/lib/apt/lists/*
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: build-test-image
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths:
7+
- .github/docker/Dockerfile
8+
schedule:
9+
# Rebuild weekly to pick up security updates
10+
- cron: '0 6 * * 1'
11+
workflow_dispatch:
12+
13+
env:
14+
IMAGE: ghcr.io/${{ github.repository }}/test
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
packages: write
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Log in to GHCR
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Build and push
33+
uses: docker/build-push-action@v6
34+
with:
35+
context: .github/docker
36+
push: true
37+
tags: |
38+
${{ env.IMAGE }}:latest
39+
${{ env.IMAGE }}:${{ github.sha }}

.github/workflows/tests.yml

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ on: [push, pull_request]
33

44
env:
55
RAILS_ENV: test
6-
PAGEFLOW_DB_HOST: 127.0.0.1
6+
PAGEFLOW_DB_HOST: mysql
77

88
jobs:
99
rspec:
1010
name: ${{ matrix.job }} (Rails ${{ matrix.rails-version }})
1111
runs-on: ubuntu-latest
12+
container: ghcr.io/${{ github.repository }}/test:latest
1213
env:
1314
PAGEFLOW_RAILS_VERSION: ${{ matrix.rails-version }}
1415

@@ -25,34 +26,29 @@ jobs:
2526
include:
2627
- job: pageflow
2728
engine-name: pageflow
28-
ruby-version: 3.4
2929
engine-directory: .
3030
rspec-command: bin/rspec --tag ~js
3131
install-audiowaveform: true
3232

3333
- job: pageflow_js
3434
engine-name: pageflow
35-
ruby-version: 3.4
3635
engine-directory: .
3736
rspec-command: bin/rspec-with-retry --tag js
3837

3938
- job: pageflow_paged
4039
engine-name: pageflow_paged
41-
ruby-version: 3.4
4240
engine-directory: entry_types/paged
4341
plugin-name: pageflow_paged
4442
rspec-command: bin/rspec
4543

4644
- job: pageflow_scrolled
4745
engine-name: pageflow_scrolled
48-
ruby-version: 3.4
4946
engine-directory: entry_types/scrolled
5047
plugin-name: pageflow_scrolled
5148
rspec-command: bin/rspec --tag ~js
5249

5350
- job: pageflow_scrolled_js
5451
engine-name: pageflow_scrolled
55-
ruby-version: 3.4
5652
engine-directory: entry_types/scrolled
5753
plugin-name: pageflow_scrolled
5854
rspec-command: bin/rspec-with-retry-on-timeout --tag js
@@ -64,7 +60,6 @@ jobs:
6460
MYSQL_ALLOW_EMPTY_PASSWORD: yes
6561
ports:
6662
- 3306:3306
67-
# Set health checks to wait until mysql has started
6863
options: >-
6964
--health-cmd="mysqladmin ping"
7065
--health-interval=10s
@@ -73,77 +68,43 @@ jobs:
7368
7469
redis:
7570
image: redis
76-
# Set health checks to wait until redis has started
7771
options: >-
7872
--health-cmd "redis-cli ping"
7973
--health-interval 10s
8074
--health-timeout 5s
8175
--health-retries 5
8276
8377
steps:
84-
- uses: actions/checkout@v2
78+
- uses: actions/checkout@v4
8579

8680
# Caching
8781

8882
- name: Set up cache for Bundler
8983
uses: actions/cache@v4
9084
with:
9185
path: vendor/bundle
92-
key: ${{ runner.os }}-ruby-${{ matrix.ruby-version }}-rails-${{ matrix.rails-version }}-gems-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
86+
key: ${{ runner.os }}-gems-rails-${{ matrix.rails-version }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
9387
restore-keys: |
94-
${{ runner.os }}-ruby-${{ matrix.ruby-version }}-rails-${{ matrix.rails-version }}-gems-
95-
96-
- name: Get yarn cache directory path
97-
id: yarn-cache-dir-path
98-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
88+
${{ runner.os }}-gems-rails-${{ matrix.rails-version }}-
9989
10090
- name: Set up cache for Yarn
10191
uses: actions/cache@v4
10292
with:
103-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
93+
path: .yarn-cache
10494
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
10595
restore-keys: |
10696
${{ runner.os }}-yarn-
10797
108-
# Ruby/Node
109-
110-
- name: Set up Ruby ${{ matrix.ruby-version }}
111-
uses: ruby/setup-ruby@v1
112-
with:
113-
ruby-version: ${{ matrix.ruby-version }}
114-
115-
- name: Use Node.js 22
116-
uses: actions/setup-node@v1
117-
with:
118-
node-version: 22
119-
12098
# Dependencies
12199

122-
- name: Install imagemagick package for image processing
123-
run: |
124-
sudo apt-get update
125-
sudo apt-get install imagemagick
126-
127-
- name: Install libvips package for image processing
128-
run: |
129-
sudo apt-get update
130-
sudo apt-get install libvips-dev
131-
132-
- name: Install audiowaveform package
133-
if: ${{ matrix.install-audiowaveform == true}}
134-
run: |
135-
sudo add-apt-repository -y ppa:chris-needham/ppa
136-
sudo apt-get update
137-
sudo apt-get install audiowaveform
138-
139100
- name: Bundle install
140101
run: |
141102
bundle config path vendor/bundle
142103
bundle install --jobs 4 --retry 3
143104
144105
- name: Yarn install
145106
run: |
146-
yarn install
107+
yarn install --cache-folder .yarn-cache
147108
148109
# Build
149110

@@ -171,6 +132,7 @@ jobs:
171132

172133
jest:
173134
runs-on: ubuntu-latest
135+
container: ghcr.io/${{ github.repository }}/test:latest
174136

175137
strategy:
176138
fail-fast: false
@@ -186,29 +148,20 @@ jobs:
186148
package-directory: entry_types/scrolled/package
187149

188150
steps:
189-
- uses: actions/checkout@v2
190-
191-
- name: Get yarn cache directory path
192-
id: yarn-cache-dir-path
193-
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
151+
- uses: actions/checkout@v4
194152

195153
- name: Set up cache for Yarn
196154
uses: actions/cache@v4
197155
with:
198-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
156+
path: .yarn-cache
199157
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
200158
restore-keys: |
201159
${{ runner.os }}-yarn-
202160
203-
- name: Set up Node.js 22
204-
uses: actions/setup-node@v1
205-
with:
206-
node-version: 22
207-
208161
- name: Yarn install
209162
run: |
210-
yarn install
211-
(cd entry_types/paged/packages/pageflow-paged-react; yarn install)
163+
yarn install --cache-folder .yarn-cache
164+
(cd entry_types/paged/packages/pageflow-paged-react; yarn install --cache-folder ../../../../.yarn-cache)
212165
213166
- name: Build packages
214167
run: |

0 commit comments

Comments
 (0)