wpdotnet-sdk icon indicating copy to clipboard operation
wpdotnet-sdk copied to clipboard

[Feature] Add project tye support to template project

Open marinasundstrom opened this issue 4 years ago • 3 comments

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 avatar May 02 '21 10:05 marinasundstrom

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 avatar May 11 '21 17:05 marinasundstrom

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 avatar May 11 '21 18:05 marinasundstrom

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

marinasundstrom avatar May 11 '21 19:05 marinasundstrom