iolevel / wpdotnet-sdk

WordPress compiled to .NET Standard. SDK for ASP.NET Core.
http://www.wpdotnet.com
Other
415 stars 71 forks source link

[Feature] Add project tye support to template project #105

Open marinasundstrom opened 3 years ago

marinasundstrom commented 3 years ago

Description Add a tye configuration file that configures the app project and MySQL (in Docker).

Reason It makes it easier to start developing without having to install MySQL locally.

What needs to be done

  1. Add the tye.yaml file
    1. Add the "app"
    2. Add MySQL
  2. Configure app
    1. Add the Microsoft.Tye.Extensions.Configuration package
    2. Get the db connection string (the name of the MySQL service as defined in tye.yaml)

Question Is it difficult to do this?

marinasundstrom commented 3 years ago

This is what I came up with:

tye.yaml:

# tye application configuration file
# read all about it at https://github.com/dotnet/tye
#
# when you've given us a try, we'd love to know what you think:
#    https://aka.ms/AA7q20u
#
name: peachpie-wordpress
services:
- name: app
  project: app/app.csproj

- name: wordpress-mysql
  image: mysql/mysql-server:latest
  bindings:
    - port: 3306
  env:
    - name: MYSQL_ROOT_PASSWORD
      value: "P@ssw0rd"
    - name: MYSQL_DATABASE
      value: "wordpress"
    - name: MYSQL_USER
      value: "user"
    - name: MYSQL_PASSWORD
      value: "P@ssw0rd"

In Program.cs, remove or comment out .UseUrls("http://*:5004/"). Since bindings will be handled by Tye.

    static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(typeof(Program).Assembly.Location));

            //
            var host = WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                //.UseUrls("http://*:5004/")
                .Build();

            host.Run();
        }

Update connection details in ``appsettings.Development.json```:

{
  "WordPress": {
    "dbhost": "localhost",
    "dbpassword": "P@ssw0rd",
    "dbuser": "user",
    "dbname": "wordpress",
  }
}

Now you have the Wordpress db in MySQL running in Docker.

Am I missing something?

I have not figured out persistence and mapping volumes yet.

marinasundstrom commented 3 years ago

Update: Mount /var/lib/mysql to the ./data/mysql.

- name: wordpress-mysql
  image: mysql/mysql-server:latest
  bindings:
    - port: 3306
  env:
    - name: MYSQL_ROOT_PASSWORD
      value: "P@ssw0rd"
    - name: MYSQL_DATABASE
      value: "wordpress"
    - name: MYSQL_USER
      value: "user"
    - name: MYSQL_PASSWORD
      value: "P@ssw0rd"
  volumes:
    - source: .data/mysql
      target: /var/lib/mysql

And to bind the Wordpress app to specific port:

name: peachpie-wordpress
services:
- name: app
  project: app/app.csproj

  bindings:
    - port: 5004
      protocol: http

The ports assigned will normally be random.

I'm working on a sample for a headless app using Blazor as a frontend. Tye is used for orchestrating during dev.

marinasundstrom commented 3 years ago

Here is my headless Wordpress with a Blazor frontend: https://github.com/robertsundstrom/headless-wordpress-blazor