Skip to content

Commit

Permalink
add dockerfile for ror, fix template issue (OpenAPITools#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Aug 2, 2018
1 parent 72688ad commit 6d370e9
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void processOpts() {
additionalProperties.put("isDBSQLite", Boolean.TRUE);
}

supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
supportingFiles.add(new SupportingFile("Gemfile.mustache", "", "Gemfile"));
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
supportingFiles.add(new SupportingFile("Rakefile", "", "Rakefile"));
supportingFiles.add(new SupportingFile("config.ru", "", "config.ru"));
Expand Down Expand Up @@ -155,7 +155,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("application.rb", configFolder, "application.rb"));
supportingFiles.add(new SupportingFile("boot.rb", configFolder, "boot.rb"));
supportingFiles.add(new SupportingFile("cable.yml", configFolder, "cable.yml"));
supportingFiles.add(new SupportingFile("database.yml", configFolder, "database.yml"));
supportingFiles.add(new SupportingFile("database.mustache", configFolder, "database.yml"));
supportingFiles.add(new SupportingFile("environment.rb", configFolder, "environment.rb"));
supportingFiles.add(new SupportingFile("puma.rb", configFolder, "puma.rb"));
supportingFiles.add(new SupportingFile("routes.mustache", configFolder, "routes.rb"));
Expand All @@ -181,6 +181,8 @@ public void processOpts() {
supportingFiles.add(new SupportingFile(".keep", socketsFolder, ".keep"));
supportingFiles.add(new SupportingFile("restart.txt", tmpFolder, "restart.txt"));
supportingFiles.add(new SupportingFile(".keep", vendorFolder, ".keep"));
supportingFiles.add(new SupportingFile("Dockerfile", "", "Dockerfile"));
supportingFiles.add(new SupportingFile("docker-entrypoint.sh", "", "docker-entrypoint.sh"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ruby:2.5-alpine

ENV BUILD_PACKAGES="curl-dev ruby-dev build-base" \
DEV_PACKAGES="zlib-dev libxml2-dev libxslt-dev tzdata yaml-dev sqlite-dev" \
RUBY_PACKAGES="ruby-json yaml nodejs"

RUN apk update && \
apk upgrade && \
apk add --no-cache --update\
$BUILD_PACKAGES \
$DEV_PACKAGES \
$RUBY_PACKAGES && \
mkdir -p /usr/src/myapp

WORKDIR /usr/src/myapp

COPY Gemfile ./
RUN gem install bundler
RUN bundle config build.nokogiri --use-system-libraries && \
bundle install --jobs=4 --retry=10 --clean

COPY . ./
RUN chmod +x bin/rails

COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["bin/rails", "s", "-b", "0.0.0.0"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

if [ "$1" = 'bin/rails' ] && [ "$2" = 's' ]; then
rm -f /myapp/tmp/pids/server.pid
bin/rails db:migrate
fi

exec "$@"
29 changes: 29 additions & 0 deletions samples/server/petstore/ruby-on-rails/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ruby:2.5-alpine

ENV BUILD_PACKAGES="curl-dev ruby-dev build-base" \
DEV_PACKAGES="zlib-dev libxml2-dev libxslt-dev tzdata yaml-dev sqlite-dev" \
RUBY_PACKAGES="ruby-json yaml nodejs"

RUN apk update && \
apk upgrade && \
apk add --no-cache --update\
$BUILD_PACKAGES \
$DEV_PACKAGES \
$RUBY_PACKAGES && \
mkdir -p /usr/src/myapp

WORKDIR /usr/src/myapp

COPY Gemfile ./
RUN gem install bundler
RUN bundle config build.nokogiri --use-system-libraries && \
bundle install --jobs=4 --retry=10 --clean

COPY . ./
RUN chmod +x bin/rails

COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["bin/rails", "s", "-b", "0.0.0.0"]
6 changes: 0 additions & 6 deletions samples/server/petstore/ruby-on-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0'
{{#isDBSQLite}}
# Use sqlite as the database for Active Record
gem 'sqlite3', '~> 1.3'
{{/isDBSQLite}}
{{#isDBMySQL}}
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
{{/isDBMySQL}}
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand Down
58 changes: 0 additions & 58 deletions samples/server/petstore/ruby-on-rails/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,3 @@
{{#isDBMySQL}}
# MySQL. Versions 5.0 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password:
socket: /tmp/mysql.sock

development:
<<: *default
database: api_demo_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: api_demo_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: api_demo_production
username: api_demo
password: <%= ENV['API_DEMO_DATABASE_PASSWORD'] %>
{{/isDBMySQL}}
{{#isDBSQLite}}
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
Expand All @@ -77,4 +20,3 @@ production:
database: db/production.sqlite3
pool: 5
timeout: 5000
{{/isDBSQLite}}
9 changes: 9 additions & 0 deletions samples/server/petstore/ruby-on-rails/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

if [ "$1" = 'bin/rails' ] && [ "$2" = 's' ]; then
rm -f /myapp/tmp/pids/server.pid
bin/rails db:migrate
fi

exec "$@"
62 changes: 62 additions & 0 deletions samples/server/petstore/ruby-on-rails/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opoenapitools</groupId>
<artifactId>RORPetstoreServerTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>ROR Petstore Server</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>bundle-install</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bundle</executable>
<arguments>
<argument>install</argument>
<argument>--path</argument>
<argument>vendor/bundle</argument>
</arguments>
</configuration>
</execution>
<!--<execution>
<id>bundle-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bundle</executable>
<arguments>
<argument>exec</argument>
<argument>rspec</argument>
</arguments>
</configuration>
</execution>-->
</executions>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 6d370e9

Please sign in to comment.