Skip to content

Commit

Permalink
Merge pull request #235 from OpenSourcePolitics/develop
Browse files Browse the repository at this point in the history
Release Develop > Master
  • Loading branch information
luciegrau authored Sep 18, 2024
2 parents 40338a1 + d609ab2 commit 4f3f6b6
Show file tree
Hide file tree
Showing 31 changed files with 2,162 additions and 47 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
SIMPLECOV: "true"
RSPEC_FORMAT: "documentation"
RUBY_VERSION: 3.0.6
CHROME_VERSION: 126.0.6478.182
RAILS_ENV: test
NODE_VERSION: 16.9.1
RUBYOPT: '-W:no-deprecated'
Expand Down Expand Up @@ -87,6 +88,12 @@ jobs:
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- run: |
sudo apt install libu2f-udev
wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${{env.CHROME_VERSION}}-1_amd64.deb
sudo dpkg -i /tmp/chrome.deb
rm /tmp/chrome.deb
name: Install Chrome version ${{ env.CHROME_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand All @@ -105,6 +112,8 @@ jobs:
- run: mkdir -p ./spec/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: ${{ env.CHROME_VERSION }}
- run: bundle exec rake "test:run[exclude, spec/system/**/*_spec.rb, ${{ matrix.slice }}]"
name: RSpec
# - run: ./.github/upload_coverage.sh decidim-app $GITHUB_EVENT_PATH
Expand Down Expand Up @@ -153,6 +162,12 @@ jobs:
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- run: |
sudo apt install libu2f-udev
wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${{env.CHROME_VERSION}}-1_amd64.deb
sudo dpkg -i /tmp/chrome.deb
rm /tmp/chrome.deb
name: Install Chrome version ${{ env.CHROME_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand All @@ -171,6 +186,8 @@ jobs:
- run: mkdir -p ./spec/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: ${{ env.CHROME_VERSION }}
- run: bundle exec rake "test:run[include, spec/system/**/*_spec.rb, ${{ matrix.slice }}]"
name: RSpec
# - run: ./.github/upload_coverage.sh decidim-app $GITHUB_EVENT_PATH
Expand Down
69 changes: 48 additions & 21 deletions Dockerfile.local
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"]
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gem "decidim-initiatives", "~> #{DECIDIM_VERSION}.0"
gem "decidim-templates", "~> #{DECIDIM_VERSION}.0"

# External Decidim gems
gem "decidim-budgets_booth", github: "Pipeline-to-Power/decidim-module-ptp", branch: "main"
gem "decidim-cache_cleaner"
gem "decidim-cleaner", git: "https://github.com/OpenSourcePolitics/decidim-module-cleaner.git", branch: "rc/3.1.1"
gem "decidim-decidim_awesome"
Expand All @@ -32,6 +31,8 @@ gem "decidim-spam_detection"
gem "decidim-survey_multiple_answers", git: "https://github.com/alecslupu-pfa/decidim-module-survey_multiple_answers"
gem "decidim-term_customizer", git: "https://github.com/OpenSourcePolitics/decidim-module-term_customizer.git", branch: "fix/email_with_precompile"

gem "decidim-budgets_booth", github: "Pipeline-to-Power/decidim-module-ptp", branch: "main"

# Omniauth gems
gem "omniauth-france_connect", git: "https://github.com/OpenSourcePolitics/omniauth-france_connect"
gem "omniauth-publik", git: "https://github.com/OpenSourcePolitics/omniauth-publik"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GIT

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module-half_sign_up.git
revision: c85a7ed0e399ded3d2494b8b8dffd6f75ad3fe6f
revision: c23334e721cd9a6b1d43ae72fc9b6a4387334c9f
branch: feature/half_signup_and_budgets_booth
specs:
decidim-half_signup (0.27.0)
Expand Down
41 changes: 28 additions & 13 deletions Makefile
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
Loading

0 comments on commit 4f3f6b6

Please sign in to comment.