Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved caching with Docker in CI #803

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/actions/continuous-integration/load-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Load cache
description: Loads the cached image in a post-cache continuous integration step
runs:
using: "composite"
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Load cache image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
build-args: |
RAILS_ENV=test
push: false
load: true
tags: app_test:latest
cache-from: type=gha
cache-to: type=gha,mode=min
79 changes: 70 additions & 9 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TODO: Enable GitHub Actions on the repository to test all pull requests
# https://github.com/<org>/<repo>/actions
name: CI Checks

on:
pull_request:
push:
Expand All @@ -8,18 +10,77 @@ on:
- develop

jobs:
test:
lint-and-format:
name: Lint and format application
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Load cache
uses: ./.github/actions/continuous-integration/load-cache
-
name: Run Ruby standard
run: |
docker run --rm app_test:latest /bin/bash -c "bundle exec standardrb -f simple"
-
name: Run ESLint
run: |
docker run --rm app_test:latest /bin/bash -c "yarn run lint:js"
-
name: Run Stylelint
run: |
docker run --rm app_test:latest /bin/bash -c "yarn run lint:css"
-
name: Run Prettier
run: |
docker run --rm app_test:latest /bin/bash -c "yarn run lint:format"

env:
RAILS_ENV: test

static-analysis:
name: Static analysis
runs-on: ubuntu-latest
steps:
- name: Check out code
-
name: Checkout
uses: actions/checkout@v4
-
name: Load cache
uses: ./.github/actions/continuous-integration/load-cache
-
name: Run Brakeman
run: |
docker run --rm app_test:latest /bin/bash -c "bundle exec brakeman -o /dev/stdout"

- name: Build
run: script/ci/cibuild
specs:
name: Specs and coverage
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Load cache
uses: ./.github/actions/continuous-integration/load-cache
-
name: Run RSpec and Simplecov
run: |
docker compose -p complete-app -f docker-compose.ci.yml \
run --name app_test test /bin/bash -c "bin/rails spec"
-
name: Shutdown containers
run: docker compose -p app_test down && docker compose -p app_test rm

- name: Test
run: script/ci/test
shellcheck:
name: Lint scripts
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Run Shellceck
run: |
for file in $(git ls-files script/*)
do shellcheck -x "$file"
done
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ------------------------------------------------------------------------------
# Base
# ------------------------------------------------------------------------------
FROM ruby:3.3.6 as base
FROM ruby:3.3.6 AS base
LABEL org.opencontainers.image.authors="[email protected]"

COPY .node-version .node-version
Expand All @@ -17,12 +17,12 @@ RUN \
build-essential \
libpq-dev

ENV APP_HOME /srv/app
ENV DEPS_HOME /deps
ENV APP_HOME=/srv/app
ENV DEPS_HOME=/deps

ARG RAILS_ENV
ENV RAILS_ENV ${RAILS_ENV:-production}
ENV NODE_ENV ${RAILS_ENV:-production}
ENV RAILS_ENV=${RAILS_ENV:-production}
ENV NODE_ENV=${RAILS_ENV:-production}

# ------------------------------------------------------------------------------
# Dependencies
Expand All @@ -34,7 +34,7 @@ RUN apt-get update && apt-get install -y yarn
WORKDIR ${DEPS_HOME}

# Install Ruby dependencies
ENV BUNDLE_GEM_GROUPS ${RAILS_ENV}
ENV BUNDLE_GEM_GROUPS=${RAILS_ENV}

COPY Gemfile ${DEPS_HOME}/Gemfile
COPY Gemfile.lock ${DEPS_HOME}/Gemfile.lock
Expand Down Expand Up @@ -109,8 +109,8 @@ RUN \
ARG CURRENT_GIT_SHA
ARG TIME_OF_BUILD

ENV CURRENT_GIT_SHA ${CURRENT_GIT_SHA}
ENV TIME_OF_BUILD ${TIME_OF_BUILD}
ENV CURRENT_GIT_SHA=${CURRENT_GIT_SHA}
ENV TIME_OF_BUILD=${TIME_OF_BUILD}

COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
Expand All @@ -123,7 +123,7 @@ CMD ["bundle", "exec", "rails", "server"]
# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
FROM web as test
FROM web AS test

RUN \
apt-get update && \
Expand Down
8 changes: 0 additions & 8 deletions script/ci/cibuild

This file was deleted.

12 changes: 0 additions & 12 deletions script/ci/test

This file was deleted.