Cleaned up, tested and documented --dbu-platform

This commit is contained in:
mdnapo 2024-07-22 21:27:17 +02:00
parent aa1c2422ef
commit d210c6ac7c
10 changed files with 29 additions and 53 deletions

View File

@ -2,7 +2,6 @@ using System.CommandLine;
using Humanizer; using Humanizer;
using MycroForge.CLI.CodeGen; using MycroForge.CLI.CodeGen;
using MycroForge.Core.Contract; using MycroForge.Core.Contract;
using MycroForge.CLI.Extensions;
using MycroForge.Core; using MycroForge.Core;
namespace MycroForge.CLI.Commands; namespace MycroForge.CLI.Commands;

View File

@ -2,7 +2,6 @@ using System.CommandLine;
using Humanizer; using Humanizer;
using MycroForge.CLI.CodeGen; using MycroForge.CLI.CodeGen;
using MycroForge.Core.Contract; using MycroForge.Core.Contract;
using MycroForge.CLI.Extensions;
using MycroForge.Core; using MycroForge.Core;
namespace MycroForge.CLI.Commands; namespace MycroForge.CLI.Commands;

View File

@ -1,7 +1,5 @@
using System.CommandLine; using System.CommandLine;
using Humanizer;
using MycroForge.Core.Contract; using MycroForge.Core.Contract;
using MycroForge.CLI.Extensions;
using MycroForge.Core; using MycroForge.Core;
namespace MycroForge.CLI.Commands; namespace MycroForge.CLI.Commands;

View File

@ -1,7 +1,6 @@
using MycroForge.CLI.CodeGen; using MycroForge.CLI.CodeGen;
using MycroForge.CLI.Commands; using MycroForge.CLI.Commands;
using MycroForge.Core; using MycroForge.Core;
using MycroForge.Core.Extensions;
namespace MycroForge.CLI.Features; namespace MycroForge.CLI.Features;
@ -58,8 +57,7 @@ public sealed partial class Db : IFeature
" - '%app_name%_mariadb:/var/lib/mysql'", " - '%app_name%_mariadb:/var/lib/mysql'",
"", "",
" %app_name%_phpmyadmin:", " %app_name%_phpmyadmin:",
" image: phpmyadmin/phpmyadmin", " image: %dbu_platform%/phpmyadmin",
" platform: %dbu_platform%",
" container_name: %app_name%_phpmyadmin", " container_name: %app_name%_phpmyadmin",
" ports:", " ports:",
" - '${DBU_PORT}:80'", " - '${DBU_PORT}:80'",
@ -127,7 +125,7 @@ public sealed partial class Db : IFeature
var dockerCompose = string.Join('\n', DockerCompose) var dockerCompose = string.Join('\n', DockerCompose)
.Replace("%app_name%", appName) .Replace("%app_name%", appName)
.Replace("%dbu_platform%", options.DbuPlatform.ToDockerPlatformString()) .Replace("%dbu_platform%", options.DbuPlatform.ToString())
; ;
await context.CreateFile($"{FeatureName}.docker-compose.yml", dockerCompose); await context.CreateFile($"{FeatureName}.docker-compose.yml", dockerCompose);

View File

@ -1,19 +0,0 @@
using System.Reflection;
using MycroForge.Core.Attributes;
namespace MycroForge.Core.Extensions;
public static class EnumExtensions
{
/// <summary>
/// A generic extension method that aids in reflecting
/// and retrieving any attribute that is applied to an `Enum`.
/// </summary>
public static string ToDockerPlatformString(this ProjectConfig.DbConfig.DbuPlatformOptions value)
{
return value.GetType()
.GetMember(value.ToString())
.FirstOrDefault()!
.GetCustomAttribute<DockerPlatformAttribute>()!.Platform;
}
}

View File

@ -1,6 +1,4 @@
using MycroForge.Core.Attributes; namespace MycroForge.Core;
namespace MycroForge.Core;
public partial class ProjectConfig public partial class ProjectConfig
{ {
@ -8,20 +6,11 @@ public partial class ProjectConfig
{ {
public enum DbuPlatformOptions public enum DbuPlatformOptions
{ {
[DockerPlatform(Platform = "linux/amd64")] amd64,
linux_amd64, arm32v5,
arm32v6,
[DockerPlatform(Platform = "linux/arm32/v5")] arm32v7,
linux_arm32v5, arm64v8
[DockerPlatform(Platform = "linux/arm32/v6")]
linux_arm32v6,
[DockerPlatform(Platform = "linux/arm32/v7")]
linux_arm32v7,
[DockerPlatform(Platform = "linux/arm64/v8")]
linux_arm64v8
} }
} }
} }

View File

@ -0,0 +1,4 @@
#!/bin/bash
dotnet build -r Release
dotnet nuget push --source devdisciples bin/Release/MycroForge.Core.1.0.0.nupkg

View File

@ -31,8 +31,7 @@ dotnet nuget add source --name devdisciples --username username --password passw
### TODO ### TODO
- Fix `-c` option for `m4g db generate entity` - Fix `-c` option for `m4g db generate entity`
- Mention `--dbu-platform` option for `m4g init`
- Research if System.CommandLine middleware can be used to safeguard commands like `m4g add` or `m4g api`. - Research if System.CommandLine middleware can be used to safeguard commands like `m4g add` or `m4g api`.
- Fix up exception handling - Fix up exception handling
- Clean up README files - Clean up README files
- - Print the path of generated files.

View File

@ -15,10 +15,10 @@ Arguments:
<name> The name of your project <name> The name of your project
Options: Options:
--without <api|db|git|gitignore> Features to exclude --without <api|db|git|gitignore> Features to exclude
--api-port <api-port> The API port --api-port <api-port> The API port
--database-host-port, --dbh-port <database-host-port> The database host port --database-host-port, --dbh-port <database-host-port> The database host port
--database-ui-port, --dbu-port <database-ui-port> The database UI port --database-ui-port, --dbu-port <database-ui-port> The database UI port
--database-ui-platform, --dbu-platform <linux_amd64|linux_arm32v5|linux_arm32v6|linux_arm32v7|linux_arm64v8> The docker platform for the PhpMyAdmin image --database-ui-platform, --dbu-platform <amd64|arm32v5|arm32v6|arm32v7|arm64v8> The docker platform for the PhpMyAdmin image
-?, -h, --help Show help and usage information -?, -h, --help Show help and usage information
``` ```

View File

@ -36,13 +36,22 @@ This command starts the services defined in the `db.docker-compose.yml` file.
You can verify that the services are up by running `docker container ls`. If everything went well, then the previous You can verify that the services are up by running `docker container ls`. If everything went well, then the previous
command should output the service names defined in `db.docker-compose.yml`. command should output the service names defined in `db.docker-compose.yml`.
If you go to [PhpMyAdmin (i.e. http://localhost:5051)](http://localhost:5051), you should now be able to login with the Go to [PhpMyAdmin (i.e. http://localhost:5051)](http://localhost:5051). You should now be able to login with the
following credentials. following credentials.
- user: root - user: root
- pass: password - pass: password
When you're done developing, you can shut down the local database by running `m4g db stop` When you're done developing, you can shut down the local database by running `m4g db stop`
:::info
If you're running on MacOS, Docker might complain about a platform mismatch for PhpMyAdmin.
In that case you might need to specify the platform for the PhpMyAdmin image.
You can do this by passing the `--dbu-platform` flag to `m4g init`.
Run `m4g init -?` for all the available options.
If you've already initialized a project, you can also change the platform prefix of the PhpMyAdmin image in the `db.docker-compose.yml`.
:::
### Create the entities ### Create the entities