Class: Dockerize

Inherits:
Object
  • Object
show all
Defined in:
lib/dockerize-ruby.rb

Class Method Summary collapse

Class Method Details

.dockercomposeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dockerize-ruby.rb', line 23

def self.dockercompose
  File.open("docker-compose.yml", 'w') do |file|
    file.write """version: \"3.9\"
services:
db:
  image: postgres
  volumes:
    - ./tmp/db:/var/lib/postgresql/data
  environment:
    POSTGRES_PASSWORD: password
web:
  build: .
  command: bash -c \"rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'\"
  volumes:
    - .:/myapp
  ports:
    - \"3000:3000\"
  depends_on:
    - db"""
  end
end

.dockerfileObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dockerize-ruby.rb', line 2

def self.dockerfile
  File.open("Dockerfile", 'w') do |file|
    file.write """# syntax=docker/dockerfile:1
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT [\"entrypoint.sh\"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD [\"rails\", \"server\", \"-b\", \"0.0.0.0\"]"""
  end
end

.entrypointObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dockerize-ruby.rb', line 45

def self.entrypoint
  File.open("entrypoint.sh", 'w') do |file|
    file.write """#!/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 \"$@\""""
  end
end