Use Pulumi to provision and Nix to configure (#12)

This commit is contained in:
Patrick Stevens
2023-02-02 22:14:16 +00:00
committed by GitHub
parent 61611ccc2c
commit d08cf9bec3
46 changed files with 810 additions and 1165 deletions

View File

@@ -1,29 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Utils.fs" />
<Compile Include="TestConfiguration.fs" />
<Compile Include="TestJsonSchema.fs" />
<EmbeddedResource Include="exampleconfig.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FsCheck" Version="2.16.5" />
<PackageReference Include="FsUnit" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NJsonSchema" Version="10.8.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PulumiWebServer\PulumiWebServer.fsproj" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Utils.fs" />
<Compile Include="TestConfiguration.fs" />
<Compile Include="TestJsonSchema.fs" />
<EmbeddedResource Include="..\PulumiWebServer\Nix\config.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FsCheck" Version="2.16.5" />
<PackageReference Include="FsUnit" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NJsonSchema" Version="10.8.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PulumiWebServer\PulumiWebServer.fsproj" />
</ItemGroup>
</Project>

View File

@@ -22,30 +22,6 @@ module TestConfiguration =
return BashString.make s
}
let radicaleConfigGen =
gen {
let! password = Arb.generate<string>
let! username = Arb.generate<string>
let! optionValue = Arb.generate<bool>
if optionValue then
let! (NonNull s) = Arb.generate<NonNull<string>>
return
{
RadicaleConfig.User = username
RadicaleConfig.Password = password
RadicaleConfig.GitEmail = Some s
}
else
return
{
RadicaleConfig.User = username
RadicaleConfig.Password = password
RadicaleConfig.GitEmail = None
}
}
type MyGenerators =
static member FileInfo () =
{ new Arbitrary<FileInfo>() with
@@ -59,12 +35,6 @@ module TestConfiguration =
override x.Shrinker t = Seq.empty
}
static member RadicaleConfig () =
{ new Arbitrary<RadicaleConfig>() with
override x.Generator = radicaleConfigGen
override x.Shrinker t = Seq.empty
}
[<Test>]
let ``Serialisation round-trip`` () =
Arb.register<MyGenerators> () |> ignore
@@ -78,26 +48,18 @@ module TestConfiguration =
[<Test>]
let ``Specific example`` () =
let config =
let publicConfig =
{
Name = ""
PrivateKey = PrivateKey (FileInfo "/tmp")
PublicKeyOverride = None
AcmeEmail = EmailAddress ""
Domain = DomainName ""
Cnames = Map.empty
Subdomains = Set.empty
RemoteUsername = Username ""
GiteaConfig = None
RadicaleConfig =
Some
{
User = ""
Password = ""
GitEmail = None
}
AcmeEmail = EmailAddress "test@example.com"
RemoteUsername = Username "non-root"
}
let serialised = SerialisedConfig.Make config
let serialised = SerialisedConfig.Make publicConfig
let roundTripped = SerialisedConfig.Deserialise serialised
config |> shouldEqual roundTripped
publicConfig |> shouldEqual roundTripped

View File

@@ -23,8 +23,7 @@ module TestSchema =
let schema = JsonSchema.FromJsonAsync(File.ReadAllText schemaFile.FullName).Result
let json =
Utils.getEmbeddedResource typeof<Utils.Dummy>.Assembly "exampleconfig.json"
let json = Utils.getEmbeddedResource typeof<Utils.Dummy>.Assembly "config.json"
let validator = JsonSchemaValidator ()
let errors = validator.Validate (json, schema)
@@ -33,8 +32,7 @@ module TestSchema =
[<Test>]
let ``Example can be loaded`` () =
let config =
Utils.getEmbeddedResource typeof<Utils.Dummy>.Assembly "exampleconfig.json"
let config = Utils.getEmbeddedResource typeof<Utils.Dummy>.Assembly "config.json"
use stream = new MemoryStream ()

View File

@@ -1,20 +0,0 @@
{
"name": "server",
"privateKey": "/path/to/.ssh/id_ed25519",
"acmeEmail": "my_acme_email@example.com",
"domain": "staging.example.com",
"remoteUsername": "my-username",
"giteaConfig": {
"serverPassword": "password-for-gitea-linux-user",
"adminPassword": "gitea-admin-user-app-password",
"adminUsername": "gitea-admin-username",
"adminEmailAddress": "gitea_email@example.com"
},
"radicaleConfig": {
"user": "app-username",
"password": "app-password",
"gitEmail": "radicale_email@example.com"
},
"cnames": {"www": "root"},
"subdomains": ["gitea", "calendar"]
}