Skip to content

Commit

Permalink
Add production boot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Taucher2003 committed Jan 13, 2024
1 parent c54051c commit abc2b5c
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
pull-requests: write
packages: write

jobs:
pipeline:
Expand All @@ -24,6 +25,7 @@ jobs:
SHOW_JOB_LOGS: all
env:
GLPA_C0_GH_REF: ${{ github.ref }}
GLPA_C0_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Find existing comment
uses: peter-evans/find-comment@v2
Expand Down
63 changes: 63 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
stages:
- lint
- build
- test

include:
Expand Down Expand Up @@ -43,6 +44,20 @@ graphql_docs:
- bundle exec rake graphql:compile_docs
- git diff --exit-code

build-image:
image:
name: gcr.io/kaniko-project/executor:v1.19.2-debug # Debug Image because a shell is required for GitLab Runner
entrypoint: [ "" ]
stage: build
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"$(printf "%s:%s" "$" "${C0_GH_TOKEN}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- >-
/kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "ghcr.io/code0-tech/sagittarius/ci-builds:${CI_COMMIT_SHA}"
rspec:
extends:
- .rails
Expand Down Expand Up @@ -84,3 +99,51 @@ db:rollback-and-migrate:
- bundle exec rake db:migrate VERSION=20231203194307
- bundle exec rake db:migrate
- git diff --exit-code

boot:production-mode:
extends:
- .rails
stage: test
variables:
POSTGRES_DB: sagittarius_production
POSTGRES_USER: sagittarius
POSTGRES_PASSWORD: sagittarius
SAGITTARIUS_DATABASE_HOST: postgres
SAGITTARIUS_DATABASE_PORT: '5432'
RAILS_ENV: production
RAILS_FORCE_SSL: 'false'
BUNDLE_WITHOUT: 'development:test'
script:
- bin/rails s &
- curl --fail -sv --retry 20 --retry-delay 3 --retry-connrefused http://127.0.0.1:3000/health/liveness

boot:docker:
stage: test
image: docker:24.0.6
services:
- docker:24.0.6-dind
script:
- docker compose up -d
- >
docker run
--name sagittarius
--network sagittarius_default
--network-alias sagittarius
-e SAGITTARIUS_DATABASE_HOST=postgresql
-e SAGITTARIUS_DATABASE_PORT=5432
-e SAGITTARIUS_REDIS_HOST=redis
-e SAGITTARIUS_REDIS_PORT=6379
-e RAILS_ENV=production
ghcr.io/code0-tech/sagittarius/ci-builds:${CI_COMMIT_SHA} &
- >
docker run
--rm
--network sagittarius_default
curlimages/curl:8.5.0
curl
--fail
-sv
--retry 20
--retry-delay 3
--retry-connrefused
http://sagittarius:3000/health/liveness
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
# Make sure RUBY_VERSION matches the Ruby version in .tool-versions and Gemfile
ARG RUBY_VERSION=3.2.2
FROM ruby:$RUBY_VERSION-slim as base

Expand All @@ -11,7 +11,7 @@ WORKDIR /rails
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
BUNDLE_WITHOUT="development:test"


# Throw-away build stage to reduce size of final image
Expand All @@ -28,7 +28,17 @@ RUN bundle install && \
bundle exec bootsnap precompile --gemfile

# Copy application code
COPY . .
COPY log/ log/
COPY storage/ storage/
COPY tmp/ tmp/
COPY bin/ bin/
COPY public/ public/
COPY Rakefile Rakefile
COPY config.ru config.ru
COPY config/ config/
COPY lib/ lib/
COPY db/ db/
COPY app/ app/

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
Expand Down
3 changes: 2 additions & 1 deletion bin/docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# If running the rails server then create or migrate existing database
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
./bin/rails db:prepare
bundle exec rake db:prepare
FILTER=01_application_settings bundle exec rake db:seed_fu
fi

exec "${@}"
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get 'up' => 'rails/health#show', as: :rails_health_check
get '/health/liveness' => 'rails/health#show', as: :rails_health_check

# Defines the root path route ("/")
# root "posts#index"
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ services:
ports:
- "6380:6379"

sagittarius:
build:
dockerfile: Dockerfile
context: .
ports:
- "3000:3000"
environment:
SAGITTARIUS_DATABASE_HOST: postgresql
SAGITTARIUS_DATABASE_PORT: 5432
RAILS_FORCE_SSL: 'false'
profiles:
- sagittarius

volumes:
database:
redis:
2 changes: 2 additions & 0 deletions tooling/init-dev-db/create-production.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE sagittarius_production;
GRANT ALL ON DATABASE sagittarius_production TO sagittarius;

0 comments on commit abc2b5c

Please sign in to comment.