Skip to content

Commit

Permalink
feat(running-locally-docker): setup for easier running locally via Do…
Browse files Browse the repository at this point in the history
…cker
  • Loading branch information
phungmanhcuong committed Oct 31, 2024
1 parent 99be9e9 commit 7896899
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
NVM = $(HOME)/.nvm/nvm.sh

SHELL := /bin/zsh
.SHELLFLAGS := -i -c
RUBY_VERSION := 3.3.5
RAILS_VERSION := 7.2.1
NODE_VERSION := v18

clean:
# Bring down the databases
docker compose down
# Start the databases, and wait for them to be ready
docker compose up -d && sleep 5
# Remove generated files
find . -name "node_modules" | xargs -I {} rm -rf {}
# Drop existing databases
psql -c 'DROP DATABASE IF EXISTS coursemology;'
psql -c 'DROP DATABASE IF EXISTS coursemology_test;'
psql -c 'DROP DATABASE IF EXISTS coursemology_keycloak;'
psql -c 'CREATE DATABASE coursemology;'
psql -c 'CREATE DATABASE coursemology_test;'
psql -c 'CREATE DATABASE coursemology_keycloak;'

check-system-requirements:
@echo "Checking system requirements..."
@ruby -v | grep -q '$(RUBY_VERSION)' || (echo "Ruby version must be $(RUBY_VERSION)" && exit 1)
@rails -v | grep -q '$(RAILS_VERSION)' || (echo "Rails version must be $(RAILS_VERSION)" && exit 1)
@node -v | grep -q '$(NODE_VERSION)' || (echo "Node.js version must be $(NODE_VERSION) LTS" && exit 1)
@yarn -v || (echo "Yarn must be installed" && exit 1)
@docker -v || (echo "Docker must be installed" && exit 1)
@redis-server -v || (echo "Redis must be installed" && exit 1)
@echo "All system requirements are met."

prepare:
git submodule update --init --recursive
gem install bundler:2.5.9
bundle config set --local without 'ci:production'
bundle install
cp env .env
cp client/env client/.env

authentication-starting:
cp authentication/env authentication/.env
cd authentication && docker compose up --build

db-setup:
bundle exec rake db:setup

client-starting:
cp client/env client/.env
$(NVM) use 18.17
cd client && yarn && yarn build:development

backend-starting:
cp env .env
bundle exec rails s -p 3000


21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.8'

services:
redis:
image: redis:latest
container_name: redis
ports:
- "6379:6379"

postgres:
image: postgres:16.1
container_name: postgres
ports:
- "5432:5432"
environment:
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:

0 comments on commit 7896899

Please sign in to comment.