-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Configure Puma server and Local docker-compose with HTTPS (#445)
* feat: Local docker-compose * fix: Update make run command * fix: Local docker-compose * fix: Webpacker compilation * fix: Local docker-compose * fix: Docker-compose with https in local * doc: Add Getting started with Docker in README * fix: Add letter_opener gem to global scope * feat: Add docker commands to Makefile * fix: backport fix docker-compose * refactor: Remove not needed entrypoint.local.sh * feat: Generate SSL certificate in Dockerfile.local * fix: Fine tuning puma on docker-compose local * lint: Fix rubocop offense * Update GETTING_STARTED_DOCKER.md fix typo --------- Co-authored-by: ailepet <[email protected]>
- Loading branch information
Showing
9 changed files
with
168 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,3 +97,4 @@ yarn-debug.log* | |
coverage/ | ||
public/sw.js* | ||
app/compiled_views/ | ||
certificate-https-local/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Builder Stage | ||
FROM ruby:3.0.6-slim as builder | ||
|
||
ENV RAILS_ENV=production \ | ||
SECRET_KEY_BASE=dummy | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update -q && \ | ||
apt-get install -yq libpq-dev curl git libicu-dev build-essential openssl && \ | ||
curl https://deb.nodesource.com/setup_16.x | bash && \ | ||
apt-get install -y nodejs && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
npm install --global yarn && \ | ||
gem install bundler:2.4.9 | ||
|
||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle config set --local without 'development test' && \ | ||
bundle install -j"$(nproc)" | ||
|
||
COPY package.json yarn.lock ./ | ||
COPY packages packages | ||
RUN yarn install --frozen-lock | ||
|
||
COPY . . | ||
|
||
RUN bundle exec bootsnap precompile --gemfile app/ lib/ config/ bin/ db/ && \ | ||
bundle exec rails deface:precompile && \ | ||
bundle exec rails assets:precompile | ||
|
||
run mkdir certificate-https-local | ||
RUN openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=FR/ST=France/L=Paris/O=decidim/CN=decidim.eu" -keyout ./certificate-https-local/key.pem -out ./certificate-https-local/cert.pem; | ||
|
||
# Runner Stage | ||
FROM ruby:3.0.6-slim as runner | ||
|
||
ENV RAILS_ENV=production \ | ||
SECRET_KEY_BASE=dummy \ | ||
RAILS_LOG_TO_STDOUT=true \ | ||
LD_PRELOAD="libjemalloc.so.2" \ | ||
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:5000,muzzy_decay_ms:5000,narenas:2" | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update -q && \ | ||
apt-get install -yq postgresql-client imagemagick libproj-dev proj-bin libjemalloc2 && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
gem install bundler:2.4.9 | ||
|
||
COPY --from=builder /usr/local/bundle /usr/local/bundle | ||
COPY --from=builder /app /app | ||
|
||
EXPOSE 3000 | ||
CMD ["bundle", "exec", "rails", "server", "-b", "ssl://0.0.0.0:3000?key=/app/certificate-https-local/key.pem&cert=/app/certificate-https-local/cert.pem"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
# Starts with production configuration | ||
local-prod: | ||
docker-compose up -d | ||
|
||
# Starts with development configuration | ||
# TODO: Fix seeds for local-dev make command | ||
local-dev: | ||
docker-compose -f docker-compose.dev.yml up -d | ||
@make create-database | ||
@make run-migrations | ||
#@make create-seeds | ||
run: up | ||
@make create-seeds | ||
|
||
up: | ||
docker-compose -f docker-compose.local.yml up --build -d | ||
@make setup-database | ||
|
||
# Stops containers and remove volumes | ||
teardown: | ||
docker-compose down -v --rmi all | ||
|
||
# Starts containers and restore dump | ||
local-restore: | ||
@make create-database | ||
@make -i restore-dump | ||
@make run-migrations | ||
@make start | ||
docker-compose -f docker-compose.local.yml down -v --rmi all | ||
|
||
# Create database | ||
create-database: | ||
docker-compose run app bundle exec rails db:create | ||
# Run migrations | ||
run-migrations: | ||
docker-compose run app bundle exec rails db:migrate | ||
docker-compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rake db:create' | ||
|
||
setup-database: create-database | ||
docker-compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rake db:migrate' | ||
|
||
# Create seeds | ||
create-seeds: | ||
docker-compose exec -e RAILS_ENV=development app /bin/bash -c '/usr/local/bundle/bin/bundle exec rake db:seed' | ||
docker-compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rake db:schema:load db:seed' | ||
|
||
# Restore dump | ||
restore-dump: | ||
bundle exec rake restore_dump | ||
|
||
shell: | ||
docker-compose -f docker-compose.local.yml exec app /bin/bash | ||
|
||
restart: | ||
docker-compose -f docker-compose.local.yml up -d | ||
|
||
status: | ||
docker-compose -f docker-compose.local.yml ps | ||
|
||
logs: | ||
docker-compose -f docker-compose.local.yml logs app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Starting DecidimApp on Docker with HTTPS ! | ||
|
||
## Requirements | ||
* **Docker** | ||
* **Docker-compose** | ||
* **Git** | ||
* **Make** | ||
* **OpenSSL** | ||
* **PostgreSQL** 14+ | ||
|
||
## Installation | ||
|
||
### Setup a clean Decidim App | ||
|
||
1. Clone repository | ||
2. Create a `.env` file from `.env.example` and fill it with your own values | ||
3. Start the application with `make up` | ||
|
||
Once containers are deployed, you should be able to visit : https://localhost:3000 | ||
|
||
Also, you should be automatically redirected to https://localhost:3000/system because your database is empty. | ||
|
||
### Setup a seeded DecidimApp | ||
|
||
1. Clone repository | ||
2. Create a `.env` file from `.env-example` and fill it with your own values | ||
3. Start the application with `make run` | ||
|
||
Once containers are deployed, you should be able to visit : https://localhost:3000/ without being redirected ! | ||
|
||
## Informations | ||
|
||
* Please use the `docker-compose.local.yml` in local environment because it uses `Dockerfile.local` which includes self signed certificate and allows to enable https in localhost | ||
* If you want to cleanup your environmen run `make teardown` : it will stop containers and remove volumes and images | ||
|