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

Issue/54 git workflow #71

Merged
merged 10 commits into from
Dec 22, 2021
Merged
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
.git/
.github/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.dockeringnore present twice as .dockerfile and **/.dockerignore looks a bit inconsistent when you're not doing the same for, say, .gitignore.
More significantly Makefile missing

.gitignore
.vs
.vscode
CHANGELOG.md
Dockerfile
Makefile
README.md
deployment.yaml
log/
log/
4 changes: 2 additions & 2 deletions .github/workflows/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = [email protected]:epimorphics/github-workflows.git
branch = hmlr
commit = fb20a3a81b36a5ae584e22d51f6c228e8c98528d
parent = 2b15d8011b1a293a3acef93fa0881df9b840f25e
commit = a31bc88a431d49edea910171c3d2a53e41c58be0
parent = 1b9cb562958e89d3383b1fa54e7e94299652ef16
method = merge
cmdver = 0.4.3
4 changes: 2 additions & 2 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ The workflow should be installed into a applications repository using
git-subrepo. See https://github.com/ingydotnet/git-subrepo#installation-instructions.


To copy this subrepo into an applicaiton's repository:
To copy this subrepo into an application's repository:
```
git subrepo clone [email protected]:epimorphics/github-workflows.git .github/workflows -b hmlr
```

To update this subrepo in an applicaiton's repository:
To update this subrepo in an application's repository:
```
git subrepo pull .github/workflows
```
26 changes: 21 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
!/log/.keep
.byebug_history
.github-token
.npmrc
.tags
.yarn-integrity
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/node_modules
/public/packs
/public/packs-test
/tmp
.byebug_history
coverage
fc.json
fc_simple.json
index-names.txt
index.json
node_modules/
public/assets
tags
yarn-debug.log*
yarn-error.log



4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This app presents the landing page experience for
landregistry.data.gov.uk, including the SPARQL
Qonsole

## 1.5.6 - 2021-12-15

- (Mairead) Added deployment sub repo and assisting deployment files

## 1.5.5 - 2021-06-25

- (Joseph) Small config change to allow linking to privacy notice.
Expand Down
55 changes: 33 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
ARG ALPINE_VERSION=3.10
ARG RUBY_VERSION=2.6.6

# Defining ruby version
FROM ruby:$RUBY_VERSION-alpine
# Defines base image which builder and final stage use
FROM ruby:$RUBY_VERSION-alpine$ALPINE_VERSION as base

# Set working dir and copy app
WORKDIR /usr/src/app
COPY . .
# Change this if Gemfile.lock bundler version changes
ARG BUNDLER_VERSION=2.2.22

# Prerequisites for gems install
RUN apk add build-base \
npm \
tzdata \
git
git \
&& rm -rf /var/cache/apk/* \
&& gem install bundler:$BUNDLER_VERSION \
&& bundle config --global frozen 1

FROM base as builder

ARG BUNDLER_VERSION=2.1.4
RUN apk add --update build-base

# Install bundler and gems
RUN gem install bundler:$BUNDLER_VERSION
RUN bundle install
# Set working dir and copy app
WORKDIR /usr/src/app
COPY . .

# Params
ARG RAILS_ENV="production"
ARG RAILS_SERVE_STATIC_FILES="true"
ARG RELATIVE_URL_ROOT="/app/root"
# Install gems
RUN bundle install \
&& RAILS_ENV=production bundle exec rake assets:precompile \
&& mkdir -p 777 /usr/src/app/coverage

# Start a new build stage to minimise the final image size
FROM base

RUN addgroup -S app && adduser -S -G app app

# Set environment variables and expose the running port
ENV RAILS_ENV=$RAILS_ENV
ENV RAILS_SERVE_STATIC_FILES=$RAILS_SERVE_STATIC_FILES
ENV RELATIVE_URL_ROOT=$RELATIVE_URL_ROOT
ENV SCRIPT_NAME=$RELATIVE_URL_ROOT
EXPOSE 3000

# Precompile assets and add entrypoint script
RUN rake assets:precompile
ENTRYPOINT [ "sh", "./entrypoint.sh" ]
WORKDIR /usr/src/app

COPY --from=builder --chown=app /usr/local/bundle /usr/local/bundle
COPY --from=builder --chown=app /usr/src/app ./app

USER app

COPY entrypoint.sh /app
ENTRYPOINT [ "sh", "/app/entrypoint.sh" ]
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ GEM
nokogiri (1.12.3)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.3-x86_64-linux)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -280,6 +282,7 @@ GEM
websocket-extensions (0.1.5)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand Down
61 changes: 48 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
.PHONY: image publish
.PHONY: assets clean image lint modules publish realclean run tag test vars

ACCOUNT?=$(shell aws sts get-caller-identity | jq -r .Account)
GRP_OWNER?=epimorphics
AWS_REGION?=eu-west-1
STAGE?=dev
NAME?=$(shell awk -F: '$$1=="name" {print $$2}' deployment.yaml | sed -e 's/\s//g')
NAME?=$(shell awk -F: '$$1=="name" {print $$2}' deployment.yaml | sed -e 's/[[:blank:]]//g')
ECR?=${ACCOUNT}.dkr.ecr.eu-west-1.amazonaws.com
TAG?=$(shell if git describe > /dev/null 2>&1 ; then git describe; else git rev-parse --short HEAD; fi)
PAT?=$(shell read -p 'Github access token:' TOKEN; echo $$TOKEN)
API_SERVICE_URL?= http://localhost:8080

COMMIT=$(shell git rev-parse --short HEAD)
VERSION?=$(shell /usr/bin/env ruby -e 'require "./app/lib/version" ; puts Version::VERSION')
TAG?=${VERSION}-${COMMIT}

${TAG}:
@echo ${TAG}

IMAGE?=${NAME}/${STAGE}
REPO?=${ECR}/${IMAGE}

all: publish
GITHUB_TOKEN=.github-token
NPMRC=.npmrc
BUNDLE_CFG=${HOME}/.bundle/config
YARN_LOCK=yarn.lock

all: image

${BUNDLE_CFG}: ${GITHUB_TOKEN}
@./bin/bundle config set rubygems.pkg.github.com ${GRP_OWNER}:`cat ${GITHUB_TOKEN}`

${GITHUB_TOKEN}:
@echo ${PAT} > ${GITHUB_TOKEN}

${NPMRC}: ${GITHUB_TOKEN}
@echo "@epimorphics:registry=https://npm.pkg.github.com/" > ${NPMRC}
@echo "//npm.pkg.github.com/:_authToken=`cat ${GITHUB_TOKEN}`" >> ${NPMRC}

image: assets test
assets:
@./bin/bundle config set --local without 'development'
@./bin/bundle install
@./bin/rails assets:clean assets:precompile

auth: ${GITHUB_TOKEN} ${NPMRC} ${BUNDLE_CFG}

clean:
@[ -d public/assets ] && ./bin/rails assets:clobber || :

image: auth lint test
@echo Building ${REPO}:${TAG} ...
@docker build --tag ${REPO}:${TAG} .
@echo Done.

lint: assets
@./bin/bundle exec rubocop

modules: ${NPMRC}
@yarn install

publish: image
@echo Publishing image: ${REPO}:${TAG} ...
@docker push ${REPO}:${TAG} 2>&1
@echo Done.

assets:
@./bin/bundle config set --local without 'development'
@./bin/bundle install
@./bin/rails assets:clean assets:precompile
realclean: clean
@rm -f ${GITHUB_TOKEN} ${NPMRC} ${BUNDLE_CFG}

run:
@-docker stop lr_landing
Expand All @@ -35,11 +74,7 @@ tag:
@echo ${TAG}

test: assets
@./bin/bundle exec rubocop
@./bin/rake test

clean:
@[ -d public/assets ] && ./bin/rails assets:clobber || :

vars:
@echo "Docker: ${REPO}:${TAG}"
2 changes: 1 addition & 1 deletion app/lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module Version
MAJOR = 1
MINOR = 5
REVISION = 5
REVISION = 6
VERSION = "#{MAJOR}.#{MINOR}.#{REVISION}"
end
4 changes: 2 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'] || true

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
Expand Down Expand Up @@ -78,7 +78,7 @@

config.logger = JsonRailsLogger::Logger.new($stdout)

config.relative_url_root = ENV['RELATIVE_URL_ROOT'] || '/'
config.relative_url_root = ENV['RELATIVE_URL_ROOT'] || '/app/root'

config.accessibility_document_path = '/accessibility'
config.privacy_document_path = '/privacy'
Expand Down
3 changes: 0 additions & 3 deletions deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ deployments:
- tag: "v{ver}"
deploy: "prod"
publish: "prod"
- tag: "v{ver}-rc"
deploy: "preprod"
publish: "preprod"
- branch: "dev-infrastructure"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be just dev?

deploy: "dev"
publish: "dev"
Expand Down
11 changes: 9 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f ./tmp/pids/server.pid
mkdir -pm 1777 ./tmp

# Set the environment
if [ -z "$RAILS_ENV" ]
Expand All @@ -12,5 +17,7 @@ then
export SECRET_KEY_BASE=`./bin/rails secret`
fi

# Run the rails app
exec ./bin/rails server
export SCRIPT_NAME=${RELATIVE_URL_ROOT :- '/app/root'}

exec ./bin/rails server -e ${RAILS_ENV} -b 0.0.0.0