-
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.
- Loading branch information
1 parent
6e070ef
commit e075f2b
Showing
5 changed files
with
171 additions
and
76 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 |
---|---|---|
|
@@ -83,3 +83,4 @@ git-status.txt | |
/yarn-error.log | ||
yarn-debug.log* | ||
.yarn-integrity | ||
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,51 @@ | ||
# Builder Stage | ||
FROM ruby:2.7.5-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 && \ | ||
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 'test' && \ | ||
bundle install -j"$(nproc)" | ||
|
||
COPY package.json yarn.lock ./ | ||
COPY packages packages | ||
RUN yarn install --frozen-lockfile | ||
|
||
COPY . . | ||
RUN bundle exec bootsnap precompile --gemfile app/ lib/ config/ bin/ db/ && \ | ||
bundle exec bin/webpack | ||
|
||
# Runner Stage | ||
FROM ruby:2.7.5-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,44 @@ | ||
#### Terraform | Scaleway provider | ||
init-scw: | ||
terraform -chdir=deploy/providers/scaleway init | ||
|
||
plan-scw: | ||
@make init-scw | ||
terraform -chdir=deploy/providers/scaleway plan | ||
|
||
deploy-scw: | ||
@make init-scw | ||
terraform -chdir=deploy/providers/scaleway apply | ||
run: up | ||
@make create-seeds | ||
|
||
destroy-scw: | ||
terraform -chdir=deploy/providers/scaleway destroy | ||
up: generate-certificate | ||
docker-compose -f docker-compose.local.yml up --build -d | ||
@make setup-database | ||
|
||
### Docker usage | ||
certificate: | ||
mkdir -p -- ./certificate-https-local | ||
|
||
# Docker images commands | ||
generate-certificate: certificate | ||
@if [ ! -f "./certificate-https-local/cert.pem" ]; then \ | ||
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=FR/ST=France/L=Paris/O=OpenSourcePolitics/CN=opensourcepolitics.eu" -keyout ./certificate-https-local/key.pem -out ./certificate-https-local/cert.pem; \ | ||
fi | ||
|
||
REGISTRY := rg.fr-par.scw.cloud | ||
NAMESPACE := decidim-app | ||
VERSION := latest | ||
IMAGE_NAME := decidim-app | ||
TAG := $(REGISTRY)/$(NAMESPACE)/$(IMAGE_NAME):$(VERSION) | ||
# Stops containers and remove volumes | ||
teardown: | ||
docker-compose -f docker-compose.local.yml down -v --rmi all | ||
|
||
login: | ||
docker login $(REGISTRY) -u nologin -p $(SCW_SECRET_TOKEN) | ||
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' | ||
|
||
build-classic: | ||
docker build -t $(IMAGE_NAME):$(VERSION) . | ||
build-scw: | ||
docker build -t $(TAG) . | ||
push: | ||
@make build-scw | ||
@make login | ||
docker push $(TAG) | ||
pull: | ||
@make build-scw | ||
docker pull $(TAG) | ||
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' | ||
|
||
# Bundle commands | ||
create-database: | ||
docker-compose run app bundle exec rails db:create | ||
run-migrations: | ||
docker-compose run app bundle exec rails db:migrate | ||
# Create seeds | ||
create-seeds: | ||
docker-compose run app bundle exec rails 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' | ||
|
||
# Database commands | ||
# Restore dump | ||
restore-dump: | ||
bundle exec rake restore_dump | ||
bundle exec rake restore_dump | ||
|
||
# Start commands seperated by context | ||
start: | ||
docker-compose up | ||
shell: | ||
docker-compose -f docker-compose.local.yml exec app /bin/bash | ||
|
||
start-dumped-decidim: | ||
@make create-database | ||
@make -i restore-dump | ||
@make run-migrations | ||
@make start | ||
start-seeded-decidim: | ||
@make create-database | ||
@make run-migrations | ||
@make create-seeds | ||
@make start | ||
start-clean-decidim: | ||
@make create-database | ||
@make run-migrations | ||
@make start | ||
restart: | ||
docker-compose -f docker-compose.local.yml up -d | ||
|
||
# Utils commands | ||
rails-console: | ||
docker exec -it decidim-app_app_1 rails c | ||
connect-app: | ||
docker exec -it decidim-app_app_1 bash | ||
status: | ||
docker-compose -f docker-compose.local.yml ps | ||
|
||
# Stop and delete commands | ||
stop: | ||
docker-compose down | ||
delete: | ||
@make stop | ||
docker volume prune | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
version: '3' | ||
services: | ||
database: | ||
image: postgres | ||
volumes: | ||
- pg-data:/var/lib/postgresql/data | ||
environment: | ||
- POSTGRES_HOST_AUTH_METHOD=trust | ||
memcached: | ||
image: memcached | ||
ports: | ||
- "11211:11211" | ||
redis: | ||
image: redis | ||
ports: | ||
- "6379:6379" | ||
volumes: | ||
- redis-data:/var/lib/redis/data | ||
sidekiq: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.local | ||
command: [ "bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml" ] | ||
environment: | ||
- DATABASE_HOST=database | ||
- DATABASE_USERNAME=postgres | ||
- DECIDIM_HOST=localhost | ||
- REDIS_URL=redis://redis:6379 | ||
- MEMCACHE_SERVERS=memcached:11211 | ||
- RAILS_SERVE_STATIC_FILES=true | ||
- RAILS_LOG_TO_STDOUT=true | ||
- ASSET_HOST=localhost:3000 | ||
- FORCE_SSL=1 | ||
- ENABLE_LETTER_OPENER=1 | ||
- SEED=true | ||
- DEFACE_ENABLED=false | ||
- QUESTION_CAPTCHA_HOST= | ||
depends_on: | ||
- app | ||
volumes: | ||
- .:/app | ||
links: | ||
- database | ||
- redis | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.local | ||
environment: | ||
- DATABASE_HOST=database | ||
- DATABASE_USERNAME=postgres | ||
- DECIDIM_HOST=localhost | ||
- REDIS_URL=redis://redis:6379 | ||
- MEMCACHE_SERVERS=memcached:11211 | ||
- RAILS_SERVE_STATIC_FILES=true | ||
- RAILS_LOG_TO_STDOUT=true | ||
- ASSET_HOST=localhost:3000 | ||
- FORCE_SSL=1 | ||
- ENABLE_LETTER_OPENER=1 | ||
- SEED=true | ||
- DEFACE_ENABLED=false | ||
- QUESTION_CAPTCHA_HOST= | ||
volumes: | ||
- .:/app | ||
ports: | ||
- 3000:3000 | ||
depends_on: | ||
- database | ||
- redis | ||
- memcached | ||
|
||
volumes: | ||
app-data: { } | ||
pg-data: { } | ||
redis-data: { } |