Skip to content

Commit 6a99e91

Browse files
committed
Merge branch 'feature/docker-compose' into develop
* feature/docker-compose: Added redis.yml Fixed docker-compose for development working well Added docker-compose in readme Fixed- You must use Bundler 2 or greater with this lockfile. RUN gem update --system Added Dockerfile, docker-compose
2 parents 04b51b7 + 7b26479 commit 6a99e91

File tree

9 files changed

+120
-30
lines changed

9 files changed

+120
-30
lines changed

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ruby:2.6.0
2+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
3+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
4+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
5+
apt-get update && \
6+
apt-get install -qq -y build-essential nodejs yarn \
7+
libpq-dev postgresql-client
8+
RUN mkdir /myapp
9+
WORKDIR /myapp
10+
COPY . /myapp
11+
RUN gem update --system
12+
RUN bundle install
13+
RUN yarn install --check-files
14+
15+
# Add a script to be executed every time the container starts.
16+
COPY entrypoint.sh /usr/bin/
17+
RUN chmod +x /usr/bin/entrypoint.sh
18+
ENTRYPOINT ["entrypoint.sh"]
19+
EXPOSE 3000
20+
21+
# Start the main process.
22+
CMD ["rails", "server", "-b", "0.0.0.0"]

README.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,41 @@
33
How to Run
44
----------
55

6-
1. Ready to database
7-
1. Run Postgresql and migrate
8-
```bash
9-
bundle install
10-
````
11-
```bash
12-
rake docker:db:init
13-
rake docker:db:run
14-
```
15-
```bash
16-
rake db:migrate
17-
rake db:migrate RAILS_ENV=test
6+
1. Setup
7+
1. non docker-compose
8+
1. Run Postgresql and migrate
9+
```bash
10+
bundle install
11+
````
12+
```bash
13+
rake docker:db:init
14+
rake docker:db:run
15+
```
16+
```bash
17+
rake db:migrate
18+
rake db:migrate RAILS_ENV=test
19+
````
20+
```bash
21+
rake db:seed
22+
```
23+
2. Run Redis for cache
24+
```bash
25+
docker run --rm --name my-redis-container -p 7001:6379 -d redis redis-server --appendonly yes
26+
redis-cli -h localhost -p 7001
27+
```
28+
3. Rails Server Run
29+
```bash
30+
rails s
31+
```
32+
2. docker-compose
33+
````bash
34+
docker-compose up --build
35+
docker-compose run web bundle exec rake db:test:load
36+
docker-compose run web bundle exec rake db:migrate
37+
docker-compose run web bundle exec rake db:seed
38+
docker-compose run web bundle exec rake rswag
39+
docker-compose run web bundle exec rake spec --format documentation
1840
````
19-
```bash
20-
rake db:seed
21-
```
22-
2. Run Redis for cache
23-
```bash
24-
docker run --rm --name my-redis-container -p 7001:6379 -d redis redis-server --appendonly yes
25-
redis-cli -h localhost -p 7001
26-
```
2741
2. ELK
2842
```bash
2943
git clone https://github.com/deviantony/docker-elk
@@ -36,11 +50,7 @@ How to Run
3650
```bash
3751
bundle exec rpsec --format documentation
3852
```
39-
4. Rails Server Run
40-
```bash
41-
rails s
42-
```
43-
5. Swagger - Restful Api Documentation
53+
4. Swagger - Restful Api Documentation
4454
```bash
4555
rake rswag
4656
```
@@ -340,6 +350,7 @@ https://ericlondon.com/2017/01/26/integrate-rails-logs-with-elasticsearch-logsta
340350
#### server run
341351
```bash
342352
docker run --rm --name my-redis-container -p 7001:6379 -d redis redis-server --appendonly yes
353+
docker run --rm --name my-redis-container -p 7001:6379 -d redis
343354
redis-cli -h localhost -p 7001
344355
```
345356

config/database.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ default: &default
2222
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
2323
username: docker_postgres_rails
2424
password: mysecretpassword
25-
host: localhost
25+
host: db
2626
port: 5432
2727

2828
development:
2929
<<: *default
3030
database: sample_post_api_development
31-
31+
3232
# The specified database role being used to connect to postgres.
3333
# To create additional roles in postgres see `$ createuser --help`.
3434
# When left blank, postgres will use the default role. This is

config/elk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
default: &default
2-
enable: true
2+
enable: false
33
protocal: udp
44
host: localhost
55
port: 5000

config/initializers/redis.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# config/initializers/redis.rb
2+
redis_config = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]
3+
$redis = Redis::Namespace.new(redis_config['namespace'], redis: Redis.new(host: redis_config['host'], port: redis_config['port']))
4+
25

3-
$redis = Redis::Namespace.new("tutorial_post", :redis => Redis.new(:host => '127.0.0.1', :port => 7001))

config/redis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#config/redis.yml
2+
default: &default
3+
host: redis
4+
port: 6379
5+
namespace: tutorial_post
6+
development:
7+
<<: *default
8+
db: 0
9+
test:
10+
<<: *default
11+
db: 1
12+
production:
13+
<<: *default
14+
db: 2
15+
host: 192.168.1.100
16+
namespace: tutorial_post

db/seeds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414

1515
admin = FactoryBot.create :admin
16-
user_count = 50
16+
user_count = 10
1717
category_count = rand(10..20)
1818
post_count_max = 30
1919
comment_count_max = 30

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3'
2+
services:
3+
db:
4+
image: postgres:10.10
5+
volumes:
6+
- ./tmp/db:/var/lib/postgresql/data
7+
ports:
8+
- "5432:5432"
9+
environment:
10+
- POSTGRES_USER=docker_postgres_rails
11+
- POSTGRES_PASSWORD=mysecretpassword
12+
- POSTGRES_DB=sample_post_api_development
13+
redis:
14+
image: redis:4.0-alpine
15+
volumes:
16+
- ./tmp/redis:/data
17+
entrypoint: redis-server --appendonly yes
18+
ports:
19+
- "7001:6379"
20+
web:
21+
build: .
22+
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
23+
volumes:
24+
- .:/myapp
25+
ports:
26+
- "3000:3000"
27+
depends_on:
28+
- db
29+
- redis
30+
volumes:
31+
pgdata:

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Remove a potentially pre-existing server.pid for Rails.
5+
rm -f /myapp/tmp/pids/server.pid
6+
7+
# Then exec the container's main process (what's set as CMD in the Dockerfile).
8+
exec "$@"

0 commit comments

Comments
 (0)