Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Save/Load CI docker image from cache (#14211)

Cyril Rohrdfc5448d72a5
diff --git a/.github/workflows/test-core.yml b/.github/workflows/test-core.yml
index 831989b4b78..a7694c6c132 100644
--- a/.github/workflows/test-core.yml
+++ b/.github/workflows/test-core.yml
@@ -34,6 +34,18 @@ jobs:
CAPYBARA_AWS_SECRET_ACCESS_KEY: "${{ secrets.CAPYBARA_AWS_SECRET_ACCESS_KEY }}"
steps:
- uses: actions/checkout@v4
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+ - name: Cache DOCKER
+ id: cache_docker
+ uses: actions/cache@v3
+ with:
+ path: cache/docker
+ key: ${{ runner.os }}-docker-ci-${{ hashFiles('docker-compose.ci.yml', 'docker/ci/*', '.ruby-version', 'bin/ci') }}
+ # Note: no restore keys since whenever the above files change, we want to rebuild the full image from scratch
+ - name: Restore CI image from cache
+ if: steps.cache_docker.outputs.cache-hit == 'true'
+ run: docker load -i cache/docker/image.tar
- name: Cache GEM
uses: actions/cache@v3
with:
@@ -71,6 +83,9 @@ jobs:
run: bin/ci run-units
- name: Feature tests
run: bin/ci run-features
+ - name: Save CI image to cache
+ if: steps.cache_docker.outputs.cache-hit != 'true'
+ run: mkdir -p cache/docker && docker save openproject/ci:v1 -o cache/docker/image.tar
- name: Cleanup
if: ${{ always() }}
run: |
diff --git a/bin/ci b/bin/ci
index 4b11f4a3b84..ad9503b80f3 100755
--- a/bin/ci
+++ b/bin/ci
@@ -9,10 +9,10 @@ export COMPOSE_FILE=docker-compose.ci.yml
export RUBY_VERSION="$(cat .ruby-version)"
export LOCAL_CACHE_PATH="./cache"
-mkdir -p $LOCAL_CACHE_PATH/{bundle,npm,angular,runtime-logs}
+mkdir -p $LOCAL_CACHE_PATH/{bundle,npm,angular,runtime-logs,buildx}
if [ "$1" = "down" ]; then
exec docker compose down --remove-orphans --volumes
else
- exec docker compose run --rm --remove-orphans --build ci "$@"
+ exec docker compose run --rm --remove-orphans app "$@"
fi
\ No newline at end of file
diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml
index db96aaa7ad7..b777cd8c02e 100644
--- a/docker-compose.ci.yml
+++ b/docker-compose.ci.yml
@@ -1,19 +1,10 @@
-version: "3.7"
-
-networks:
- testing:
name: "openproject-ci"
services:
- db:
- image: postgres:13
- tmpfs:
- - /var/lib/postgresql/data
- command: "-c autovacuum=off -c fsync=off -c synchronous_commit=off -c checkpoint_timeout=30min -c full_page_writes=off -c deadlock_timeout=5s -c track_activities=off -c track_counts=off -c max_connections=200 -c shared_buffers=8GB -c work_mem=10485kB -c min_wal_size=1GB -c max_wal_size=4GB -c max_worker_processes=16 -c max_parallel_workers=16"
- environment:
- POSTGRES_PASSWORD: p4ssw0rd
- ci:
+ # Note: not using a database container since it adds 1min to pull and start it on CI
+ app:
+ image: openproject/ci:v1
build:
context: .
dockerfile: ./docker/ci/Dockerfile
@@ -21,16 +12,15 @@ services:
- APP_USER_UID
- APP_USER_GID
- RUBY_VERSION
+ cache_from: ["type=local,src=${LOCAL_CACHE_PATH}/buildx"]
+ cache_to: ["type=local,dest=${LOCAL_CACHE_PATH}/buildx"]
environment:
CI_JOBS: "${CI_JOBS}"
RSPEC_RETRY_RETRY_COUNT: "${CI_RETRY_COUNT:-3}"
CAPYBARA_AWS_ACCESS_KEY_ID: "${CAPYBARA_AWS_ACCESS_KEY_ID}"
CAPYBARA_AWS_SECRET_ACCESS_KEY: "${CAPYBARA_AWS_SECRET_ACCESS_KEY}"
- PGHOST: db
tmpfs:
- "/tmp"
- depends_on:
- - db
volumes:
- .:/app
- ${LOCAL_CACHE_PATH}/bundle:/usr/local/bundle
diff --git a/docker/ci/Dockerfile b/docker/ci/Dockerfile
index 321462ab7cb..d5009f563b1 100644
--- a/docker/ci/Dockerfile
+++ b/docker/ci/Dockerfile
@@ -7,10 +7,14 @@ ENV BUNDLER_VERSION="2.4.21"
ENV DEBIAN_FRONTEND=noninteractive
ENV BUNDLE_WITHOUT="development:production:docker"
-RUN apt-get update -qq && apt-get install -y postgresql-client time imagemagick default-jre-headless firefox-esr
+ENV PGVERSION=13
+RUN wget --quiet -O- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
+ echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list
ENV CHROME_SOURCE_URL="https://dl.google.com/dl/linux/direct/google-chrome-stable_current_amd64.deb"
-RUN f="/tmp/chrome.deb"; wget --no-verbose -O $f $CHROME_SOURCE_URL && apt install -y $f && rm -f $f
+RUN --mount=type=cache,target=/var/cache/apt export f="/tmp/chrome.deb" && wget --no-verbose -O $f $CHROME_SOURCE_URL && \
+ apt-get update -qq && apt-get install -y "$f" postgresql-$PGVERSION postgresql-client-$PGVERSION time imagemagick default-jre-headless firefox-esr && \
+ rm -f "$f" && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -L https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz -o - | tar xJf - -C /usr/local --strip=1 && node --version
@@ -21,9 +25,9 @@ ENV APP_PATH=/app
ARG APP_USER_UID
ARG APP_USER_GID
-RUN groupadd --force --gid $APP_USER_GID $APP_USER
-RUN useradd -d $APP_PATH -m $APP_USER -s /bin/bash --uid $APP_USER_UID --gid $APP_USER_GID
-RUN chown -R $APP_USER:$APP_USER /usr/local/bundle
+RUN groupadd --force --gid $APP_USER_GID $APP_USER && \
+ useradd -d $APP_PATH -m $APP_USER -s /bin/bash --uid $APP_USER_UID --gid $APP_USER_GID && \
+ chown -R $APP_USER:$APP_USER /usr/local/bundle
ENV CI=true
ENV RAILS_ENV=test
diff --git a/docker/ci/database.yml b/docker/ci/database.yml
index 98db2dd2bd8..6a8272ff569 100644
--- a/docker/ci/database.yml
+++ b/docker/ci/database.yml
@@ -1,2 +1,2 @@
test:
- url: <%= ENV['DATABASE_URL'].sub(/\/postgres$/, "/appdb#{ENV['TEST_ENV_NUMBER']}") %>
+ url: <%= ENV['DATABASE_URL'].sub(/\/appdb$/, "/appdb#{ENV['TEST_ENV_NUMBER']}") %>
diff --git a/docker/ci/entrypoint.sh b/docker/ci/entrypoint.sh
index 3f6e9701cf1..e04a3627c3d 100755
--- a/docker/ci/entrypoint.sh
+++ b/docker/ci/entrypoint.sh
@@ -9,10 +9,10 @@ export PARALLEL_TEST_FIRST_IS_1=true
export DISABLE_DATABASE_ENVIRONMENT_CHECK=1
# export NODE_OPTIONS="--max-old-space-size=8192"
export LOG_FILE=/tmp/op-output.log
-export PGUSER=${PGUSER:=postgres}
-export PGHOST=${PGHOST:=localhost}
+export PGUSER=${PGUSER:=appuser}
+export PGHOST=${PGHOST:=127.0.0.1}
export PGPASSWORD=${PGPASSWORD:=p4ssw0rd}
-export DATABASE_URL="postgres://$PGUSER:$PGPASSWORD@$PGHOST/postgres"
+export DATABASE_URL="postgres://$PGUSER:$PGPASSWORD@$PGHOST/appdb"
run_psql() {
psql -v ON_ERROR_STOP=1 "$@"
@@ -45,8 +45,16 @@ execute_quiet() {
return 0
fi
}
+create_db_cluster() {
+ if [ ! -d "/tmp/nulldb" ]; then
+ execute_quiet "initdb -E UTF8 -D /tmp/nulldb -U $PGUSER"
+ execute_quiet "cp docker/ci/postgresql.conf /tmp/nulldb/"
+ execute_quiet "pg_ctl -D /tmp/nulldb -l /dev/null -w start"
+ fi
+}
reset_dbs() {
+ create_db_cluster
# must reset main db because for some reason the users table is not empty, after running db:migrate
execute_quiet "echo 'drop database if exists appdb ; create database appdb' | run_psql -d postgres"
execute_quiet "cat db/structure.sql | run_psql -d appdb"
@@ -71,12 +79,13 @@ setup_tests() {
execute_quiet "rm -rf '$folder' ; mkdir -p '$folder' ; chmod 1777 '$folder'"
done
- execute_quiet "cp docker/ci/database.yml config/"
execute_quiet "mkdir -p spec/support/runtime-logs/"
execute "BUNDLE_JOBS=4 bundle install"
execute_quiet "bundle clean --force"
+ create_db_cluster
+ execute_quiet "cp docker/ci/database.yml config/"
# create test database "app" and dump schema because db/structure.sql is not checked in
execute_quiet "time bundle exec rails db:create db:migrate db:schema:dump zeitwerk:check"