Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile for the Ruby-Sinatra generator #9299

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void processOpts() {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'

gem "webrick"
gem "sinatra"
gem "sinatra-cross_origin"
gem "sinatra-cross_origin"
Original file line number Diff line number Diff line change
@@ -1,29 +1,65 @@
# 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
out more about both the spec and the framework at http://swagger.io. For more information about
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:

```
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
```

To run the generated server, please run the following:

```
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.

```
rackup -p 4567 config.ru
docker build . --tag "container_name"
```

In your [swagger ui](https://github.com/swagger-api/swagger-ui), put in the following URL:
### Run the docker image

```
http://localhost:4567/resources.json
docker run -it --rm -p 8080:8080 "container_name"
```

Voila!