Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: add a Docker setup #2349

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.git
.github
.dockerignore
Dockerfile
docker-compose.yml
tmp/**
log/**
.DS_STORE
storage/**
.local
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ruby:3.3.3-slim

EXPOSE 3000

RUN apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends -y build-essential libpq-dev nodejs npm git curl

# do the bundle install in another directory with the strict essential
# (Gemfile and Gemfile.lock) to allow further steps to be cached
# (namely the NPM steps)
WORKDIR /bundle
COPY Gemfile Gemfile.lock ./
RUN bundle install

# Move to the main folder
WORKDIR /app

# We can't do the WORKDIR trick here because npm modules need to be
# installed in the root folder (since they're installed locally in
# node_modules)
COPY package.json yarn.lock ./

RUN npm install -g yarn && yarn install

COPY . .

ENTRYPOINT ["./entrypoint.sh"]

CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
DOCKER-RUN = docker compose run -e TERM -e DISABLE_SPRING_WATCHER_LISTEN=1 --rm --entrypoint=""
BUNDLE-EXEC = bundle exec

install: ## Setup development environment
bin/setup

Expand Down Expand Up @@ -26,3 +29,9 @@ help: ## Display available commands

rswag:
SWAGGER_DRY_RUN=0 RAILS_ENV=test rake rswag:specs:swaggerize PATTERN="spec/requests/api/**/*_spec.rb"

sh: ## [docker] Runs a shell within the web container
$(DOCKER-RUN) web bash

cl: ## [docker] Runs a Rails console within the web container
$(DOCKER-RUN) web $(BUNDLE-EXEC) bin/rails c
2 changes: 1 addition & 1 deletion config/initializers/agent_connect.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless Rails.env.test?
if Rails.env.production?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seul obstacle pour le moment : AgentConnect qui essaie d'effectuer une connexion à un serveur externe même dans un environnement local

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je suis d'accord on ne devrait pas avoir ce comportement en dev (ça ne devrait pas de poser de problème @Michaelvilleneuve ?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement on peut conditionner ça, de toute façon AgentConnect ne fonctionnera pas en dév

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pour info je crois que Romain a de toute façon rajouté cette condition dans sa PR donc ça finira pas être mergé avec ou sans cette PR

AgentConnect.initialize! do |config|
config.client_id = ENV["AGENT_CONNECT_CLIENT_ID"]
config.client_secret = ENV["AGENT_CONNECT_CLIENT_SECRET"]
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Dans le cas où on veut aller au-delà du POC et faire du dev faudra juste rajouter les workers ici)

web:
image: rdv-insertion-web
build: .
depends_on:
- db
env_file:
- '.env'
ports:
- "8000:8000"
volumes:
- assets:/app/app/assets/builds
js:
image: rdv-insertion-web
command: ["yarn", "build", "--watch"]
entrypoint: '' # ignore the Rails commands in entrypoint.sh
volumes:
- assets:/app/app/assets/builds
db:
image: postgres:15
environment:
POSTGRES_PASSWORD: dummy
PGPORT: 5433
volumes:
- "./tmp/db:/var/lib/postgresql/data"
ports:
- "5433:5433"
volumes:
assets:
21 changes: 20 additions & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@

## Outils à installer

- Ruby 3.0.3 (nous conseillons l’utilisation de [rbenv](https://github.com/rbenv/rbenv-installer#rbenv-installer--doctor-scripts))
Pour lancer l'application en local :

- Ruby 3.3.3 (nous conseillons l’utilisation de [rbenv](https://github.com/rbenv/rbenv-installer#rbenv-installer--doctor-scripts))
- PostgreSQL >= 12, l’utilisateur doit avoir les droits `superuser`. C'est nécessaire pour pouvoir activer les extensions utilisés.
- [Yarn](https://yarnpkg.com/en/docs/install)
- [Foreman](https://github.com/ddollar/foreman), (ou équivalent, comme [Overmind](https://github.com/DarthSim/overmind))
- [Scalingo CLI](https://doc.scalingo.com/cli) (OPTIONAL)
- [Make](https://fr.wikipedia.org/wiki/Make) (OPTIONAL)

## Avec Docker

Pour lancer l'applicaiton avec Docker :

Installez Docker et Docker Compose (avec [Docker Desktop](https://www.docker.com/products/docker-desktop/) par exemple) puis lancez :

```sh
docker-compose up
```

Quelques commandes de base sont fournies pour accéder à votre conteneur web :

```
make sh # lance un terminal
make cl # lance une console Rails
```

## Avant de commencer

### Installer RDV-Solidarités
Expand Down
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh -l
set -ex

if [ -f /app/tmp/pids/server.pid ]; then
rm /app/tmp/pids/server.pid
fi

bin/rails db:prepare

exec "$@"