.NET
Step-by-step guide to deploy an ASP.NET Core application on Out Plane
This guide walks you through deploying an ASP.NET Core Web API on Out Plane using Git-driven deployment with a Dockerfile.
Prerequisites
- An Out Plane account
- A GitHub account
- .NET 8 SDK installed on your machine
- Git installed on your machine
Create the .NET App
Create a new ASP.NET Core Web API project:
dotnet new webapi -n MyWebApi
cd MyWebApiThis creates a minimal API with a sample weather endpoint.
Configure for Production
Open Program.cs and update it to read the port from environment variables:
var builder = WebApplication.CreateBuilder(args);
// Configure port from environment variable
var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
builder.WebHost.UseUrls($"http://0.0.0.0:{port}");
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("/", () => new { message = "Hello from Out Plane" });
app.MapGet("/health", () => Results.Ok("OK"));
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
});
app.Run();
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};Create the Dockerfile
Create a file called Dockerfile in your project root:
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/publish
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENTRYPOINT ["dotnet", "MyWebApi.dll"]Replace MyWebApi.dll with your project's assembly name if different.
Create a .dockerignore file:
bin
obj
.git
.vs
*.user
*.md
.DS_StoreTest Locally
Run the application:
dotnet runOpen http://localhost:5000 (or the port shown in the console) in your browser.
To test the production build:
dotnet publish -c Release
dotnet ./bin/Release/net8.0/publish/MyWebApi.dllPush to GitHub
Initialize a Git repository and push to GitHub:
git init
git add .
git commit -m "Initial commit"
git remote add origin [email protected]:YOUR_USERNAME/MyWebApi.git
git branch -M main
git push -u origin mainReplace YOUR_USERNAME with your GitHub username.
Deploy on Out Plane
Step 1: Install GitHub App
- Go to console.outplane.com
- Navigate to Applications from the sidebar
- Click Deploy Application
- If prompted, click Install GitHub App
- Select which repositories Out Plane can access
- Click Install and you'll be redirected back
Step 2: Select Repository
- Find your repository in the list
- Click to select it
- Choose the branch to deploy (default:
main) - Set Root Directory to
/
Step 3: Configure Build
| Setting | Value |
|---|---|
| Build Method | Select Dockerfile |
| Application Name | Enter a unique name (e.g., my-web-api) |
| Port | 8080 |
Step 4: Select Resources
| Instance | vCPU | RAM | Recommended For |
|---|---|---|---|
| op-46 | 1 | 1 GB | Small APIs |
| op-82 | 2 | 2 GB | Production (recommended) |
| op-94 | 4 | 4 GB | High traffic |
Step 5: Configure Scaling
- Min Scale: Set to
1for always-on - Max Scale: Set based on expected traffic
Step 6: Environment Variables (Optional)
Click Add Variable to add environment variables:
| Key | Value |
|---|---|
ASPNETCORE_ENVIRONMENT | Production |
ConnectionStrings__DefaultConnection | Your database connection string |
Step 7: Deploy
- Review your configuration
- Click Create Application
- Wait for the build to complete (typically 2-4 minutes)
Step 8: Access Your App
Once the deployment status shows Ready:
- Go to the application Overview tab
- Find your domain:
my-web-api.outplane.app - Click to open your live application
Adding Entity Framework Core
Step 1: Install Packages
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
dotnet add package Microsoft.EntityFrameworkCore.DesignStep 2: Create DbContext
using Microsoft.EntityFrameworkCore;
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<TodoItem> TodoItems { get; set; }
}
public class TodoItem
{
public int Id { get; set; }
public string Title { get; set; } = "";
public bool IsComplete { get; set; }
}Step 3: Configure in Program.cs
var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL")
?? builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(connectionString));Step 4: Create Database on Out Plane
- Go to Databases in the sidebar
- Click Create Database
- Configure and create the database
- Copy the connection string
- Add it as
DATABASE_URLin your app's environment variables
Automatic Deployments
Push to your branch to trigger automatic deployments:
git add .
git commit -m "Add new feature"
git push origin main