Skip to content

feat: add ruby server example #4

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions ruby-server-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

bsf-result/
8 changes: 8 additions & 0 deletions ruby-server-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ruby Alpine image (after using bsf dockerfile digest)
FROM ttl.sh/ruby-server:dev AS build

# Expose the application port
EXPOSE 9898

# Command to run the Ruby application
CMD ["ruby", "main.rb"]
3 changes: 3 additions & 0 deletions ruby-server-example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'activesupport', '~> 7.0'
66 changes: 66 additions & 0 deletions ruby-server-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
This is an Example Ruby repo

## Install nix
```
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

```

```
To get started using Nix, open a new shell or run `. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`
```
You can experiment if the installation was successful by runing `nix run "nixpkgs#hello"`
## Install bsf cli
nix profile install {{URL}}


## Initialize the projct
Now is the time to run `bsf init` which will generate the `bsf.hcl` and `bsf.locl` files. It also generates a bsf folder with all nix files requred to build the project.

## Add files before building
`git add . ` <- Required by nix sandboxing.

## Develop the porject
This will get you in the development shell of your application
`bsf develop`

## Interact with the project
You can checkout the ruby version
`ruby -v`
Try to install rails
`gem install rails`

## Create a base image with Ruby dependencies and using it the Dockerfile
```Dockerfile
# Ruby Alpine image (after using bsf dockerfile digest)
FROM ttl.sh/ruby-server AS build

# Install all required dependencies for Ruby gems
RUN apk add --no-cache build-base libxml2-dev libxslt-dev tzdata

WORKDIR /src

# Copy the Gemfile and Gemfile.lock into the container
COPY Gemfile Gemfile.lock /src/

# Install the required gems
RUN bundle install

# Copy the rest of the application files to the container
COPY . /src

# Expose the application port
EXPOSE 9898

# Command to run the Ruby application
CMD ["ruby", "main.rb"]
```

Lets build this image
`docker build -t ttl.sh/ruby-server:dev`

Now Run the image
`docker run -d -p 9898:9898 ttl.sh/ruby-server:dev`

## Checkout your application
`curl localhost:9898/ping` here the response should be `Pong!`
16 changes: 16 additions & 0 deletions ruby-server-example/bsf.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

packages {
development = ["[email protected]", "[email protected]", "ruby@~3.3.4", "bundler@~2.5.16"]
runtime = ["[email protected]"]
}

oci "pkgs" {
name = "ttl.sh/ruby-server"
layers = ["split(packages.runtime)", "split(packages.dev)"]
isBase = true
cmd = []
entrypoint = []
envVars = []
exposedPorts = []
importConfigs = []
}
Loading