Skip to content

Commit a0b9bc8

Browse files
authored
Merge pull request #13 from AMosa3d/task/CU-3d899qn_The-system-should-be-containerized
dockerizing the app
2 parents 872b8db + 8cb194e commit a0b9bc8

File tree

7 files changed

+113
-10
lines changed

7 files changed

+113
-10
lines changed

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ruby:3.0.2
2+
RUN apt-get update && apt-get install -y build-essential
3+
RUN apt-get install -y redis-server
4+
RUN apt-get install -y cron
5+
6+
RUN mkdir /app
7+
WORKDIR /app
8+
COPY Gemfile /app/Gemfile
9+
COPY Gemfile.lock /app/Gemfile.lock
10+
RUN bundle install
11+
12+
# Add a script to be executed every time the container starts.
13+
COPY init_app.sh /usr/bin/
14+
RUN chmod +x /usr/bin/init_app.sh
15+
ENTRYPOINT ["init_app.sh"]
16+
EXPOSE 3000
17+
18+
# Configure the main process to run when running the image
19+
CMD ["rails", "server", "-b", "0.0.0.0"]

config/database.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ default: &default
88
adapter: mysql2
99
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
1010
timeout: 5000
11-
username: instabugUser
12-
password: mysql-db-password
11+
username: root
12+
password: pswd
1313
port: 3306
14+
host: mysql
1415

1516
development:
1617
<<: *default

config/initializers/elasticsearch.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
require 'elasticsearch/model'
22

3-
Elasticsearch::Model.client = Elasticsearch::Client.new url: 'https://localhost:9200',
4-
user: 'elastic',
5-
password: '1MagbcdA9zrtRQKRSbro',
6-
log:true,
7-
transport_options: { ssl: { verify: false }, request: { timeout: 30} }
3+
Elasticsearch::Model.client = Elasticsearch::Client.new url: 'http://elasticsearch:9200'

config/initializers/sidekiq.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Sidekiq.configure_server do |config|
3+
config.redis = { url: "redis://redis:6379" }
4+
5+
config.on(:startup) do
6+
Sidekiq::Cron::Job.load_from_hash YAML.load_file("config/schedule.yml")
7+
Sidekiq::Scheduler.reload_schedule!
8+
end
9+
end
10+
11+
Sidekiq.configure_client do |config|
12+
config.redis = { url: "redis://redis:6379" }
13+
end

db/schema.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# It's strongly recommended that you check this file into your version control system.
1212

1313
ActiveRecord::Schema[7.0].define(version: 2022_09_03_052718) do
14-
create_table "applications", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
14+
create_table "applications", charset: "latin1", force: :cascade do |t|
1515
t.string "name", null: false
1616
t.string "token", null: false
1717
t.datetime "created_at", null: false
@@ -20,7 +20,7 @@
2020
t.index ["token"], name: "index_applications_on_token", unique: true
2121
end
2222

23-
create_table "chats", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
23+
create_table "chats", charset: "latin1", force: :cascade do |t|
2424
t.string "name", null: false
2525
t.integer "number", null: false
2626
t.integer "messages_count", default: 0, null: false
@@ -31,7 +31,7 @@
3131
t.index ["number", "application_id"], name: "index_chats_on_number_and_application_id", unique: true
3232
end
3333

34-
create_table "messages", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
34+
create_table "messages", charset: "latin1", force: :cascade do |t|
3535
t.string "body", null: false
3636
t.integer "number", null: false
3737
t.bigint "chat_id", null: false

docker-compose.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
version: "3.9"
2+
services:
3+
mysql:
4+
image: 'mysql:5.7'
5+
environment:
6+
MYSQL_ROOT_PASSWORD: pswd
7+
MYSQL_DATABASE: instabug_challenge_dev
8+
volumes:
9+
- db_data:/var/lib/mysql/
10+
ports:
11+
- "3306:3306"
12+
expose:
13+
- 3306
14+
networks:
15+
- default
16+
17+
redis:
18+
image: redis
19+
command: bash -c "redis-server"
20+
environment:
21+
REDIS_URL: redis://0.0.0.0:6379/0
22+
ports:
23+
- "6379:6379"
24+
volumes:
25+
- redis:/var/lib/redis/data
26+
27+
app:
28+
build: .
29+
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
30+
volumes:
31+
- '.:/app'
32+
ports:
33+
- "3000:3000"
34+
depends_on:
35+
- mysql
36+
links:
37+
- mysql:mysql
38+
39+
sidekiq:
40+
build: .
41+
command: bash -c "bundle exec sidekiq restart"
42+
volumes:
43+
- '.:/app'
44+
depends_on:
45+
- redis
46+
- app
47+
networks:
48+
- default
49+
50+
elastic:
51+
image: elasticsearch:8.4.0
52+
ports:
53+
- "9200:9200"
54+
volumes:
55+
- elastic:/usr/share/elasticsearch/data
56+
environment:
57+
- cluster.name=docker-cluster
58+
- bootstrap.memory_lock=true
59+
- discovery.type=single-node
60+
networks:
61+
- default
62+
63+
64+
volumes:
65+
db_data:
66+
redis:
67+
elastic:

init_app.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
rails db:create
3+
rails db:migrate
4+
rm tmp/pids/server.pid
5+
rails server -b 0.0.0.0
6+
redis-server
7+
sidekiq restart

0 commit comments

Comments
 (0)