Skip to content

Instantly share code, notes, and snippets.

@igkuz

igkuz/Dockerfile Secret

Last active July 17, 2018 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igkuz/87d2087ccf333870c50cbc04ebfedf04 to your computer and use it in GitHub Desktop.
Save igkuz/87d2087ccf333870c50cbc04ebfedf04 to your computer and use it in GitHub Desktop.
Socket Activation systemd service with Unicorn & Nginx
require 'bundler/setup'
Bundler.require
require 'rack'
app = Proc.new do |env|
['200', {'Content-Type' => 'text/html'}, ['Simple app for test']]
end
run app
FROM ruby:2.4
RUN mkdir /app
COPY Gemfile Gemfile.lock /app/
WORKDIR /app
RUN bundle install
ADD config.ru /app/
ADD unicorn.rb /app/
CMD ["bundle", "exec", "--keep-file-descriptors", "unicorn", "-c", "unicorn.rb"]
source 'https://rubygems.org'
gem 'unicorn'
gem 'rack'
GEM
remote: https://rubygems.org/
specs:
kgio (2.11.2)
rack (2.0.5)
raindrops (0.19.0)
unicorn (5.4.0)
kgio (~> 2.6)
raindrops (~> 0.7)
PLATFORMS
ruby
DEPENDENCIES
rack
unicorn
BUNDLED WITH
1.16.1
[Unit]
Description=Socket Activation with Unicorn Service
After=network.target sact-test.socket
Requires=sact-test.socket
[Service]
ExecStart=/usr/bin/docker run --user 1001 --rm --name sact-test-n -v '/apps/sact/sact-git/tmp:/app/tmp' -e 'SOCKET_FILE=/app/tmp/sockets/unicorn.sock' sact-test
ExecStartPost=/bin/sleep 1
SyslogIdentifier=sact-test-docker
ExecStop=/usr/bin/docker stop sact-test-n
[Unit]
Requires=sact-test-docker.service
After=sact-test-docker.service
[Service]
SyslogIdentifier=sact-test-docker
ExecStart=/lib/systemd/systemd-socket-proxyd /apps/sact/sact-git/tmp/sockets/unicorn.sock
[Unit]
Description=Socket Activation with Unicorn
PartOf=sact-test.service
[Socket]
SocketUser=sact
SocketGroup=sact
SocketMode=0777
Backlog=2048
ListenStream=/apps/sact/sact-git/tmp/sockets/unicorn-proxy.sock
[Install]
WantedBy=sockets.target
upstream app_sact {
server unix:/apps/sact/sact-git/tmp/sockets/unicorn-proxy.sock;
}
server {
listen 80;
charset utf-8;
set $application_name "sact";
location / {
try_files $uri $uri.html @application;
}
location @application {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_hide_header X-User-Id;
proxy_redirect off;
proxy_pass http://app_$application_name;
break;
}
}
worker_processes 2
timeout 30
listen ENV['SOCKET_FILE'] || 8080, backlog: 2048
working_directory ENV['APP_PATH'] || '/app/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment