-
Notifications
You must be signed in to change notification settings - Fork 3
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
hanshal101
wants to merge
2
commits into
buildsafedev:main
Choose a base branch
from
hanshal101:ruby-server-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
bsf-result/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'activesupport', '~> 7.0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.