Skip to content

Commit

Permalink
Merge pull request #2424 from UKGovernmentBEIS/chore/update-ci
Browse files Browse the repository at this point in the history
Update CI
  • Loading branch information
mec authored Nov 21, 2024
2 parents 81e5c87 + ae4f29d commit 8561560
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 50 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build_and_cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build and cache
description: |
Builds the Docker image, caches layers to the Github action cache
and loads the built image into Docker"
runs:
using: "composite"
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and cache
uses: docker/build-push-action@v6
with:
context: .
build-args: |
RAILS_ENV=test
push: false
load: true
tags: app_test:latest
cache-from: type=gha
cache-to: type=gha,mode=min
60 changes: 60 additions & 0 deletions .github/workflows/ci_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI Checks

on:
push:

jobs:
lint-and-format:
name: Linting and formatting
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Build and cache
uses: ./.github/workflows/build_and_cache
-
name: Run Standard Ruby
run: |
docker run --rm app_test:latest /bin/bash -c "bundle exec standardrb -f simple"
-
name: Run Shellcheck
run: |
for file in $(git ls-files script/*)
do shellcheck -x "$file"
done
static-analysis:
name: Static analysis
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Build and cache
uses: ./.github/workflows/build_and_cache
-
name: Run Brakeman
run: |
docker run --rm app_test:latest /bin/bash -c "bundle exec brakeman -o /dev/stdout"
specs:
name: Specs and coverage
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Build and cache
uses: ./.github/workflows/build_and_cache
-
name: Run Rspec and Simplebcov
run: |
docker compose -p app_test -f docker-compose.ci.yml \
run --name app_test test /bin/bash -c "bin/rspec --format=documentation"
-
name: Shutdown containers
run: docker compose -p app_test down && docker compose -p app_test rm
44 changes: 22 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
# base
# ------------------------------------------------------------------------------
FROM ruby:3.1.2 AS base
MAINTAINER dxw <[email protected]>

ARG RAILS_ENV
ARG NODE_MAJOR

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

ENV NODE_MAJOR ${NODE_MAJOR:-16}
ENV RAILS_ENV ${RAILS_ENV:-production}
ENV NODE_ENV ${RAILS_ENV:-production}
ENV NODE_MAJOR=${NODE_MAJOR:-16}
ENV RAILS_ENV=${RAILS_ENV:-production}
ENV NODE_ENV=${RAILS_ENV:-production}

# Setup Node installation
# https://github.com/nodesource/distributions#installation-instructions
Expand Down Expand Up @@ -40,6 +39,23 @@ RUN apt-get update && apt-get install -qq -y \
yarn \
--fix-missing --no-install-recommends

# Install Firefox and Gecko driver if RAILS_ENV=test
RUN \
if [ "${RAILS_ENV}" = "test" ]; then \
apt-get install -qq -y --fix-missing firefox-esr shellcheck; \
fi

ARG gecko_driver_version=0.31.0

RUN \
if [ "${RAILS_ENV}" = "test" ]; then \
wget https://github.com/mozilla/geckodriver/releases/download/v$gecko_driver_version/geckodriver-v$gecko_driver_version-linux64.tar.gz && \
tar -xvzf geckodriver-v$gecko_driver_version-linux64.tar.gz && \
rm geckodriver-v$gecko_driver_version-linux64.tar.gz && \
chmod +x geckodriver && \
mv geckodriver* /usr/local/bin; \
fi

RUN echo "\nexport PATH=/usr/local/bin:\$PATH\n\n# Stop here if non-interactive shell\n[[ \$- == *i* ]] || return\n\ncd /app" >> ~/.bashrc

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -124,19 +140,3 @@ ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 3000

CMD ["bundle", "exec", "puma"]

# ------------------------------------------------------------------------------
# test
# ------------------------------------------------------------------------------
FROM web as test

RUN apt-get install -qq -y --fix-missing firefox-esr \
shellcheck

ARG gecko_driver_version=0.31.0

RUN wget https://github.com/mozilla/geckodriver/releases/download/v$gecko_driver_version/geckodriver-v$gecko_driver_version-linux64.tar.gz
RUN tar -xvzf geckodriver-v$gecko_driver_version-linux64.tar.gz
RUN rm geckodriver-v$gecko_driver_version-linux64.tar.gz
RUN chmod +x geckodriver
RUN mv geckodriver* /usr/local/bin
14 changes: 2 additions & 12 deletions docker-compose.test.yml → docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
version: "3.7"
services:
test:
build:
cache_from:
- beis-report-official-development-assistance_test:latest
context: .
target: test
args:
RAILS_ENV: test
volumes:
- type: bind
source: ./coverage
target: /app/coverage
cache_from:
- app_test:latest
depends_on:
- db
environment:
Expand All @@ -21,9 +15,5 @@ services:
- .env.test
db:
image: postgres:13
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
volumes:
db-data:
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions lib/tasks/shellcheck.rake

This file was deleted.

4 changes: 2 additions & 2 deletions script/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

docker compose -f docker-compose.test.yml build
docker compose -f docker-compose.test.yml run \
docker compose -f docker-compose.ci.yml build
docker compose -f docker-compose.ci.yml run \
-e CI=true \
-e COVERALLS_REPO_TOKEN="$COVERALLS_REPO_TOKEN" \
test script/test
4 changes: 2 additions & 2 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set -e

if [ -z "$CI" ] && [ "$DB_DROP_RESULT" -ne "0" ]; then
printf "\\nDatabase drop failed. Continue anyway? [y/N] "
read -r
read -r REPLY

case $REPLY in
y | Y)
Expand All @@ -50,7 +50,7 @@ set -e

if [ -z "$CI" ] && [ "$DB_DROP_RESULT" -ne "0" ]; then
printf "\\nDatabase drop failed. Continue anyway? [y/N] "
read -r
read -r REPLY

case $REPLY in
y | Y)
Expand Down
4 changes: 3 additions & 1 deletion script/test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ else
fi

echo "==> Linting our shellscripts"
bundle exec rake shellcheck
for file in $(git ls-files script/*)
do shellcheck -x "$file"
done

echo "==> Running Brakeman"
bundle exec brakeman
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# TODO: tasks have very low coverage, we should decide what our stance on this is and leave them here
# or add coverage
add_filter "/lib/tasks"
# Ignore the 'scripts' that have been written in Ruby with no tests
add_filter "/lib/scripts"
end

require "webmock/rspec"
Expand Down

0 comments on commit 8561560

Please sign in to comment.