diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7ce4132 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM ruby:3.1.2 + +# Set up the working directory +WORKDIR /app + +# Install dependencies +COPY Gemfile Gemfile.lock ./ +RUN bundle install + +# Copy the application code +COPY . . + +# Expose port +EXPOSE 3000 diff --git a/Gemfile.lock b/Gemfile.lock index 9e4e1b4..9f7f550 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,6 +114,9 @@ GEM nio4r (2.7.3) nokogiri (1.16.7-x64-mingw-ucrt) racc (~> 1.4) + nokogiri (1.16.7-x86_64-linux) + racc (~> 1.4) + pg (1.5.8) pg (1.5.8-x64-mingw-ucrt) puma (5.6.8) nio4r (~> 2.0) @@ -173,6 +176,7 @@ GEM PLATFORMS x64-mingw-ucrt + x86_64-linux DEPENDENCIES bcrypt (~> 3.1.7) diff --git a/app/sidekiq/delete_old_posts_job.rb b/app/sidekiq/delete_old_posts_job.rb deleted file mode 100644 index 424dd69..0000000 --- a/app/sidekiq/delete_old_posts_job.rb +++ /dev/null @@ -1,7 +0,0 @@ -class DeleteOldPostsJob - include Sidekiq::Job - - def perform(*args) - # Do something - end -end diff --git a/backup.sql b/backup.sql new file mode 100644 index 0000000..e69de29 diff --git a/config/database.yml b/config/database.yml index 63f0223..9902d15 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,88 +1,37 @@ -# PostgreSQL. Versions 9.3 and up are supported. -# -# Install the pg driver: -# gem install pg -# On macOS with Homebrew: -# gem install pg -- --with-pg-config=/usr/local/bin/pg_config -# On macOS with MacPorts: -# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config -# On Windows: -# gem install pg -# Choose the win32 build. -# Install PostgreSQL and put its /bin directory on your path. -# -# Configure Using Gemfile -# gem "pg" -# + + default: &default + + #adapter: postgresql + #encoding: unicode + #pool: 5 + #host: db #<%= ENV['DB_HOST'] || 'localhost' %> + #port: 5432 + #username: postgres + #password: 1234 adapter: postgresql encoding: unicode - # For details on connection pooling, see Rails configuration guide - # https://guides.rubyonrails.org/configuring.html#database-pooling - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: postgres - password: 1234 - host: localhost + pool: 5 + host: <%= ENV['DB_HOST'] || 'db' %> + port: <%= ENV['DB_PORT'] || 5432 %> + username: <%= ENV['DB_USERNAME'] || 'postgres' %> + password: <%= ENV['DB_PASSWORD'] || '1234' %> + development: <<: *default database: project_api_development - # The specified database role being used to connect to postgres. - # To create additional roles in postgres see `$ createuser --help`. - # When left blank, postgres will use the default role. This is - # the same name as the operating system user running Rails. - - - # The password associated with the postgres role (username). - - - # Connect on a TCP socket. Omitted by default since the client uses a - # domain socket that doesn't need configuration. Windows does not have - # domain sockets, so uncomment these lines. - - - # The TCP port the server listens on. Defaults to 5432. - # If your server runs on a different port number, change accordingly. - #port: 5432 - - # Schema search path. The server defaults to $user,public - #schema_search_path: myapp,sharedapp,public - - # Minimum log levels, in increasing order: - # debug5, debug4, debug3, debug2, debug1, - # log, notice, warning, error, fatal, and panic - # Defaults to warning. - #min_messages: notice - -# 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: <<: *default database: project_api_test -# As with config/credentials.yml, you never want to store sensitive information, -# like your database password, in your source code. If your source code is -# ever seen by anyone, they now have access to your database. -# -# Instead, provide the password or a full connection URL as an environment -# variable when you boot the app. For example: -# -# DATABASE_URL="postgres://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: project_api_production - username: project_api + #username: project_api + #password: <%= ENV["PROJECT_API_DATABASE_PASSWORD"] %> + username: <%= ENV["PROJECT_API_DATABASE_USERNAME"] %> password: <%= ENV["PROJECT_API_DATABASE_PASSWORD"] %> + diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 4b85f87..43abc29 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,3 +1,4 @@ +=begin Sidekiq.configure_server do |config| config.redis = { url: 'redis://localhost:6379/1' } end @@ -5,4 +6,13 @@ Sidekiq.configure_client do |config| config.redis = { url: 'redis://localhost:6379/1' } end - \ No newline at end of file + +=end + +Sidekiq.configure_server do |config| + config.redis = { url: 'redis://redis:6379/1' } +end + +Sidekiq.configure_client do |config| + config.redis = { url: 'redis://redis:6379/1' } +end diff --git a/db/seeds.rb b/db/seeds.rb index bc25fce..03a5a15 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). -# -# Examples: -# -# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) -# Character.create(name: "Luke", movie: movies.first) + +# db/seeds.rb +User.create(name: 'John Doe', email: 'john@example.com', password: 'password', image: 'photo.png'); +User.create(name: 'moamen', email: 'moamen@example.com', password: 'password', image: 'photo.png'); + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9de437b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ + +services: + db: + image: postgres:17rc1 # Use 'latest' or a valid version like '15' + volumes: + # - ./tmp/db:/var/lib/postgresql/data + - db_data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 1234 + POSTGRES_DB: project_api_development + + redis: + image: redis:7 + ports: + - "6379:6379" + + web: + build: + context: . + dockerfile: Dockerfile + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -b '0.0.0.0'" + volumes: + - .:/app + ports: + - "3000:3000" + environment: + DATABASE_URL: postgres://postgres:1234@db:5432/project_api_development + REDIS_URL: redis://redis:6379/1 + #new + DB_HOST: db + DB_PORT: 5432 + # + DB_USERNAME: postgres + DB_PASSWORD: 1234 + depends_on: + - db + - redis + + sidekiq: + build: + context: . + dockerfile: Dockerfile + command: bundle exec sidekiq + volumes: + - .:/app + depends_on: + - db + - redis + +volumes: + db_data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1 @@ +