Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Table of Contents:
| **[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] |
| **[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] |
| **[gRPC HTTP2 in Go](containers/grpc-http2-go/README.md)** <br/> A Go gRPC Container using http2 | Go/Protobuf | [CLI] |
| **[.NET C#](containers/csharp-hello-world)** <br/> A .NET C# Container hello world | C# .NET | [CLI] |

### ⚙️ Jobs

Expand Down
18 changes: 18 additions & 0 deletions containers/csharp-hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use the official .NET runtime image.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app

# Final stage
FROM base AS final
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "HelloWorldApp.dll"]
9 changes: 9 additions & 0 deletions containers/csharp-hello-world/HelloWorldApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
11 changes: 11 additions & 0 deletions containers/csharp-hello-world/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var builder = WebApplication.CreateBuilder(args);

// Get PORT from environment, default to 8080 if not set
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
builder.WebHost.UseUrls($"http://*:{port}");

var app = builder.Build();

app.MapGet("/", () => "Hello from Scaleway!");

app.Run();
73 changes: 73 additions & 0 deletions containers/csharp-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# C# .NET hello world

This example demonstrates the deployment of a simple C# http service on Scaleway Serverless Containers.

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/).

## Workflow

Here are the different steps we are going to proceed:

- Quick set-up of Container Registry to host our .NET container
- Deploy the Serverless Container
- Test the container

## Deployment

### Requirements

To complete the actions presented below, you must have:
- installed and configured the [Scaleway CLI](https://www.scaleway.com/en/docs/developer-tools/scaleway-cli/quickstart/)
- installed [Docker](https://docs.docker.com/engine/install/) to build the image

### Building the image

1. Run the following command in a terminal to create Container Registry namespace to store the image:

```bash
scw registry namespace create name=hello-dotnet
```

The registry namespace information displays.

1. Copy the namespace endpoint (in this case, `rg.fr-par.scw.cloud/hello-dotnet`).

1. Log into the Container Registry namespace you created using Docker:

```bash
docker login rg.fr-par.scw.cloud/hello-dotnet -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
```

At this point, you have correctly set up Docker to be able to push your image online.

1. In a terminal, access this directory (containing the Dockerfile), and run the following command to build and tag the image:

```bash
docker build --platform linux/amd64 -t rg.fr-par.scw.cloud/hello-dotnet/dotnet:v1 .
```

1. Tag and push the image to the registry namespace:

```bash
docker push rg.fr-par.scw.cloud/hello-dotnet/dotnet:v1
```

### Deploying the image

In a terminal, run the following command to create a Serverless Containers namespace:

```bash
scw container namespace create name=hello
```
The namespace information displays.

1. Copy the namespace ID.

1. Run the following command to create and deploy the container:

```bash
scw container container create namespace-id=<PREVIOUS_NAMESPACE_ID> name=hello registry-image=rg.fr-par.scw.cloud/hello-dotnet/dotnet:v1
```
The container information displays.

1. Copy the DomainName (endpoint) to test your container, you can put the endpoint in your web browser for testing.
Loading