Skip to content
This repository was archived by the owner on Sep 27, 2021. It is now read-only.

Commit 9bd0f0a

Browse files
committed
Auto-seed
1 parent 2e1f7bf commit 9bd0f0a

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

.docker/entrypoint

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@
33
set +e
44

55
echo "⚙️ Testing DB connection"
6-
timeout 300s waitfortcp "$RAILS_DB_HOST" "$RAILS_DB_PORT"
6+
timeout 300s waitfortcp "${RAILS_DB_HOST-db}" "${RAILS_DB_PORT-3306}"
77
echo "✅ DB is ready"
88

99
if [ "$RAILS_ENV" != "production" ]; then
1010
echo "⚙️ Performing migrations"
11-
bundle exec rake db:migrate
12-
bundle exec rake wagon:migrate
11+
bundle exec rake db:migrate wagon:migrate
1312
echo "✅ Migrations done"
1413
else
1514
echo "↪️ Skipping migrations because RAILS_ENV='$RAILS_ENV'"
1615
fi
1716

17+
if [ "$RAILS_ENV" == "development" ]; then
18+
if [ ! -f /seed/done ]; then
19+
echo "⚙️ Seeding DB"
20+
bundle exec rake db:seed wagon:seed && date > /seed/done
21+
echo "✅ Seeding done"
22+
else
23+
echo "↪️ Skipping seeding because already done on $(cat /seed/done)"
24+
fi
25+
else
26+
echo "↪️ Skipping seeding because RAILS_ENV='$RAILS_ENV'"
27+
fi
28+
1829
echo "➡️ Handing control over to '$*''"
1930

2031
# shellcheck disable=SC2068

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**/.git
55
**/.gitignore
66
**/.editorconfig
7+
**/.code-workspace
78
**/.project
89
**/.travis.yml
910
**/AUTHORS

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ echo "http://$(docker-compose port mail 1080)"
5050

5151
## First Login
5252

53-
Use the password reset flow and use the e-mail address of the root account.
54-
You find it as `root_email` in the `settings.yml` file of the wagon.
53+
Get the login information via the Rails console.
5554

56-
Then open the mailcatcher and copy the path.
57-
**Don't forget to adjust the host & port in that url!**
55+
```bash
56+
echo 'p=Person.first; p.update(password: "password"); "You can now login as #{p.email} with the password \"password\""' | \
57+
docker-compose run --rm -T app rails c
58+
```
5859

59-
Now you should be able to log-in.
60+
Now you should be able to log-in with the email address in the output and the password _password_.
6061

6162
## Debug
6263

@@ -76,6 +77,19 @@ To run them all, use the following command:
7677
docker-compose run --rm test
7778
```
7879

80+
### Test of a specific Wagon
81+
82+
To test a specific wagon, you need to cd to the directory.
83+
But because the `entrypoint` script automatically does a `bundle exec` for you (which is fine most of the time), you need to overwrite the entrypoint to be plain `bash`.
84+
85+
```bash
86+
$ docker-compose run --rm --entrypoint bash test
87+
Starting hitobito_db-test_1 ... done
88+
root@a42b42c42d42:/app/hitobito# rake db:migrate wagon:migrate # if you changed the db schema
89+
root@a42b42c42d42:/app/hitobito# cd ../hitobito_WAGON/
90+
root@a42b42c42d42:/app/hitobito_WAGON# rspec
91+
```
92+
7993
## Full-text search
8094

8195
Hitobito relies on Sphinx Search for indexing Persons, Events and Groups.

docker-compose.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ services:
88
- db
99
- mail
1010
- cache
11-
- worker
1211
env_file: .docker/app.env
1312
ports:
1413
- 3000
1514
volumes:
1615
- ./:/app
16+
- seed:/seed
1717

1818
worker:
1919
<<: *app
@@ -28,8 +28,13 @@ services:
2828
context: .
2929
target: test
3030
depends_on:
31-
- db
31+
- db-test
3232
env_file: .docker/app.env
33+
environment:
34+
RAILS_DB_NAME: hitobito_test
35+
RAILS_DB_HOST: db-test
36+
volumes:
37+
- ./:/app
3338

3439
# Dependencies
3540

@@ -64,13 +69,22 @@ services:
6469

6570
db:
6671
image: mysql:5.6
72+
command:
73+
- --sort_buffer_size=2M
6774
env_file: .docker/mysql.env
6875
volumes:
6976
- db:/var/lib/mysql
77+
78+
db-test:
79+
image: mysql:5.6
7080
command:
7181
- --sort_buffer_size=2M
82+
env_file: .docker/mysql.env
83+
environment:
84+
MYSQL_DATABASE: hitobito_test
7285

7386
volumes:
7487
db:
7588
sphinx:
89+
seed:
7690

0 commit comments

Comments
 (0)