Skip to content

Commit

Permalink
Update containerised workflow, testing, config and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdavidhamilton committed Apr 25, 2024
1 parent 08b1d46 commit 61e8462
Show file tree
Hide file tree
Showing 32 changed files with 348 additions and 199 deletions.
3 changes: 0 additions & 3 deletions .docker-profile

This file was deleted.

32 changes: 15 additions & 17 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
.DS_Store
.bin
.git
.gitignore
.bundleignore
.bundle
.byebug_history
.rspec
tmp
.env
.git
.github
.gitignore
.yardoc
adr
config/*.key
config/credentials/*.key
coverage
doc
log
test
spec
config/deploy
node_modules
public/assets
public/packs
public/packs-test
node_modules
yarn-error.log
coverage/
/terraform/*

.env
*.log
terraform-azure
tmp
vendor
6 changes: 0 additions & 6 deletions .env.development.example

This file was deleted.

38 changes: 28 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
DATABASE_NAME=
DATABASE_USER=boilerplate_user
DATABASE_PASSWORD=
DATABASE_HOST=database
NODE_ENV=development
DATABASE_URL=postgres://postgres:password@localhost:5432/early_years_foundation_reform_production
POSTGRES_USER=
POSTGRES_PASSWORD=
RAILS_ENV=development
WEBPACKER_DEV_SERVER_HOST=0.0.0.0
FEEDBACK_URL=
SIGNUP_URL=
TRACKING_ID=
# psql client
# PGUSER=postgres
# PGPASSWORD=password
# PGHOST=localhost
# PGDATABASE=early_years_foundation_reform_production

CONTENTFUL_SPACE=
CONTENTFUL_MANAGEMENT_TOKEN=
CONTENTFUL_DELIVERY_TOKEN=
CONTENTFUL_PREVIEW_TOKEN=
CONTENTFUL_ENVIRONMENT=
CONTENTFUL_PREVIEW=

SENTRY_TOKEN=

DOMAIN=localhost:3000

DEBUG=true

NODE_ENV=production
RAILS_ENV=production

ENVIRONMENT=production

RAILS_MASTER_KEY=xxxxxxxxxxxxxxxx
RAILS_LOG_TO_STDOUT=true
13 changes: 0 additions & 13 deletions .github/workflows/azure-deploy-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push image
# - name: Build and push dependencies
# uses: docker/build-push-action@v5
# with:
# target: deps
# context: .
# push: true
# build-args: |
# BUILDKIT_INLINE_CACHE=1
# SHA=${{ github.event.pull_request.head.sha }}
# cache-from: |
# ${{ env.DOCKER_IMAGE }}:deps
# tags: ${{ env.DOCKER_IMAGE }}:deps

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
services:
postgres:
image: postgres:15.4-alpine
image: postgres:13.1-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
Expand Down
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ yarn-debug.log*
.yarn-integrity
.yarn/install-state.gz*

.env
.env.docker
.env.localhost
.env.development
.env*
*.log
/.idea
.DS_Store
/coverage
coverage

# Terraform
*.tfstate
Expand All @@ -59,3 +54,5 @@ tokens

/app/assets/builds/*
!/app/assets/builds/.keep

nscacert.pem
13 changes: 13 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
enableTelemetry: 0

nodeLinker: node-modules

supportedArchitectures:
cpu:
- x64
- arm64
libc:
- glibc
- musl
os:
- darwin
- linux

yarnPath: .yarn/releases/yarn-4.0.2.cjs
42 changes: 0 additions & 42 deletions CLAMAV.md

This file was deleted.

16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ------------------------------------------------------------
# ------------------------------------------------------------------------------
# Base - AMD64 & ARM64 compatible
# ------------------------------------------------------------
# ------------------------------------------------------------------------------
FROM ruby:3.2.2-alpine AS base

RUN apk add --no-cache --no-progress --no-check-certificate build-base less curl tzdata gcompat

ENV TZ Europe/London

# ------------------------------------------------------------
# ------------------------------------------------------------------------------
# Dependencies
# ------------------------------------------------------------
# ------------------------------------------------------------------------------
FROM base as deps

LABEL org.opencontainers.image.description "Application Dependencies"
Expand All @@ -33,22 +33,20 @@ RUN bundle config set no-cache true
RUN bundle config set without development test
RUN bundle install --no-binstubs --retry=10 --jobs=4

# ------------------------------------------------------------
# ------------------------------------------------------------------------------
# Production Stage
# ------------------------------------------------------------
# ------------------------------------------------------------------------------
FROM base AS app

LABEL org.opencontainers.image.source=https://github.com/DFE-Digital/early-years-foundation-reform
LABEL org.opencontainers.image.description "Help for Early Years Providers Rails Application"

RUN echo "Welcome to the EYFS HfEYP Application" > /etc/motd
RUN apk add --no-cache --no-progress --no-check-certificate postgresql-dev yarn openssh
RUN apk add --no-cache --no-progress --no-check-certificate postgresql-dev yarn openssh chromium
RUN echo "root:Docker!" | chpasswd && cd /etc/ssh/ && ssh-keygen -A

ENV APP_HOME /srv
ENV RAILS_ENV ${RAILS_ENV:-production}
ENV GOVUK_APP_DOMAIN www.gov.uk
ENV GOVUK_WEBSITE_ROOT https://www.gov.uk
ENV AUTHORIZED_HOSTS 127.0.0.1
ENV IGNORE_SECRETS_FOR_BUILD=1

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ group :development, :test do
gem 'dotenv-rails'
gem 'factory_bot_rails'
gem 'faker'
gem 'foreman'
gem 'pry-byebug'
gem 'rspec'
gem 'rspec-expectations'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ GEM
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
foreman (0.88.1)
globalid (1.2.1)
activesupport (>= 6.1)
govuk-components (4.1.2)
Expand Down Expand Up @@ -551,6 +552,7 @@ DEPENDENCIES
dry-types
factory_bot_rails
faker
foreman
govuk-components
govuk_design_system_formbuilder
govuk_markdown
Expand Down
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
web: bin/rails server -b 0.0.0.0 -p 3000
css: yarn build:css --watch
js: yarn build --watch
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ doctype html
html.govuk-template lang='en'
head
title= [t('service.name'), yield(:page_title).presence].compact.join(' : ')
= csrf_meta_tags
= csrf_meta_tags
= csp_meta_tag

= tag.meta content: 'text/html; charset=UTF-8', 'http-equiv': 'Content-Type'
Expand Down
12 changes: 2 additions & 10 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

if ! gem list foreman -i --silent; then
echo "Installing foreman..."
gem install foreman
fi

# Default to port 3000 if not specified
export PORT="${PORT:-3000}"

exec foreman start -f Procfile.dev "$@"
bundle exec foreman start -f Procfile.dev
14 changes: 14 additions & 0 deletions bin/docker-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
#
# Builds and tags all project images
# Force a rebuild using `./bin/docker-build --no-cache`
# ------------------------------------------------------------------------------
set -e

for env in dev test; do
docker-compose \
-f docker-compose.yml \
-f docker-compose.$env.yml \
--project-name reform \
build "$@"
done
11 changes: 11 additions & 0 deletions bin/docker-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
set -e

docker-compose \
-f docker-compose.yml \
-f docker-compose.dev.yml \
--project-name reform \
up --detach app

docker attach reform_dev
13 changes: 13 additions & 0 deletions bin/docker-down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
#
# Take down all project services.
# ------------------------------------------------------------------------------
set -e

for env in dev test; do
docker-compose \
-f docker-compose.yml \
-f docker-compose.$env.yml \
--project-name reform \
down --remove-orphans
done
19 changes: 19 additions & 0 deletions bin/docker-rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
#
# ------------------------------------------------------------------------------
set -e

if docker container ls | grep reform_dev; then
echo "Already running development container"
docker exec -it reform_dev rails "$@"
else
echo "Starting development container"
docker-compose \
-f docker-compose.yml \
-f docker-compose.dev.yml \
--project-name reform \
run \
--name reform_rails \
--rm app \
rails "$@"
fi
18 changes: 18 additions & 0 deletions bin/docker-rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# If the working directory is not mounted as a volume, then the test environment
# RAILS_MASTER_KEY variable must be passed in.
#
# This behaviour is used in a GitHub workflow, however this script adds the mount
#
set -e

docker-compose \
-f docker-compose.yml \
-f docker-compose.test.yml \
--project-name reform \
run \
--volume="$PWD:/srv" \
--name reform_rspec \
--rm app \
rspec "$@"
Loading

0 comments on commit 61e8462

Please sign in to comment.