Skip to content
Snippets Groups Projects
Commit 055497b3 authored by Treadway, Ross T (UG - Computer Science)'s avatar Treadway, Ross T (UG - Computer Science)
Browse files

Implementing PostgreSQL, adding creator and invitees to model, fixing gemfile, fixing database.yml

parent 294627e1
No related branches found
No related tags found
No related merge requests found
# syntax=docker/dockerfile:1
FROM ruby:2.7.0 FROM ruby:2.7.0
RUN apt-get update -qq && apt-get install -y nodejs default-mysql-client
WORKDIR /event-service RUN apt-get update
COPY Gemfile /event-service/Gemfile RUN apt-get install -y nodejs
COPY Gemfile.lock /event-service/Gemfile.lock RUN gem install bundler -v 2.1.4
RUN apt-get install -y default-mysql-client
RUN apt-get install -y netcat
RUN apt-get install -y dos2unix
RUN echo "export PATH=\"$PATH:/usr/local/bundle/bin\"" >> ~/.bashrc
WORKDIR /app
COPY Gemfile* /app/
RUN bundle install RUN bundle install
COPY . /app
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/ COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"] RUN dos2unix /usr/bin/entrypoint.sh
EXPOSE 3000 ENTRYPOINT [ "entrypoint.sh" ]
# Configure the main process to run when running the image EXPOSE 3000
# WORKDIR /app/app
CMD ["rails", "server", "-b", "0.0.0.0"] CMD ["rails", "server", "-b", "0.0.0.0"]
...@@ -6,7 +6,7 @@ ruby '2.7.0' ...@@ -6,7 +6,7 @@ ruby '2.7.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.5' gem 'rails', '~> 6.1.5'
# Use mysql as the database for Active Record # Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5' gem 'pg'
# Use Puma as the app server # Use Puma as the app server
gem 'puma', '~> 5.0' gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
...@@ -33,8 +33,6 @@ end ...@@ -33,8 +33,6 @@ end
group :development do group :development do
gem 'listen', '~> 3.3' gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actioncable (6.1.5) actioncable (6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (>= 0.6.1) websocket-driver (>= 0.6.1)
actionmailbox (6.1.5) actionmailbox (6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
activejob (= 6.1.5) activejob (= 6.1.5.1)
activerecord (= 6.1.5) activerecord (= 6.1.5.1)
activestorage (= 6.1.5) activestorage (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
mail (>= 2.7.1) mail (>= 2.7.1)
actionmailer (6.1.5) actionmailer (6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
actionview (= 6.1.5) actionview (= 6.1.5.1)
activejob (= 6.1.5) activejob (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (6.1.5) actionpack (6.1.5.1)
actionview (= 6.1.5) actionview (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
rack (~> 2.0, >= 2.0.9) rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.5) actiontext (6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
activerecord (= 6.1.5) activerecord (= 6.1.5.1)
activestorage (= 6.1.5) activestorage (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
nokogiri (>= 1.8.5) nokogiri (>= 1.8.5)
actionview (6.1.5) actionview (6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.5) activejob (6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (6.1.5) activemodel (6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
activerecord (6.1.5) activerecord (6.1.5.1)
activemodel (= 6.1.5) activemodel (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
activestorage (6.1.5) activestorage (6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
activejob (= 6.1.5) activejob (= 6.1.5.1)
activerecord (= 6.1.5) activerecord (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
marcel (~> 1.0) marcel (~> 1.0)
mini_mime (>= 1.1.0) mini_mime (>= 1.1.0)
activesupport (6.1.5) activesupport (6.1.5.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2) i18n (>= 1.6, < 2)
minitest (>= 5.1) minitest (>= 5.1)
...@@ -75,7 +75,7 @@ GEM ...@@ -75,7 +75,7 @@ GEM
listen (3.7.1) listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3) rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10) rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.16.0) loofah (2.17.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.1) mail (2.7.1)
...@@ -83,43 +83,41 @@ GEM ...@@ -83,43 +83,41 @@ GEM
marcel (1.0.2) marcel (1.0.2)
method_source (1.0.0) method_source (1.0.0)
mini_mime (1.1.2) mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0) minitest (5.15.0)
msgpack (1.5.1) msgpack (1.5.1)
mysql2 (0.5.3)
nio4r (2.5.8) nio4r (2.5.8)
nokogiri (1.13.4) nokogiri (1.13.4-x86_64-linux)
mini_portile2 (~> 2.8.0)
racc (~> 1.4) racc (~> 1.4)
pg (1.3.5)
puma (5.6.4) puma (5.6.4)
nio4r (~> 2.0) nio4r (~> 2.0)
racc (1.6.0) racc (1.6.0)
rack (2.2.3) rack (2.2.3)
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rails (6.1.5) rails (6.1.5.1)
actioncable (= 6.1.5) actioncable (= 6.1.5.1)
actionmailbox (= 6.1.5) actionmailbox (= 6.1.5.1)
actionmailer (= 6.1.5) actionmailer (= 6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
actiontext (= 6.1.5) actiontext (= 6.1.5.1)
actionview (= 6.1.5) actionview (= 6.1.5.1)
activejob (= 6.1.5) activejob (= 6.1.5.1)
activemodel (= 6.1.5) activemodel (= 6.1.5.1)
activerecord (= 6.1.5) activerecord (= 6.1.5.1)
activestorage (= 6.1.5) activestorage (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
bundler (>= 1.15.0) bundler (>= 1.15.0)
railties (= 6.1.5) railties (= 6.1.5.1)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3) rails-dom-testing (2.0.3)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2) rails-html-sanitizer (1.4.2)
loofah (~> 2.3) loofah (~> 2.3)
railties (6.1.5) railties (6.1.5.1)
actionpack (= 6.1.5) actionpack (= 6.1.5.1)
activesupport (= 6.1.5) activesupport (= 6.1.5.1)
method_source method_source
rake (>= 12.2) rake (>= 12.2)
thor (~> 1.0) thor (~> 1.0)
...@@ -127,7 +125,6 @@ GEM ...@@ -127,7 +125,6 @@ GEM
rb-fsevent (0.11.1) rb-fsevent (0.11.1)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
spring (4.0.0)
sprockets (4.0.3) sprockets (4.0.3)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
...@@ -150,14 +147,12 @@ DEPENDENCIES ...@@ -150,14 +147,12 @@ DEPENDENCIES
bootsnap (>= 1.4.4) bootsnap (>= 1.4.4)
byebug byebug
listen (~> 3.3) listen (~> 3.3)
mysql2 (~> 0.5) pg
puma (~> 5.0) puma (~> 5.0)
rails (~> 6.1.5) rails (~> 6.1.5)
spring
tzinfo-data
RUBY VERSION RUBY VERSION
ruby 2.7.0p0 ruby 2.7.0p0
BUNDLED WITH BUNDLED WITH
2.1.2 2.1.4
...@@ -7,7 +7,6 @@ class EventsController < ApplicationController ...@@ -7,7 +7,6 @@ class EventsController < ApplicationController
render json: @events render json: @events
end end
# GET /events/1 # GET /events/1
def show def show
render json: @event render json: @event
...@@ -46,6 +45,8 @@ class EventsController < ApplicationController ...@@ -46,6 +45,8 @@ class EventsController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def event_params def event_params
params.require(:event).permit(:title, :description, :active, :createdAt, :scheduledAt) puts "lolol"
puts params["event"]
params.require(:event).permit(:title, :description, :active, :createdAt, :scheduledAt, :creator, :invitees => [])
end end
end end
# MySQL. Versions 5.5.8 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
#
default: &default
adapter: mysql2
encoding: utf8
host: db
username: root
password: group24
development: development:
<<: *default primary:
database: docker_dev adapter: postgresql
encoding: unicode
host: db_events
username: admin
password: group24
database: event_microservice
port: 5432
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: test:
<<: *default primary:
database: docker_test adapter: postgresql
encoding: unicode
# As with config/credentials.yml, you never want to store sensitive information, host: db_events
# like your database password, in your source code. If your source code is username: admin
# ever seen by anyone, they now have access to your database. password: group24
# database: event_microservice
# Instead, provide the password or a full connection URL as an environment port: 5432
# variable when you boot the app. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
<<: *default
database: event_service_production
username: event_service
password: <%= ENV['EVENT_SERVICE_DATABASE_PASSWORD'] %>
Rails.application.routes.draw do Rails.application.routes.draw do
resources :events resources :events
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get "events", to: "events#index"
get "event", to: "events#show"
post "events", to: "events#create"
put "events", to: "events#update"
delete "events", to: "events#destroy"
end end
...@@ -6,7 +6,6 @@ class CreateEvents < ActiveRecord::Migration[6.1] ...@@ -6,7 +6,6 @@ class CreateEvents < ActiveRecord::Migration[6.1]
t.boolean :active t.boolean :active
t.datetime :createdAt t.datetime :createdAt
t.datetime :scheduledAt t.datetime :scheduledAt
t.timestamps t.timestamps
end end
end end
......
class AddCreatorToEvent < ActiveRecord::Migration[6.1]
def change
add_column :events, :creator, :string
end
end
class AddInviteesToEvent < ActiveRecord::Migration[6.1]
def change
add_column :events, :invitees, :text, array: true, default: []
end
end
...@@ -10,9 +10,12 @@ ...@@ -10,9 +10,12 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_04_15_153430) do ActiveRecord::Schema.define(version: 2022_05_01_142617) do
create_table "events", charset: "utf8", force: :cascade do |t| # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "events", force: :cascade do |t|
t.string "title" t.string "title"
t.text "description" t.text "description"
t.boolean "active" t.boolean "active"
...@@ -20,6 +23,8 @@ ActiveRecord::Schema.define(version: 2022_04_15_153430) do ...@@ -20,6 +23,8 @@ ActiveRecord::Schema.define(version: 2022_04_15_153430) do
t.datetime "scheduledAt" t.datetime "scheduledAt"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.string "creator"
t.text "invitees", default: [], array: true
end end
end end
version: "3.7" version: "3.7"
services: services:
db: db_events:
image: mysql:5.7 image: postgres:latest
# volumes: # volumes:
# - db_data:/var/lib/mysql # - db_data:/var/lib/mysql
restart: always restart: always
environment: environment:
# MYSQL_DATABASE: docker POSTGRES_DB: event_microservice
MYSQL_USER: admin POSTGRES_USER: admin
MYSQL_PASSWORD: admin POSTGRES_PASSWORD: group24
MYSQL_ROOT_PASSWORD: group24
ports:
- 3308:3308
event: event:
build: . build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" image: event-service
ports: ports:
- 3000:3000 - 3003:3000
volumes: volumes:
- .:/event-service - .:/app
depends_on: depends_on:
- db - db_events
\ No newline at end of file links:
- db_events
\ No newline at end of file
#!/bin/bash #!/bin/bash
set -e set -e
# Remove a potentially pre-existing server.pid for Rails. #Remove a potentally pre-existing server.pid for Rails.
rm -f /event-service/tmp/pids/server.pid rm -f /tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile). # Sleep for 14 seconds to allow mysql db to setup and connect
exec "$@" # sleep 14
\ No newline at end of file
# Check and wait for mysql container to be setup and connected
echo "Waiting for MySQL DB connection ..."
status=$(nc -z db_events 5432; echo $?)
echo $status
while [ $status != 0 ]
do
echo "Waiting 3s ..."
sleep 3s
status=$(nc -z db_events 5432; echo $?)
echo $status
done
echo "DB is up ..."
# # Dropping existing db
# printf "\nDropping exising db ...\n"
# rake db:drop
# # Create all databases
# printf "\nCreating new databases ...\n"
# rake db:create
# # Migrate all pending db migrations
# printf "\nMigrating new databases ...\n"
# printf "[db:migrate]\n"
# rails db:migrate
# printf "[db:migrate RAILS_ENV=test]\n"
# rails db:migrate RAILS_ENV=test
# # Push seeds into database
# printf "\nPushing seeds to database ...\n"
# printf "[rake db:seed]\n"
# rake db:seed
RAILS_ENV=development rails db:environment:set
# Reseting database (dropping previous, creating and migrating fresh db)
printf "\nResetting database ...\n"
printf "[db:migrate:reset] => [db:drop]-[db:create]-[db:migrate]\n"
rails db:migrate:reset
# Pushing seeds into database
printf "\nPushing seeds to database ...\n"
printf "[db:setup] => [db:schema:load]-[db:seed]\n"
rails db:setup
printf "\n------------------------\n"
printf "Completed database setup\nStarting server ...\n"
printf "hosted on: localhost:3000\n\n"
# Then exec the containers main process (what's set as CMD in the Dockerfile).
exec "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment