Skip to content

Commit f32398a

Browse files
authored
add dockerfile for ror, fix template issue (#718)
1 parent f0425d7 commit f32398a

10 files changed

Lines changed: 142 additions & 66 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyOnRailsServerCodegen.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void processOpts() {
122122
additionalProperties.put("isDBSQLite", Boolean.TRUE);
123123
}
124124

125-
supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
125+
supportingFiles.add(new SupportingFile("Gemfile.mustache", "", "Gemfile"));
126126
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
127127
supportingFiles.add(new SupportingFile("Rakefile", "", "Rakefile"));
128128
supportingFiles.add(new SupportingFile("config.ru", "", "config.ru"));
@@ -155,7 +155,7 @@ public void processOpts() {
155155
supportingFiles.add(new SupportingFile("application.rb", configFolder, "application.rb"));
156156
supportingFiles.add(new SupportingFile("boot.rb", configFolder, "boot.rb"));
157157
supportingFiles.add(new SupportingFile("cable.yml", configFolder, "cable.yml"));
158-
supportingFiles.add(new SupportingFile("database.yml", configFolder, "database.yml"));
158+
supportingFiles.add(new SupportingFile("database.mustache", configFolder, "database.yml"));
159159
supportingFiles.add(new SupportingFile("environment.rb", configFolder, "environment.rb"));
160160
supportingFiles.add(new SupportingFile("puma.rb", configFolder, "puma.rb"));
161161
supportingFiles.add(new SupportingFile("routes.mustache", configFolder, "routes.rb"));
@@ -181,6 +181,8 @@ public void processOpts() {
181181
supportingFiles.add(new SupportingFile(".keep", socketsFolder, ".keep"));
182182
supportingFiles.add(new SupportingFile("restart.txt", tmpFolder, "restart.txt"));
183183
supportingFiles.add(new SupportingFile(".keep", vendorFolder, ".keep"));
184+
supportingFiles.add(new SupportingFile("Dockerfile", "", "Dockerfile"));
185+
supportingFiles.add(new SupportingFile("docker-entrypoint.sh", "", "docker-entrypoint.sh"));
184186
}
185187

186188
@Override
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM ruby:2.5-alpine
2+
3+
ENV BUILD_PACKAGES="curl-dev ruby-dev build-base" \
4+
DEV_PACKAGES="zlib-dev libxml2-dev libxslt-dev tzdata yaml-dev sqlite-dev" \
5+
RUBY_PACKAGES="ruby-json yaml nodejs"
6+
7+
RUN apk update && \
8+
apk upgrade && \
9+
apk add --no-cache --update\
10+
$BUILD_PACKAGES \
11+
$DEV_PACKAGES \
12+
$RUBY_PACKAGES && \
13+
mkdir -p /usr/src/myapp
14+
15+
WORKDIR /usr/src/myapp
16+
17+
COPY Gemfile ./
18+
RUN gem install bundler
19+
RUN bundle config build.nokogiri --use-system-libraries && \
20+
bundle install --jobs=4 --retry=10 --clean
21+
22+
COPY . ./
23+
RUN chmod +x bin/rails
24+
25+
COPY docker-entrypoint.sh /usr/local/bin/
26+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
27+
ENTRYPOINT ["docker-entrypoint.sh"]
28+
29+
CMD ["bin/rails", "s", "-b", "0.0.0.0"]

modules/openapi-generator/src/main/resources/ruby-on-rails-server/Gemfile renamed to modules/openapi-generator/src/main/resources/ruby-on-rails-server/Gemfile.mustache

File renamed without changes.

modules/openapi-generator/src/main/resources/ruby-on-rails-server/database.yml renamed to modules/openapi-generator/src/main/resources/ruby-on-rails-server/database.mustache

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" = 'bin/rails' ] && [ "$2" = 's' ]; then
5+
rm -f /myapp/tmp/pids/server.pid
6+
bin/rails db:migrate
7+
fi
8+
9+
exec "$@"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM ruby:2.5-alpine
2+
3+
ENV BUILD_PACKAGES="curl-dev ruby-dev build-base" \
4+
DEV_PACKAGES="zlib-dev libxml2-dev libxslt-dev tzdata yaml-dev sqlite-dev" \
5+
RUBY_PACKAGES="ruby-json yaml nodejs"
6+
7+
RUN apk update && \
8+
apk upgrade && \
9+
apk add --no-cache --update\
10+
$BUILD_PACKAGES \
11+
$DEV_PACKAGES \
12+
$RUBY_PACKAGES && \
13+
mkdir -p /usr/src/myapp
14+
15+
WORKDIR /usr/src/myapp
16+
17+
COPY Gemfile ./
18+
RUN gem install bundler
19+
RUN bundle config build.nokogiri --use-system-libraries && \
20+
bundle install --jobs=4 --retry=10 --clean
21+
22+
COPY . ./
23+
RUN chmod +x bin/rails
24+
25+
COPY docker-entrypoint.sh /usr/local/bin/
26+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
27+
ENTRYPOINT ["docker-entrypoint.sh"]
28+
29+
CMD ["bin/rails", "s", "-b", "0.0.0.0"]

samples/server/petstore/ruby-on-rails/Gemfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@ source 'https://rubygems.org'
33

44
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
55
gem 'rails', '~> 5.0.0'
6-
{{#isDBSQLite}}
76
# Use sqlite as the database for Active Record
87
gem 'sqlite3', '~> 1.3'
9-
{{/isDBSQLite}}
10-
{{#isDBMySQL}}
11-
# Use mysql as the database for Active Record
12-
gem 'mysql2', '>= 0.3.18', '< 0.5'
13-
{{/isDBMySQL}}
148
# Use Puma as the app server
159
gem 'puma', '~> 3.0'
1610
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,3 @@
1-
{{#isDBMySQL}}
2-
# MySQL. Versions 5.0 and up are supported.
3-
#
4-
# Install the MySQL driver
5-
# gem install mysql2
6-
#
7-
# Ensure the MySQL gem is defined in your Gemfile
8-
# gem 'mysql2'
9-
#
10-
# And be sure to use new-style password hashing:
11-
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
12-
#
13-
default: &default
14-
adapter: mysql2
15-
encoding: utf8
16-
pool: 5
17-
username: root
18-
password:
19-
socket: /tmp/mysql.sock
20-
21-
development:
22-
<<: *default
23-
database: api_demo_development
24-
25-
# Warning: The database defined as "test" will be erased and
26-
# re-generated from your development database when you run "rake".
27-
# Do not set this db to the same as development or production.
28-
test:
29-
<<: *default
30-
database: api_demo_test
31-
32-
# As with config/secrets.yml, you never want to store sensitive information,
33-
# like your database password, in your source code. If your source code is
34-
# ever seen by anyone, they now have access to your database.
35-
#
36-
# Instead, provide the password as a unix environment variable when you boot
37-
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
38-
# for a full rundown on how to provide these environment variables in a
39-
# production deployment.
40-
#
41-
# On Heroku and other platform providers, you may have a full connection URL
42-
# available as an environment variable. For example:
43-
#
44-
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
45-
#
46-
# You can use this database configuration with:
47-
#
48-
# production:
49-
# url: <%= ENV['DATABASE_URL'] %>
50-
#
51-
production:
52-
<<: *default
53-
database: api_demo_production
54-
username: api_demo
55-
password: <%= ENV['API_DEMO_DATABASE_PASSWORD'] %>
56-
{{/isDBMySQL}}
57-
{{#isDBSQLite}}
581
# SQLite version 3.x
592
# gem install sqlite3-ruby (not necessary on OS X Leopard)
603
development:
@@ -77,4 +20,3 @@ production:
7720
database: db/production.sqlite3
7821
pool: 5
7922
timeout: 5000
80-
{{/isDBSQLite}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" = 'bin/rails' ] && [ "$2" = 's' ]; then
5+
rm -f /myapp/tmp/pids/server.pid
6+
bin/rails db:migrate
7+
fi
8+
9+
exec "$@"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.opoenapitools</groupId>
4+
<artifactId>RORPetstoreServerTests</artifactId>
5+
<packaging>pom</packaging>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>ROR Petstore Server</name>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<artifactId>maven-dependency-plugin</artifactId>
12+
<executions>
13+
<execution>
14+
<phase>package</phase>
15+
<goals>
16+
<goal>copy-dependencies</goal>
17+
</goals>
18+
<configuration>
19+
<outputDirectory>${project.build.directory}</outputDirectory>
20+
</configuration>
21+
</execution>
22+
</executions>
23+
</plugin>
24+
<plugin>
25+
<groupId>org.codehaus.mojo</groupId>
26+
<artifactId>exec-maven-plugin</artifactId>
27+
<version>1.2.1</version>
28+
<executions>
29+
<execution>
30+
<id>bundle-install</id>
31+
<phase>pre-integration-test</phase>
32+
<goals>
33+
<goal>exec</goal>
34+
</goals>
35+
<configuration>
36+
<executable>bundle</executable>
37+
<arguments>
38+
<argument>install</argument>
39+
<argument>--path</argument>
40+
<argument>vendor/bundle</argument>
41+
</arguments>
42+
</configuration>
43+
</execution>
44+
<!--<execution>
45+
<id>bundle-test</id>
46+
<phase>integration-test</phase>
47+
<goals>
48+
<goal>exec</goal>
49+
</goals>
50+
<configuration>
51+
<executable>bundle</executable>
52+
<arguments>
53+
<argument>exec</argument>
54+
<argument>rspec</argument>
55+
</arguments>
56+
</configuration>
57+
</execution>-->
58+
</executions>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>

0 commit comments

Comments
 (0)