Skip to content

Commit 26afc1d

Browse files
feat(content): ruby hello world (#103)
1 parent a2f9097 commit 26afc1d

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Table of Contents:
7676
| **[Terraform NGINX hello world](containers/terraform-nginx-hello-world/README.md)** <br/> A minimal example running the base NGINX image in a serverless container deployed with Terraform. | N/A | [Terraform] |
7777
| **[Triggers with Terraform](containers/terraform-triggers/README.md)** <br/> Configuring two SQS triggers, used to trigger two containers, one public, one private. | N/A | [Terraform] |
7878
| **[gRPC HTTP2 in Go](containers/grpc-http2-go/README.md)** <br/> A Go gRPC Container using http2 | Go/Protobuf | [CLI] |
79+
| **[Ruby Hello World](containers/ruby-hello-world/)** <br/> A simple Ruby Hello world Container | Ruby | [CLI] |
7980

8081
### ⚙️ Jobs
8182

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use the official Ruby image from the Docker Hub
2+
FROM ruby:3.4.4
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy the Gemfile and Gemfile.lock into the container
8+
COPY Gemfile ./
9+
10+
# Install the dependencies
11+
RUN bundle install && bundle add rackup puma
12+
13+
# Copy the rest of the application code into the container
14+
COPY app.rb .
15+
16+
# Run the application
17+
CMD ["ruby", "app.rb"]

containers/ruby-hello-world/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'webrick'

containers/ruby-hello-world/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Ruby hello world
2+
3+
This example demonstrates the deployment of a simple Ruby http service on Scaleway Serverless Containers.
4+
5+
For this example, we will use the CLI to deploy the container, but you can use [other methods](https://www.scaleway.com/en/docs/serverless/containers/reference-content/deploy-container/).
6+
7+
## Workflow
8+
9+
Here are the different steps we are going to proceed:
10+
11+
- Quick set-up of Container Registry to host our Ruby container
12+
- Deploy the Serverless Container
13+
- Test the container
14+
15+
## Deployment
16+
17+
### Requirements
18+
19+
To complete the actions presented below, you must have:
20+
- installed and configured the [Scaleway CLI](https://www.scaleway.com/en/docs/developer-tools/scaleway-cli/quickstart/)
21+
- installed [Docker](https://docs.docker.com/engine/install/) to build the image
22+
23+
### Building the image
24+
25+
1. Run the following command in a terminal to create Container Registry namespace to store the image:
26+
27+
```bash
28+
scw registry namespace create name=hello-ruby
29+
```
30+
31+
The registry namespace information displays.
32+
33+
1. Copy the namespace endpoint (in this case, `rg.fr-par.scw.cloud/hello-ruby`).
34+
35+
1. Log into the Container Registry namespace you created using Docker:
36+
37+
```bash
38+
docker login rg.fr-par.scw.cloud/hello-ruby -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
39+
```
40+
41+
At this point, you have correctly set up Docker to be able to push your image online.
42+
43+
1. In a terminal, access this directory (containing the Dockerfile), and run the following command to build and tag the image:
44+
45+
```bash
46+
docker build --platform linux/amd64 -t rg.fr-par.scw.cloud/hello-ruby/ruby:v1 .
47+
```
48+
49+
1. Tag and push the image to the registry namespace:
50+
51+
```bash
52+
docker push rg.fr-par.scw.cloud/hello-ruby/ruby:v1
53+
```
54+
55+
### Deploying the image
56+
57+
In a terminal, run the following command to create a Serverless Containers namespace:
58+
59+
```bash
60+
scw container namespace create name=hello
61+
```
62+
The namespace information displays.
63+
64+
1. Copy the namespace ID.
65+
66+
1. Run the following command to create and deploy the container:
67+
68+
```bash
69+
scw container container create namespace-id=<PREVIOUS_NAMESPACE_ID> name=hello registry-image=rg.fr-par.scw.cloud/hello-ruby/ruby:v1
70+
```
71+
The container information displays.
72+
73+
1. Copy the DomainName (endpoint) to test your container, you can put the endpoint in your web browser for testing.

containers/ruby-hello-world/app.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'webrick'
2+
3+
# Read the PORT environment variable, default to 8000 if not set
4+
port = ENV['PORT'] || 8000
5+
6+
server = WEBrick::HTTPServer.new(Port: port.to_i)
7+
8+
server.mount_proc '/' do |req, res|
9+
res.body = "Hello from Scaleway!"
10+
end
11+
12+
trap('INT') { server.shutdown }
13+
server.start

0 commit comments

Comments
 (0)