diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8a9918b92 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules +.git +.github +.dockerignore +Dockerfile +docker-compose.yml +tmp/** +log/** +.DS_STORE +storage/** +.local diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..ca18ae3e2 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index b2335d378..af1737b62 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/config/initializers/agent_connect.rb b/config/initializers/agent_connect.rb index 9e9397a28..63192613b 100644 --- a/config/initializers/agent_connect.rb +++ b/config/initializers/agent_connect.rb @@ -1,4 +1,4 @@ -unless Rails.env.test? +if Rails.env.production? AgentConnect.initialize! do |config| config.client_id = ENV["AGENT_CONNECT_CLIENT_ID"] config.client_secret = ENV["AGENT_CONNECT_CLIENT_SECRET"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..75cdf581e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +services: + 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: diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 7e63567d4..2cf596ee4 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 000000000..4ab85cd72 --- /dev/null +++ b/entrypoint.sh @@ -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 "$@"