Skip to content

Commit

Permalink
Merge pull request #1131 from etalab/makefile
Browse files Browse the repository at this point in the history
using a makefile to simply docker
  • Loading branch information
Samuelfaure authored Jul 24, 2023
2 parents 16c653a + bc5adc5 commit aa15d4f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DOCKER_COMPOSE_CMD = docker-compose
RAILS_DOCKER_CMD = ${DOCKER_COMPOSE_CMD} exec -e POSTGRES_HOST=db web bundle exec rails

start:
docker-compose up --build

stop:
docker-compose down

install_database:
$(RAILS_DOCKER_CMD) db:create
$(RAILS_DOCKER_CMD) db:schema:load
$(RAILS_DOCKER_CMD) db:seed:replant

reinstall_database:
$(RAILS_DOCKER_CMD) db:drop
$(MAKE) install_database
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,31 @@ installer les paquets et importer les tables de la base de données :
Installer `Docker` et `docker-compose` (sur Mac tout est
[ici](https://docs.docker.com/desktop/mac/install/))

Puis:
Pour lancer l'application :

```sh
docker-compose up --build
make start
```

Et pour setup la db:
**L'application doit être lancée pour exécuter les autres commandes.**

Pour arrêter:

```sh
make stop
```

Lors du premier lancement, il faut initialiser la base de donnée (après `make start`):

```sh
docker-compose exec -e RAILS_ENV=development -e POSTGRES_HOST=db web bundle exec rails db:schema:load db:schema:load
docker-compose exec -e RAILS_ENV=development -e POSTGRES_HOST=db web bundle exec rails db:schema:load db:seed:replant
make install_database
```

P.S: la première commande se termine en erreur parfois, mais le schéma est
bien loadé. Il n'est donc pas possible de chaîner les commandes.
En cas de problème, pour réinstaller la base de données:

```sh
make reinstall_database
```

## Tests

Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ development:
# Do not set this db to the same as development or production.
test:
<<: *default
host: localhost
host: <%= ENV.fetch("POSTGRES_HOST") { 'localhost' } %>
database: admin_apientreprise_test

# As with config/secrets.yml, you never want to store sensitive information,
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"
services:
db:
image: postgres:12.4
Expand All @@ -10,7 +10,7 @@ services:
volumes:
- ./docker/db/:/docker-entrypoint-initdb.d
redis:
image: 'redis:6.2-alpine'
image: "redis:6.2-alpine"
command: redis-server
web:
build: .
Expand Down

0 comments on commit aa15d4f

Please sign in to comment.