Skip to content

Commit

Permalink
try new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
croyfish committed Nov 15, 2024
1 parent c9645fb commit f48f9ae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
# Ignore files in the data/private subdirectory
/data/private

# Ignore postgresql data from the local environment
/data/postgres-my-library-nyc-app

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
Expand Down
5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Set base image and working directory
FROM ruby:3.3

# Use baseimage-docker's init process.
RUN mkdir -p /etc/my_init.d
ADD ./provisioning/docker_build/00-create-databases.sh /etc/my_init.d/00-create-databases.sh
CMD ["/sbin/my_init"]

# Install necessary packages, including curl and PostgreSQL client
RUN apt-get update -qq && apt-get install -y \
curl \
Expand Down
18 changes: 11 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
build:
context: .
ports:
- "3000:3000"
- '3000:3000'
environment:
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
Expand All @@ -13,27 +13,31 @@ services:
depends_on:
- postgres
- elasticsearch
command: >
bash -c "
RAILS_ENV=test bundle exec rake db:set_up_for_local;
RAILS_ENV=development bundle exec rake db:set_up_for_local;
bundle exec rails server -b 0.0.0.0
"
postgres:
image: postgres:13
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- pgdata:/var/lib/postgresql/data
- './data/postgres-my-library-nyc-app:/var/lib/postgresql/data'
ports:
- "5432:5432"
- '5432:5432'

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
environment:
- discovery.type=single-node
ports:
- "9200:9200"
- '9200:9200'
volumes:
- esdata:/usr/share/elasticsearch/data
- 'esdata:/usr/share/elasticsearch/data'

volumes:
pgdata:
esdata:

16 changes: 16 additions & 0 deletions lib/tasks/db_set_up_for_local.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace :db do
desc "Setup the database if it doesn't exist"
task set_up_for_local: :environment do
env = ENV['RAILS_ENV'] || 'development'

if ActiveRecord::Base.connection.database_exists?
puts "#{env.capitalize} database already exists"
else
puts "Setting up #{env} database..."
Rake::Task["db:create"].invoke
Rake::Task["db:schema:load"].invoke
Rake::Task["db:seed"].invoke if env == 'development'
end
end
end

3 changes: 0 additions & 3 deletions provisioning/docker_build/00-create-databases.sh

This file was deleted.

0 comments on commit f48f9ae

Please sign in to comment.