Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Healthchecks #39

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
49 changes: 29 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,33 @@ jobs:
- name: Clear
run: make ci-clear

# healthcheck:
# runs-on: ubuntu-latest
# needs: build
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Prepare
# run: cp ./.env.example ./.env

# - name: Download image
# uses: actions/download-artifact@v4
# with:
# name: bmstu_2024-app
# path: /tmp

# - name: Load container
# run: docker load --input /tmp/bmstu_2024-app.tar
healthcheck:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Prepare
run: cp ./.env.example ./.env

- name: Download image
uses: actions/download-artifact@v4
with:
name: bmstu_2024-app
path: /tmp

- name: Load container
run: docker load --input /tmp/bmstu_2024-app.tar

# - name: Healthcheck
# run: make ci-up-healthy
- name: Make user
run: |
adduser -D rails --shell /bin/ash
chmod 777 .

- name: Healthcheck
run: make ci-up-healthy

- name: Clear
run: make ci-clear

8 changes: 3 additions & 5 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ RUN bundle exec bootsnap precompile app/ lib/
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

RUN adduser -D rails --shell /bin/bash
RUN adduser -D rails --shell /bin/ash
RUN mkdir -p /usr/local/bundle/ruby/3.2.0/cache
RUN chown -R rails:rails \
db log storage tmp \
/usr/local/bundle/ruby/3.2.0/cache
RUN chmod -R 777 /usr/local/bundle/ruby/3.2.0/cache
RUN chown -R rails:rails storage /usr/local/bundle/ruby/3.2.0/cache
RUN chmod -R 755 /usr/local/bundle/ruby/3.2.0/cache

USER rails:rails

Expand Down
166 changes: 84 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,82 +1,84 @@
SHELL=/bin/sh

UID := $(shell id -u)
GID := $(shell id -g)

include .env
export

setup: build db-prepare

build:
bundle lock --update
npm install --package-lock-only
docker compose build

up:
docker compose up

down:
docker compose down

clear:
sudo docker compose down -v --rmi all

creds:
EDITOR='code --wait' bin/rails credentials:edit

ash:
sudo docker compose run --rm app ash

console:
sudo docker compose run --rm app bundle exec rails c

yarn:
docker compose run --rm app yarn install

bundle:
docker compose run --rm app bundle install

rubocop:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml

rubocop-verbose:
docker compose run --rm app bundle exec rubocop

rubocopA:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml -A

db-psql:
sudo docker compose run --rm app psql -d ${POSTGRES_DB} -U ${POSTGRES_USER} -W -h db

db-prepare: db-drop db-create db-migrate db-seed

db-create:
sudo docker compose run --rm app bin/rails db:create RAILS_ENV=development

db-migrate:
sudo docker compose run --rm app bin/rails db:migrate

db-rollback:
sudo docker compose run --rm app bin/rails db:rollback

db-seed:
sudo docker compose run --rm app bin/rails db:seed

db-reset:
sudo docker compose run --rm app bin/rails db:reset

db-drop:
docker compose run --rm app bin/rails db:drop

ci-build:
bundle lock --update
npm install --package-lock-only
docker compose build -q

ci-up-healthy: db-prepare
docker compose up -d --wait --wait-timeout 60

ci-rubocop: rubocop

ci-clear: clear
SHELL=/bin/sh

UID := $(shell id -u)
GID := $(shell id -g)

include .env
export

RAILS_ENV ?= development

setup: build db-prepare

build:
bundle lock --update
npm install --package-lock-only
docker compose build

up:
docker compose up

down:
docker compose down

clear:
docker compose down -v --rmi all

creds:
EDITOR='code --wait' bin/rails credentials:edit

ash:
docker compose run --rm app ash

console:
docker compose run --rm app bundle exec rails c

yarn:
docker compose run --rm app yarn install

bundle:
docker compose run --rm app bundle install

rubocop:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml

rubocop-verbose:
docker compose run --rm app bundle exec rubocop

rubocopA:
docker compose run --rm app bundle exec rubocop --config /rails/config/rubocop.yml -A

db-psql:
docker compose run --rm app psql -d ${POSTGRES_DB} -U ${POSTGRES_USER} -W -h db

db-prepare: db-drop db-create db-migrate db-seed

db-create:
docker compose run --rm app bin/rails db:create RAILS_ENV=${RAILS_ENV}

db-migrate:
docker compose run --rm app bin/rails db:migrate

db-rollback:
docker compose run --rm app bin/rails db:rollback

db-seed:
docker compose run --rm app bin/rails db:seed

db-reset:
docker compose run --rm app bin/rails db:reset

db-drop:
docker compose run --rm app bin/rails db:drop

ci-build:
docker compose build

ci-up-healthy:
export CI=
RAILS_ENV=test make db-prepare
docker compose up -d --wait --wait-timeout 60

ci-rubocop: rubocop

ci-clear: clear
5 changes: 5 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# frozen_string_literal: true

require 'active_support/core_ext/integer/time'
require 'logger'

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!

Rails.application.configure do
# if ENV['CI'].present?
# config.logger = Logger.new($stdout)
# ENV['TMPDIR'] = '/tmp'
# end
# Settings specified here will take precedence over those in config/application.rb.

# While tests run files are not watched, reloading is not necessary.
Expand Down
Loading