Sinatra simple is built to provide a simple configured development environment to get started with ruby sinatra web framework fast and efficently. It also comes with dockerfile that may come in handy when one wants to deploy docker images to production or may be use docker images for serving application in development.
I assume, you've ruby
preinstalled.
First get sinatra simple repository using the following command:
$ git clone https://github.com/reyadussalahin/sinatra-simple.git <your-webapp>
$ cd <your-webapp>
# install bundler
$ gem install bundler
# now, install gems listed in Gemfiles
$ bundle install
$ rerun "rackup -o 0.0.0.0 -p 8000"
check your web app by entering the url 127.0.0.1:8000
To use in production you may want to choose puma
as your server rather than using builtin webrick
server. After installing you can run your production server as follows:
$ rackup -s puma -o 0.0.0.0 -p 8000
Before following the steps below, you must perform the step from getting started section:
After performing Get sinatra-simple
, you may do as follows:
I assume that, you've docker installed in your machine.
Create a docker image using the following command:
$ docker build --tag=<app-image-tag> .
Now you can use the image as both development container and production use.
Run the following command to start web server for development env:
$ docker run --name=<app-container-dev> -v $PWD:/App -v /App/.bundle -p 127.0.0.1:8000:80 -dit <app-image-tag> rerun "rackup -o 0.0.0.0 -p 8000"
This will create a volume mounting your project directory as /App
inside docker container. So, any changes made in your current directory i.e. project root will be visible inside container <app-container-dev>
.
After you're done with all the features and fixes, run docker build command again:
$ docker build --tag=<app-image-new-tag> .
Now, psuh the container to docker hub or your selected docker registry using the following command
$ docker push <app-image-new-tag>
Now, you can pull the docker image from any cloud server and start it using the following command as follows:
$ docker pull <app-image-new-tag>
$ docker run --name=<app-container-production> -p <host>:<port>:80 <app-image-new-tag>
Voila! you're done deploying your first sinatra app in production using docker conatiner!
[Caution: I would advice not to use puma
or webrick
as your front server, rather you should use nginx
as a proxy in front of these servers.]
To learn about the project license, visit here.
This project is beginner friendly and open for contributing. So, any improvements, issues or feature requests are very much welcome.