Skip to content

Commit 3b04284

Browse files
feat(content): .NET example (#105)
* feat(content): .NET example * remove port metadata
1 parent 26afc1d commit 3b04284

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-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+
| **[.NET C#](containers/csharp-hello-world)** <br/> A .NET C# Container hello world | C# .NET | [CLI] |
7980
| **[Ruby Hello World](containers/ruby-hello-world/)** <br/> A simple Ruby Hello world Container | Ruby | [CLI] |
8081

8182
### ⚙️ Jobs
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use the official .NET runtime image.
2+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
3+
WORKDIR /app
4+
5+
# Build stage
6+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
7+
WORKDIR /src
8+
COPY *.csproj .
9+
RUN dotnet restore
10+
COPY . .
11+
RUN dotnet publish -c Release -o /app
12+
13+
# Final stage
14+
FROM base AS final
15+
WORKDIR /app
16+
COPY --from=build /app .
17+
ENTRYPOINT ["dotnet", "HelloWorldApp.dll"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Get PORT from environment, default to 8080 if not set
4+
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
5+
builder.WebHost.UseUrls($"http://*:{port}");
6+
7+
var app = builder.Build();
8+
9+
app.MapGet("/", () => "Hello from Scaleway!");
10+
11+
app.Run();
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# C# .NET hello world
2+
3+
This example demonstrates the deployment of a simple C# 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 .NET 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-dotnet
29+
```
30+
31+
The registry namespace information displays.
32+
33+
1. Copy the namespace endpoint (in this case, `rg.fr-par.scw.cloud/hello-dotnet`).
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-dotnet -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-dotnet/dotnet: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-dotnet/dotnet: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-dotnet/dotnet: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.

0 commit comments

Comments
 (0)