Skip to content

Commit

Permalink
docker-compose.yml + redis (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmahyde authored Nov 20, 2023
1 parent 4ce8c09 commit 9fe5ad2
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
FROM ruby:3.2-bullseye AS sinatra_bundle

COPY Gemfile /app/Gemfile
ENV APP_HOME /app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

WORKDIR /app
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev vim

ADD Gemfile Gemfile
ENV BUNDLE_PATH /gem_cache
ENV GEM_PATH /gem_cache
ENV GEM_HOME /gem_cache

RUN gem install bundler
RUN bundle install
COPY . /app

ADD . /app
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ gem 'puma'
gem 'sinatra'
gem 'discordrb'
gem 'rspec'
gem "awesome_print", "~> 1.9"
gem "redis", '~> 5.0'
gem 'connection_pool', '~> 2.4'

group :development do
gem 'awesome_print', '~> 1.9'
gem 'dotenv', groups: [:development, :test]
end


16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
awesome_print (1.9.2)
connection_pool (2.4.1)
diff-lcs (1.5.0)
discordrb (3.5.0)
discordrb-webhooks (~> 3.5.0)
Expand All @@ -11,8 +12,7 @@ GEM
websocket-client-simple (>= 0.3.0)
discordrb-webhooks (3.5.0)
rest-client (>= 2.0.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
domain_name (0.6.20231109)
dotenv (2.8.1)
event_emitter (0.2.6)
ffi (1.16.3)
Expand All @@ -25,14 +25,18 @@ GEM
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
netrc (0.11.0)
nio4r (2.5.9)
nio4r (2.6.0)
opus-ruby (1.0.1)
ffi
puma (6.4.0)
nio4r (~> 2.0)
rack (2.2.8)
rack-protection (3.1.0)
rack (~> 2.2, >= 2.2.4)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.18.0)
connection_pool
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -58,23 +62,21 @@ GEM
rack-protection (= 3.1.0)
tilt (~> 2.0)
tilt (2.3.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
websocket (1.2.10)
websocket-client-simple (0.8.0)
event_emitter
websocket

PLATFORMS
aarch64-linux
x86_64-darwin-23

DEPENDENCIES
awesome_print (~> 1.9)
connection_pool (~> 2.4)
discordrb
dotenv
puma
redis (~> 5.0)
rspec
sinatra

Expand Down
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require './app'
require './dula_peep_bot'

run Sinatra::Application.run!
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
TZ: ${TZ}
# POSTGRES_URL: ${POSTGRES_URL}
depends_on:
- gem_cache
- redis
networks:
- botnetwork
Expand All @@ -27,6 +28,12 @@ services:
- "6379:6379"
networks:
- botnetwork
gem_cache:
image: busybox
volumes:
- /gem_cache
networks:
- botnetwork

networks:
botnetwork:
6 changes: 4 additions & 2 deletions dula_peep_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

class DulaPeepBot
def initialize(token:)
@api = Api.new(bot.token)
@api = Api.new(token)
@bot = Discordrb::Bot.new(
token: token,
intents: [:server_messages]
)

CommandDefinitions.new(bot, api)
CommandDefinitions.new(@bot, @api)
end

attr_reader :bot, :api
end

APP = DulaPeepBot.new(token: TOKEN)
Expand Down
9 changes: 9 additions & 0 deletions lib/api.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require 'redis'
require 'connection_pool'
require_relative './channel'

class Api
def initialize(bot_token)
@bot_token = bot_token
end

# @return [ConnectionPool::Wrapper] the redis connection_pool instance
def self.redis
@redis ||= ConnectionPool::Wrapper.new do
Redis.new url: ENV.fetch('REDIS_URL', nil)
end
end

# @param [Numeric] days
def delete_messages(channel_id, days)
message_ids = Channel.get_message_ids(
Expand Down
2 changes: 1 addition & 1 deletion lib/command_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative 'register_commands'

class CommandDefinitions
extend RegisterCommands
include RegisterCommands

def initialize(bot, api)
@bot = bot
Expand Down

0 comments on commit 9fe5ad2

Please sign in to comment.