Skip to content

Commit acbdf4e

Browse files
committed
add: Create a Makefile that defines build and launch commands
1 parent b7cd404 commit acbdf4e

File tree

3 files changed

+112
-8
lines changed

3 files changed

+112
-8
lines changed

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

README.md

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
11
# docker-rails6-postgres
22

3+
## Run the following command
4+
5+
```bash
6+
$ make all
7+
```
8+
9+
That's all.
10+
11+
312
## How to buildup environment
13+
414
### Clone This Repository
515

6-
```
16+
```bash
717
$ git clone https://github.com/tokidrill/docker-rails6-postgres.git
818
```
919

1020
### Run rails new
21+
1122
Create Rails project with PostgreSQL.
1223

24+
#### run rails new
25+
1326
```
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
1528
```
1629

17-
### Build Docker image
30+
#### alias
1831

32+
```bash
33+
$ make new
1934
```
35+
36+
### Build Docker image
37+
38+
```bash
2039
$ docker-compose build --no-cache
2140
```
2241

42+
#### alias
43+
44+
```bash
45+
$ make build
46+
```
47+
2348
### Modify your database configulation and create database
2449

25-
Modify ```database.yml``` .
50+
#### Modify ```database.yml``` .
2651

2752
config/database.yml
2853
```config/database.yml
@@ -53,18 +78,34 @@ production:
5378
5479
```
5580

56-
Then, run migrate for initialize.
81+
#### Or execute the command
5782

83+
```bash
84+
make copy-config
5885
```
86+
87+
#### Then, run migrate for initialize.
88+
89+
```bash
5990
$ docker-compose run web rake db:create
6091
```
6192

6293
## Up Docker container
6394

64-
```
95+
```bash
6596
$ docker-compose up -d
6697
```
6798

99+
#### alias
100+
101+
```bash
102+
$ make up
103+
```
104+
68105
## 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)

database.postgres.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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'] %>

0 commit comments

Comments
 (0)