diff --git a/.env.example b/.env.example index b667033..b522814 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,8 @@ SMTP_DOMAIN=example.com SMTP_AUTH_METHOD=plain SMTP_ENABLE_STARTTLS=auto +REDIS_URL='redis://localhost:6379/1' + LDAP_HOST=localhost LDAP_PORT=389 LDAP_ADMIN_PASSWORD=passthebutter diff --git a/Dockerfile b/Dockerfile index 0eead4c..f2692e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,13 @@ # syntax=docker/dockerfile:1 FROM ruby:2.7.6 -RUN apt-get update -qq && apt-get install -y curl ldap-utils + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN apt-get update -qq && apt-get install -y --no-install-recommends curl \ + ldap-utils tini RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - RUN apt-get update && apt-get install -y nodejs + WORKDIR /akkounts COPY Gemfile /akkounts/Gemfile COPY Gemfile.lock /akkounts/Gemfile.lock @@ -12,11 +17,5 @@ RUN gem install foreman RUN npm install -g yarn RUN yarn install -# Add a script to be executed every time the container starts. -COPY docker/entrypoint.sh /usr/bin/ -RUN chmod +x /usr/bin/entrypoint.sh -ENTRYPOINT ["entrypoint.sh"] +ENTRYPOINT ["/usr/bin/tini", "--"] EXPOSE 3000 - -# Configure the main process to run when running the image -CMD ["bin", "dev"] diff --git a/README.md b/README.md index b2e7205..6ff6c17 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ so: 1. Make sure [Docker Compose is installed][1] and Docker is running (included in Docker Desktop) -2. Uncomment the `web` section in `docker-compose.yml` +2. Uncomment the `redis`, `web`, and `sidekiq` sections in `docker-compose.yml` 3. Run `docker compose up` and wait until 389ds announces its successful start in the log output 4. `docker-compose exec ldap dsconf localhost backend create --suffix="dc=kosmos,dc=org" --be-name="dev"` diff --git a/app/models/setting.rb b/app/models/setting.rb index e86a79c..dff6425 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -2,6 +2,13 @@ class Setting < RailsSettings::Base cache_prefix { "v1" } + # + # Internal services + # + + field :redis_url, type: :string, readonly: true, + default: ENV["REDIS_URL"] || "redis://localhost:6379/0" + # # Registrations # diff --git a/app/models/user.rb b/app/models/user.rb index d8ebee8..5b40929 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,6 +65,10 @@ class User < ApplicationRecord end end + def send_devise_notification(notification, *args) + devise_mailer.send(notification, self, *args).deliver_later + end + def reset_password(new_password, new_password_confirmation) self.password = new_password self.password_confirmation = new_password_confirmation diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 0000000..044cec0 --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,5 @@ +require_relative "../../app/models/setting" + +Sidekiq.configure_server do |config| + config.redis = { url: Setting.redis_url } +end diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 615bb16..adc65b2 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -1,3 +1,4 @@ :concurrency: 2 :queues: - default + - mailers diff --git a/docker-compose.yml b/docker-compose.yml index a4d5a29..8a0de47 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,11 +3,67 @@ services: image: 4teamwork/389ds:latest volumes: - ./tmp/389ds:/data + networks: + - external_network + - internal_network ports: - "389:3389" environment: DS_DM_PASSWORD: passthebutter SUFFIX_NAME: "dc=kosmos,dc=org" + + # redis: + # restart: always + # image: redis:7-alpine + # networks: + # - internal_network + # healthcheck: + # test: ['CMD', 'redis-cli', 'ping'] + # volumes: + # - ./tmp/redis:/data + + # web: + # build: . + # tty: true + # command: bash -c "rm -f /akkounts/tmp/pids/server.pid; bin/dev" + # volumes: + # - .:/akkounts + # networks: + # - external_network + # - internal_network + # ports: + # - "3000:3000" + # environment: + # RAILS_ENV: development + # REDIS_URL: redis://redis:6379/0 + # LDAP_HOST: ldap + # LDAP_PORT: 3389 + # LDAP_ADMIN_PASSWORD: passthebutter + # LDAP_USE_TLS: "false" + # depends_on: + # - ldap + # - redis + + # sidekiq: + # build: . + # command: bash -c "bundle exec sidekiq -C config/sidekiq.yml" + # volumes: + # - .:/akkounts + # networks: + # - internal_network + # environment: + # RAILS_ENV: development + # REDIS_URL: redis://redis:6379/0 + # LDAP_HOST: ldap + # LDAP_PORT: 3389 + # LDAP_ADMIN_PASSWORD: passthebutter + # LDAP_USE_TLS: "false" + # LAUNCHY_DRY_RUN: true + # BROWSER: /dev/null + # depends_on: + # - ldap + # - redis + # phpldapadmin: # image: osixia/phpldapadmin:0.9.0 # ports: @@ -16,19 +72,8 @@ services: # PHPLDAPADMIN_HTTPS: false # PHPLDAPADMIN_LDAP_HOSTS: "#PYTHON2BASH:[{'ldap': [{'server': [{'tls': False}, {'port': 3389}]}, {'login': [{'bind_id': 'cn=Directory Manager'}, {'bind_pass': 'passthebutter'}]}]}]" # PHPLDAPADMIN_LDAP_CLIENT_TLS: false - # web: - # build: . - # tty: true - # command: bash -c "sleep 5 && rm -f tmp/pids/server.pid && bin/dev" - # volumes: - # - .:/akkounts - # ports: - # - "3000:3000" - # environment: - # RAILS_ENV: development - # LDAP_HOST: ldap - # LDAP_PORT: 3389 - # LDAP_ADMIN_PASSWORD: passthebutter - # LDAP_USE_TLS: "false" - # depends_on: - # - ldap + +networks: + external_network: + internal_network: + internal: true diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100644 index 3af18f7..0000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -# Remove a potentially pre-existing server.pid for Rails. -rm -f /myapp/tmp/pids/server.pid - -# Then exec the container's main process (what's set as CMD in the Dockerfile). -exec "$@"