File tree Expand file tree Collapse file tree 3 files changed +112
-8
lines changed Expand file tree Collapse file tree 3 files changed +112
-8
lines changed Original file line number Diff line number Diff line change
1
+ DOCKER_COMPOSE =docker-compose
2
+ RUN_WEB =$(DOCKER_COMPOSE ) run --rm web
3
+ DATABASE_YAML_COPY_FROM =database.postgres.yml
4
+ DATABASE_YAML_COPY_TO =config/database.yml
5
+
6
+ all :
7
+ @make new --no-print-directory
8
+ @make build --no-print-directory
9
+ @make copy-config --no-print-directory
10
+ @make db-create --no-print-directory
11
+ @make up --no-print-directory
12
+ @echo " Yay! You're on Rails !!" && echo " Open in web browser http://localhost:3000"
13
+
14
+ # Create a rails project
15
+ new :
16
+ @$(RUN_WEB ) rails new . --force --no-deps --database=postgresql --skip-test --webpacker
17
+
18
+ # Build Dockerfile
19
+ build :
20
+ @$(DOCKER_COMPOSE ) build --no-cache
21
+
22
+ # Copy postgres connection settings
23
+ copy-config :
24
+ @$(RUN_WEB ) cp -b $(DATABASE_YAML_COPY_FROM ) $(DATABASE_YAML_COPY_TO ) | true
25
+
26
+ # Create a database
27
+ db-create :
28
+ @$(RUN_WEB ) bundle exec rake db:create
29
+
30
+ # Create and start a docker container
31
+ up :
32
+ @$(DOCKER_COMPOSE ) up -d
33
+
34
+ # Close container
35
+ down :
36
+ @$(DOCKER_COMPOSE ) down
37
+
38
+ # Delete all containers, images, volumes, and networks
39
+ remove-all :
40
+ @$(DOCKER_COMPOSE ) down --rmi all --volumes
Original file line number Diff line number Diff line change 1
1
# docker-rails6-postgres
2
2
3
+ ## Run the following command
4
+
5
+ ``` bash
6
+ $ make all
7
+ ```
8
+
9
+ That's all.
10
+
11
+
3
12
## How to buildup environment
13
+
4
14
### Clone This Repository
5
15
6
- ```
16
+ ``` bash
7
17
$ git clone https://github.com/tokidrill/docker-rails6-postgres.git
8
18
```
9
19
10
20
### Run rails new
21
+
11
22
Create Rails project with PostgreSQL.
12
23
24
+ #### run rails new
25
+
13
26
```
14
- $ docker-compose run web rails new . --force --no-deps --databse=postgres --skip-test --webpacker
27
+ $ docker-compose run --rm web rails new . --force --no-deps --databse=postgres --skip-test --webpacker
15
28
```
16
29
17
- ### Build Docker image
30
+ #### alias
18
31
32
+ ``` bash
33
+ $ make new
19
34
```
35
+
36
+ ### Build Docker image
37
+
38
+ ``` bash
20
39
$ docker-compose build --no-cache
21
40
```
22
41
42
+ #### alias
43
+
44
+ ``` bash
45
+ $ make build
46
+ ```
47
+
23
48
### Modify your database configulation and create database
24
49
25
- Modify ``` database.yml ``` .
50
+ #### Modify ``` database.yml ``` .
26
51
27
52
config/database.yml
28
53
``` config/database.yml
@@ -53,18 +78,34 @@ production:
53
78
54
79
```
55
80
56
- Then, run migrate for initialize.
81
+ #### Or execute the command
57
82
83
+ ``` bash
84
+ make copy-config
58
85
```
86
+
87
+ #### Then, run migrate for initialize.
88
+
89
+ ``` bash
59
90
$ docker-compose run web rake db:create
60
91
```
61
92
62
93
## Up Docker container
63
94
64
- ```
95
+ ``` bash
65
96
$ docker-compose up -d
66
97
```
67
98
99
+ #### alias
100
+
101
+ ``` bash
102
+ $ make up
103
+ ```
104
+
68
105
## Yay! You're on Rails !!
69
- Access http://localhost:3000 .
70
- Congratulations !! Now, you're on Rails !!
106
+ Access http://localhost:3000 .
107
+ Congratulations !! Now, you're on Rails !!
108
+
109
+ #### Other commands
110
+
111
+ [ See Makefile] ( ./Makefile )
Original file line number Diff line number Diff line change
1
+ default : &default
2
+ adapter : postgresql
3
+ encoding : utf8
4
+
5
+ pool : <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
6
+ host : <%= ENV.fetch('DATABASE_HOST') {'db'} %>
7
+ port : <%= ENV.fetch('DATABASE_PORT') {'5432'} %>
8
+ username : <%= ENV.fetch('DATABASE_USER') {'postgres'} %>
9
+ password : <%= ENV.fetch('DATABASE_PASSWORD') {'password'} %>
10
+
11
+ development :
12
+ << : *default
13
+ database : test_development
14
+
15
+ test :
16
+ << : *default
17
+ database : test_test
18
+
19
+ production :
20
+ << : *default
21
+ database : test_production
22
+ username : test
23
+ password : <%= ENV['TEST_DATABASE_PASSWORD'] %>
You can’t perform that action at this time.
0 commit comments