Class: Dockerize
- Inherits:
-
Object
- Object
- Dockerize
- Defined in:
- lib/dockerize-ruby.rb
Class Method Summary collapse
Class Method Details
.dockercompose ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dockerize-ruby.rb', line 24 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 ports: - \"5432:5432\" environment: POSTGRES_PASSWORD: password web: build: . command: bash -c \"rm -f tmp/pids/server.pid && bundle exec rails db:migrate && bundle exec rails s -p 3000 -b '0.0.0.0'\" volumes: - .:/myapp ports: - \"3000:3000\" depends_on: - db""" end end |
.dockerfile(options: {}) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dockerize-ruby.rb', line 2 def self.dockerfile(options: {}) File.open("Dockerfile", 'w') do |file| file.write """# syntax=docker/dockerfile:1 FROM ruby:#{[:ruby_version]} 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 gem install bundler -v #{[:bundler_version]} 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 |
.entrypoint ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dockerize-ruby.rb', line 48 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 |