Skip to content

Commit

Permalink
feat: flake for template cli dependencies (#1)
Browse files Browse the repository at this point in the history
* feat: flake for template cli dependencies

* chore: Cleanup Readme Docs

---------

Co-authored-by: sheldon.malboeuf@nventive.com <sheldon.malboeuf@nventive.com>
Co-authored-by: Sheldon Malboeuf <45205598+smalboeuf@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 840b9bb commit d8b2021
Show file tree
Hide file tree
Showing 38 changed files with 1,036 additions and 2 deletions.
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,95 @@ The following is the template for the final README.md file:

## Getting Started

{Instructions to quickly get started using the project: pre-requisites, packages
to install, sample code, etc.}
The main prerequisites for a developer setup are:
- either Linux (including WSL) or macOS as OS;
- the Nix package manager with flakes enabled;
- [direnv](https://direnv.net/) and [nix-direnv](https://github.com/nix-community/nix-direnv);
- Docker;
- Visual Studio Code with the C# DevKit extension for debugging;
- an Azure account to deploy and run in the cloud.

> ### For WSL Users
> - If you’re using Docker Desktop, remember to [enable it in your WSL distro](https://docs.docker.com/desktop/wsl/#enabling-docker-support-in-wsl-2-distros)
> - VS Code extensions must be activated in WSL.
> - The ASP.NET Core developement certificate installed in WSL must be trusted in your Windows browser.
> ### Steps to trust the ASP.NET Core development certificate used in WSL
> 1. Install the .NET SDK in Windows [whichever way you want](https://learn.microsoft.com/en-us/dotnet/core/install/windows).
> 1. Install and activate the ASP.NET Core development certificate (`[password]` being any password you’ll remember in the next minute). In Windows:
> ```console
> dotnet dev-certs https --clean
> dotnet dev-certs https --trust
> dotnet dev-certs https -ep https.pfx -p [password]
> ```
> 3. Restart your browser to make sure it trusts the new certificate.
> 3. Import the certificate in WSL and trust it for inter-service communications (`[path]` being the path to the windows directory you executed the previous commands, and `[password]` being the password entered previously):
> ```console
> sudo apt install dotnet-sdk-8.0
> dotnet dev-certs https --clean --import /mnt/c/[path]/https.pfx --password [password]
> sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM
> sudo update-ca-certificates
>```
### Steps to install Nix, direnv
Use the [Determinate Nix installer](https://github.com/DeterminateSystems/nix-installer):
```console
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
```
For direnv, the best way would be [via home-manager](https://github.com/nix-community/nix-direnv?tab=readme-ov-file#via-home-manager), if you have [home-manager](https://nix-community.github.io/home-manager/).

> ### WSL Method
> 1. Install direnv (tested with Ubuntu 24.04 in WSL).
> ```console
> sudo apt install direnv
> ```
> 2. [Hook direnv into your shell](https://direnv.net/docs/hook.html). For bash this means adding the following line in your `~/.bashrc`:
> ```bash
> eval "$(direnv hook bash)"
> ```
> Don’t forget to reload your bash.
> ```console
> source ~/.bashrc
> ```
> 4. Install nix-direnv in your user Nix profile and hook it up to direnv.
> ```console
> nix profile install nixpkgs#nix-direnv
> source $HOME/.nix-profile/share/nix-direnv/direnvrc
> ```
### Start for real
1. Get this repository’s content
```console
git checkout https://github.com/nventive/cloud-template.git
```
2. Copy the template to wherever you want to have it and enable the development shell. **Warning:** the last step may take a while, as it’s downloading/building all tools and dependencies.
```console
cp -r cloud-template/template MyProject
cd MyProject
direnv allow
```

3. Install the Aspire .NET workload. *TODO: [use local install](https://discourse.nixos.org/t/dotnet-maui-workload/20370/13) as soon as .NET SDK 8.0.40x is in nixpkgs*
```console
$ sudo `which dotnet` workload install aspire
```

4. Rename the project according to your inspirations (`Placeholder` is the actual string to be replaced).
```console
fd Placeholder | tac | xargs rnm -rs '/Placeholder/MyProject/g' -y
fd --hidden --type file --exec sd Placeholder MyProject
```

5. Start VS Code. NB: it has to be started this way to ensure the correct .NET frawework is found and debugging works.
```console
./start-code.sh
```

Further instructions are in the `README` of your new project.

## Features

Expand Down
1 change: 1 addition & 0 deletions template/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
3 changes: 3 additions & 0 deletions template/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "src/Placeholder.sln"
}
27 changes: 27 additions & 0 deletions template/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions template/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
description = "Development environment for the Placeholder project";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

outputs = { self, nixpkgs }:
let
overlays = [
(final: prev: rec {
nodejs = prev.nodejs_20; # Use Node.js 20
yarn = (prev.yarn.override { inherit nodejs; });
})
];

# Helpers for producing system-specific outputs
supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs {
inherit overlays system;
config = { allowUnfree = true; };
};
});
in {
# Development environments
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {

# Pinned packages available in the environment
packages = with pkgs; [
(azure-cli.withExtensions [
azure-cli.extensions.ad
azure-cli.extensions.azure-devops
azure-cli.extensions.containerapp
])
coreutils
dotnet-sdk_8
fd
nil
nixpkgs-fmt
node2nix
nodejs
pnpm
rnm
sd
terraform
yarn
];
};
});
};
}
13 changes: 13 additions & 0 deletions template/src/Placeholder.ApiService/Placeholder.ApiService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<ProjectReference Include="..\Placeholder.ServiceDefaults\Placeholder.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions template/src/Placeholder.ApiService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var builder = WebApplication.CreateBuilder(args);

// Add service defaults & Aspire components.
builder.AddServiceDefaults();

// Add services to the container.
builder.Services.AddProblemDetails();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseExceptionHandler();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

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.MapDefaultEndpoints();

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions template/src/Placeholder.ApiService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
21 changes: 21 additions & 0 deletions template/src/Placeholder.AppHost/Placeholder.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>6e41954c-3a11-4840-b848-e4684e4bde53</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Placeholder.ApiService\Placeholder.ApiService.csproj" />
<ProjectReference Include="..\Placeholder.Web\Placeholder.Web.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.1.0" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions template/src/Placeholder.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var builder = DistributedApplication.CreateBuilder(args);

var apiService = builder.AddProject<Projects.Placeholder_ApiService>("apiservice");

builder.AddProject<Projects.Placeholder_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(apiService);

builder.Build().Run();
8 changes: 8 additions & 0 deletions template/src/Placeholder.AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions template/src/Placeholder.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Loading

0 comments on commit d8b2021

Please sign in to comment.