Skip to content

Commit

Permalink
create default hosts files if missing, add base64 to gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Apr 25, 2024
1 parent 4343fa1 commit 98bda90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ LABEL maintainer="Mike Glenn <[email protected]>"
LABEL ilude-project=joyride

RUN \
mkdir -p /app /etc/hosts.d /etc/dnsmasq.d \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /etc/gemrc \
&& apk add --no-cache \
bash \
dnsmasq \
shadow \
tzdata \
mkdir -p /app /etc/hosts.d /etc/dnsmasq.d && \
touch /etc/hosts.d/hosts && \
touch /etc/dnsmasq.d/hosts && \
echo 'install: --no-document' >> /etc/gemrc && \
echo 'update: --no-document' >> /etc/gemrc && \
apk add --no-cache \
bash \
dnsmasq \
shadow \
tzdata \
&& rm -rf \
/usr/lib/ruby/gems/*/cache/* \
/root/.gem/ \
Expand Down
1 change: 1 addition & 0 deletions app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'

gem 'base64'
gem 'docker-api'
gem 'rufus-scheduler'
17 changes: 12 additions & 5 deletions app/joyride.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@

locator = {}

log = Logger.new($stdout)
log = Logger.new($stdout)
log.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }

generator = Joyride::DnsGenerator.new(log)
file_path = "/etc/hosts.d/hosts"
begin
File.new(file_path, "w") if !File.exist?(file_path)
rescue => ex
log.warn("Error creating file: #{ex.message}")
end

generator = Joyride::DnsGenerator.new(log)
context = Joyride::Context.new(log)

define_singleton_method("log") { log }
Expand All @@ -29,16 +36,16 @@

scheduler.every '3s', :first => :now, :mutex => context.mutex do
Docker::Event.since(context.updated_at, until: Time.now.to_i) {|event| context.process_event(event)}

if context.dirty?
generator.process(context)
context.reset()
end
end

Kernel.trap( "INT" ) do
Kernel.trap( "INT" ) do
scheduler.shutdown
log.info "Joyride has ended!"
end

scheduler.join()
scheduler.join()

0 comments on commit 98bda90

Please sign in to comment.