-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from OpenSourcePolitics/develop
Release Develop > Master
- Loading branch information
Showing
31 changed files
with
2,162 additions
and
47 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 |
---|---|---|
@@ -1,57 +1,84 @@ | ||
# Builder Stage | ||
FROM ruby:3.0.6-slim as builder | ||
# Base image for builder stage | ||
FROM ruby:3.0.6-slim as base | ||
|
||
# Set environment variables | ||
ENV RAILS_ENV=production \ | ||
SECRET_KEY_BASE=dummy | ||
|
||
# Install common dependencies | ||
RUN apt-get update -q && \ | ||
apt-get install -yq --no-install-recommends \ | ||
libpq-dev curl git libicu-dev build-essential openssl && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Builder Stage | ||
FROM base as builder | ||
|
||
# Set work directory | ||
WORKDIR /app | ||
|
||
RUN apt-get update -q && \ | ||
apt-get install -yq libpq-dev curl git libicu-dev build-essential openssl libproj-dev proj-bin && \ | ||
curl https://deb.nodesource.com/setup_16.x | bash && \ | ||
# Install Node.js and Yarn | ||
RUN curl -fsSL https://deb.nodesource.com/setup_18.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 | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Bundler | ||
RUN gem install bundler:2.4.9 | ||
|
||
# Copy Gemfile and install gems | ||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle config set --local without 'development test' && \ | ||
bundle install -j"$(nproc)" | ||
RUN bundle config set build.rgeo-proj4 --with-proj-dir="/usr/bin/" | ||
|
||
# Copy package.json and install node modules | ||
COPY package.json yarn.lock ./ | ||
COPY packages packages | ||
RUN yarn install --frozen-lock | ||
RUN yarn install --frozen-lockfile | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Precompile assets and perform other build tasks | ||
RUN bundle exec bootsnap precompile --gemfile app/ lib/ config/ bin/ db/ && \ | ||
bundle exec rails assets:precompile && \ | ||
bundle exec rails deface: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; | ||
# Generate self-signed certificate | ||
RUN mkdir certificate-https-local && \ | ||
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 | ||
FROM base as runner | ||
|
||
ENV RAILS_ENV=production \ | ||
SECRET_KEY_BASE=dummy \ | ||
RAILS_LOG_TO_STDOUT=true \ | ||
# Set environment variables | ||
ENV 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" | ||
|
||
# Set work directory | ||
WORKDIR /app | ||
|
||
# Install runtime dependencies | ||
RUN apt-get update -q && \ | ||
apt-get install -yq postgresql-client imagemagick libproj-dev proj-bin libjemalloc2 && \ | ||
apt-get install -yq --no-install-recommends \ | ||
postgresql-client imagemagick libproj-dev proj-bin libjemalloc2 && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
gem install bundler:2.4.9 | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Install Bundler | ||
RUN gem install bundler:2.4.9 | ||
|
||
# Copy the built application and gems from the builder stage | ||
COPY --from=builder /usr/local/bundle /usr/local/bundle | ||
COPY --from=builder /app /app | ||
|
||
# Expose port | ||
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"] | ||
|
||
# Start the Rails server | ||
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
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,41 +1,56 @@ | ||
IMAGE_NAME=decidim-tou | ||
|
||
run: up | ||
@make create-seeds | ||
|
||
up: | ||
docker build . -f Dockerfile.local -t decidim-tou-app:latest | ||
docker build . -f Dockerfile.local -t decidim-tou-sidekiq:latest | ||
docker-compose -f docker-compose.local.yml up -d | ||
up: build | ||
docker compose -f docker-compose.local.yml up -d | ||
@make setup-database | ||
|
||
build: | ||
docker build . -f Dockerfile.local -t ${IMAGE_NAME}:latest | ||
|
||
# Stops containers and remove volumes | ||
teardown: | ||
docker-compose -f docker-compose.local.yml down -v --rmi all | ||
docker compose -f docker-compose.local.yml down -v --rmi all | ||
|
||
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:create' | ||
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' | ||
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 -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' | ||
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 | ||
docker compose -f docker-compose.local.yml exec app /bin/bash | ||
|
||
restart: | ||
docker-compose -f docker-compose.local.yml up -d | ||
docker compose -f docker-compose.local.yml up -d | ||
|
||
status: | ||
docker-compose -f docker-compose.local.yml ps | ||
docker compose -f docker-compose.local.yml ps | ||
|
||
logs: | ||
docker-compose -f docker-compose.local.yml logs app | ||
docker compose -f docker-compose.local.yml logs app | ||
|
||
external: | ||
@if [ -z "$(IP)" ]; then \ | ||
echo "Pass IP as follow : make external IP=192.168.64.1"; \ | ||
echo "You can discover your IP as follow : \n > ifconfig | grep netmask | grep -v 127.0.0.1 | awk '{print \$$2}' | tail -n1"; \ | ||
exit 1; \ | ||
fi | ||
docker compose -f docker-compose.local.yml exec app /bin/bash -c 'DISABLE_DATABASE_ENVIRONMENT_CHECK=1 /usr/local/bundle/bin/bundle exec rails runner "puts Decidim::Organization.first.update(host: \"$(IP)\")"'; \ | ||
echo "Decidim organization host updated to $(IP)"; \ | ||
echo "App is now accessible at https://$(IP):3000"; | ||
|
||
rebuild: | ||
docker-compose -f docker-compose.local.yml up --build -d | ||
docker compose -f docker-compose.local.yml down | ||
docker volume rm ${IMAGE_NAME}_shared-volume || true | ||
@make up |
Oops, something went wrong.