From d210c6ac7ccf7ada8ff0676735d84c68e21b588a Mon Sep 17 00:00:00 2001 From: mdnapo Date: Mon, 22 Jul 2024 21:27:17 +0200 Subject: [PATCH] Cleaned up, tested and documented --dbu-platform --- .../MycroForge.Api.Generate.Router.cs | 1 - .../Commands/MycroForge.Db.Generate.Entity.cs | 1 - .../Commands/MycroForge.Generate.Service.cs | 2 -- MycroForge.CLI/Features/Db.cs | 6 ++--- MycroForge.Core/Extensions/EnumExtensions.cs | 19 --------------- ...ojectConfig.DbConfig.DbuPlatformOptions.cs | 23 +++++-------------- MycroForge.Core/scripts/publish-nuget.sh | 4 ++++ README.md | 3 +-- docs/docs/Commands/m4g_init.md | 12 +++++----- docs/docs/tutorial.md | 11 ++++++++- 10 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 MycroForge.Core/Extensions/EnumExtensions.cs create mode 100644 MycroForge.Core/scripts/publish-nuget.sh diff --git a/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs b/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs index b130909..14a4db1 100644 --- a/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs +++ b/MycroForge.CLI/Commands/MycroForge.Api.Generate.Router.cs @@ -2,7 +2,6 @@ using System.CommandLine; using Humanizer; using MycroForge.CLI.CodeGen; using MycroForge.Core.Contract; -using MycroForge.CLI.Extensions; using MycroForge.Core; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs b/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs index 3253815..9fffbf7 100644 --- a/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs +++ b/MycroForge.CLI/Commands/MycroForge.Db.Generate.Entity.cs @@ -2,7 +2,6 @@ using System.CommandLine; using Humanizer; using MycroForge.CLI.CodeGen; using MycroForge.Core.Contract; -using MycroForge.CLI.Extensions; using MycroForge.Core; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs b/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs index 000eceb..a8b1a5d 100644 --- a/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs +++ b/MycroForge.CLI/Commands/MycroForge.Generate.Service.cs @@ -1,7 +1,5 @@ using System.CommandLine; -using Humanizer; using MycroForge.Core.Contract; -using MycroForge.CLI.Extensions; using MycroForge.Core; namespace MycroForge.CLI.Commands; diff --git a/MycroForge.CLI/Features/Db.cs b/MycroForge.CLI/Features/Db.cs index 4b8ba64..4b8df5f 100644 --- a/MycroForge.CLI/Features/Db.cs +++ b/MycroForge.CLI/Features/Db.cs @@ -1,7 +1,6 @@ using MycroForge.CLI.CodeGen; using MycroForge.CLI.Commands; using MycroForge.Core; -using MycroForge.Core.Extensions; namespace MycroForge.CLI.Features; @@ -58,8 +57,7 @@ public sealed partial class Db : IFeature " - '%app_name%_mariadb:/var/lib/mysql'", "", " %app_name%_phpmyadmin:", - " image: phpmyadmin/phpmyadmin", - " platform: %dbu_platform%", + " image: %dbu_platform%/phpmyadmin", " container_name: %app_name%_phpmyadmin", " ports:", " - '${DBU_PORT}:80'", @@ -127,7 +125,7 @@ public sealed partial class Db : IFeature var dockerCompose = string.Join('\n', DockerCompose) .Replace("%app_name%", appName) - .Replace("%dbu_platform%", options.DbuPlatform.ToDockerPlatformString()) + .Replace("%dbu_platform%", options.DbuPlatform.ToString()) ; await context.CreateFile($"{FeatureName}.docker-compose.yml", dockerCompose); diff --git a/MycroForge.Core/Extensions/EnumExtensions.cs b/MycroForge.Core/Extensions/EnumExtensions.cs deleted file mode 100644 index 3b399c4..0000000 --- a/MycroForge.Core/Extensions/EnumExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using MycroForge.Core.Attributes; - -namespace MycroForge.Core.Extensions; - -public static class EnumExtensions -{ - /// - /// A generic extension method that aids in reflecting - /// and retrieving any attribute that is applied to an `Enum`. - /// - public static string ToDockerPlatformString(this ProjectConfig.DbConfig.DbuPlatformOptions value) - { - return value.GetType() - .GetMember(value.ToString()) - .FirstOrDefault()! - .GetCustomAttribute()!.Platform; - } -} \ No newline at end of file diff --git a/MycroForge.Core/ProjectConfig.DbConfig.DbuPlatformOptions.cs b/MycroForge.Core/ProjectConfig.DbConfig.DbuPlatformOptions.cs index 2cd9206..8f78d0d 100644 --- a/MycroForge.Core/ProjectConfig.DbConfig.DbuPlatformOptions.cs +++ b/MycroForge.Core/ProjectConfig.DbConfig.DbuPlatformOptions.cs @@ -1,6 +1,4 @@ -using MycroForge.Core.Attributes; - -namespace MycroForge.Core; +namespace MycroForge.Core; public partial class ProjectConfig { @@ -8,20 +6,11 @@ public partial class ProjectConfig { public enum DbuPlatformOptions { - [DockerPlatform(Platform = "linux/amd64")] - linux_amd64, - - [DockerPlatform(Platform = "linux/arm32/v5")] - linux_arm32v5, - - [DockerPlatform(Platform = "linux/arm32/v6")] - linux_arm32v6, - - [DockerPlatform(Platform = "linux/arm32/v7")] - linux_arm32v7, - - [DockerPlatform(Platform = "linux/arm64/v8")] - linux_arm64v8 + amd64, + arm32v5, + arm32v6, + arm32v7, + arm64v8 } } } \ No newline at end of file diff --git a/MycroForge.Core/scripts/publish-nuget.sh b/MycroForge.Core/scripts/publish-nuget.sh new file mode 100644 index 0000000..019115d --- /dev/null +++ b/MycroForge.Core/scripts/publish-nuget.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +dotnet build -r Release +dotnet nuget push --source devdisciples bin/Release/MycroForge.Core.1.0.0.nupkg \ No newline at end of file diff --git a/README.md b/README.md index 9537622..1dab471 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,7 @@ dotnet nuget add source --name devdisciples --username username --password passw ### TODO - 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`. - Fix up exception handling - Clean up README files -- \ No newline at end of file +- Print the path of generated files. \ No newline at end of file diff --git a/docs/docs/Commands/m4g_init.md b/docs/docs/Commands/m4g_init.md index ef85f7c..f89b637 100644 --- a/docs/docs/Commands/m4g_init.md +++ b/docs/docs/Commands/m4g_init.md @@ -15,10 +15,10 @@ Arguments: The name of your project Options: - --without Features to exclude - --api-port The API port - --database-host-port, --dbh-port The database host port - --database-ui-port, --dbu-port The database UI port - --database-ui-platform, --dbu-platform The docker platform for the PhpMyAdmin image - -?, -h, --help Show help and usage information + --without Features to exclude + --api-port The API port + --database-host-port, --dbh-port The database host port + --database-ui-port, --dbu-port The database UI port + --database-ui-platform, --dbu-platform The docker platform for the PhpMyAdmin image + -?, -h, --help Show help and usage information ``` diff --git a/docs/docs/tutorial.md b/docs/docs/tutorial.md index bae9e75..bf99438 100644 --- a/docs/docs/tutorial.md +++ b/docs/docs/tutorial.md @@ -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 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. - user: root - pass: password 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