Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marinasundstrom opened this issue May 2, 2021 · 3 comments
Open

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

marinasundstrom opened this issue May 2, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@marinasundstrom
Copy link

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 marinasundstrom added the enhancement New feature or request label May 2, 2021
@marinasundstrom
Copy link
Author

marinasundstrom commented May 11, 2021

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
Copy link
Author

marinasundstrom commented May 11, 2021

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant