Dockerfile for the Ruby-Sinatra generator (#9299)

* add the Dockerfile and updated the README and others.

Signed-off-by: Yasuhiro ABE <yasu-abe@u-aizu.ac.jp>

* fixed the indent to follow the coding style guide.

Signed-off-by: Yasuhiro ABE <yasu-abe@u-aizu.ac.jp>

* revised.

Signed-off-by: Yasuhiro ABE <yasu-abe@u-aizu.ac.jp>
This commit is contained in:
Yasuhiro ABE
2021-04-21 16:46:56 +09:00
committed by GitHub
parent ebc98ec848
commit d4748a7a20
4 changed files with 79 additions and 9 deletions

View File

@@ -87,6 +87,7 @@ public class RubySinatraServerCodegen extends AbstractRubyCodegen {
supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
supportingFiles.add(new SupportingFile("openapi.mustache", "", "openapi.yaml"));
supportingFiles.add(new SupportingFile("Dockerfile", "", "Dockerfile"));
}
@Override

View File

@@ -0,0 +1,32 @@
## Build libraries
FROM ruby:3.0-alpine as rubydev
## for thin or falcon
#RUN apk --no-cache add make g++ libc-dev
## for puma
#RUN apk --no-cache add make gcc libc-dev
ADD . /app
WORKDIR /app
RUN bundle config set path lib
RUN bundle install
## Build Runtime image
FROM ruby:3.0-alpine
RUN apk --no-cache add tzdata ## ca-certificates
COPY --from=rubydev /app /app
WORKDIR /app
ENV SINATRA_HOST 0.0.0.0
ENV SINATRA_PORT 8080
EXPOSE $SINATRA_PORT
RUN addgroup sinatra
RUN adduser -S -G sinatra sinatra
USER sinatra
RUN bundle config set path lib
CMD bundle exec rackup --host $SINATRA_HOST -p $SINATRA_PORT

View File

@@ -1,4 +1,5 @@
source 'https://rubygems.org'
gem "webrick"
gem "sinatra"
gem "sinatra-cross_origin"
gem "sinatra-cross_origin"

View File

@@ -1,4 +1,4 @@
# Swagger for Sinatra
# OpenAPI for Sinatra
## Overview
This is a project to provide Swagger support inside the [Sinatra](http://www.sinatrarb.com/) framework. You can find
@@ -6,24 +6,60 @@ out more about both the spec and the framework at http://swagger.io. For more i
Wordnik's APIs, please visit http://developer.wordnik.com.
## Prerequisites
You need to install ruby 1.9.3 and the following gems:
As of ruby 3.0.0, the webrick web server library was removed.
You need to install a rack-supported web server, such as webrick and thin.
The default Gemfile is as follows.
Update the name of the web server as your prefer.
```
sinatra
sinatra-cross_origin
source 'https://rubygems.org'
gem "webrick"
gem "sinatra"
gem "sinatra-cross_origin"
```
## Getting started
This sample was generated with the [OpenAPI Generator](https://github.com/openapitools/openapi-generator) project.
To generate a ruby-sinatra server for petstore.yaml, please run the following:
```
rackup -p 4567 config.ru
openapi-generator-cli generate \
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml \
-g ruby-sinatra -o code
```
In your [swagger ui](https://github.com/swagger-api/swagger-ui), put in the following URL:
To run the generated server, please run the following:
```
http://localhost:4567/resources.json
cd code/
bundle config set path lib
bundle install
bundle exec rackup -p 8080
```
You can access the application by the following URL:
```
http://localhost:8080/v2/store/inventory
```
## Docker
If you want to use a web server other than webrick, you need to edit the generated Dockerfile to prepare the compiler and the make command. Please check the comment of the Dockerfile.
To run the code on docker, you can use the Dockerfile as follows:
### Build the docker image
The "container_name" can be changed for your preferences.
```
docker build . --tag "container_name"
```
### Run the docker image
```
docker run -it --rm -p 8080:8080 "container_name"
```
Voila!