Yii Framework Forum

Assets, asset publishing

(Gaz) #1

Hi, and thanks to everyone that has made Yii what it is today.

I had some thoughts about asset publishing in the context of Yii3 and docker.

I noticed the refactoring of Yii into modules for v3 and can’t help thinking that dockerization is a key motivation.

And if you think of Yii as modules with project templates i.e. basic vs advanced, and now yiisoft/yii-project-template… modules that manage assets need a hub to control where assets are published (file-system vs remote buckets).

(Alexander Makarov) #2

Yes, that would be a great addition to asset publishing to be able to publish assets targeting something like S3 buckets.

(Alexander Makarov) #3

Would you like to try designing it?

(Gaz) #4

I’m thinking it could be a cornerstone of how a modularised Yii3 works.

It would mean dropping Vagrant in favour of Docker.

A Yii project template (composer.json + config files) defines how a vhost serves a Yii application.

A Yii application can be executed via web or console (or with test config).

When executed via web, modules need to publish assets.

Assets might be copies from npm registry (bower is no longer, but packagist still exists).

Or assets might be built locally e.g. via npm run (gulp | grunt | webpack)

And output somewhere a Yii application can point to.

(Gaz) #5

A Yii asset hub.

sqlite key/val database:

path | value

(Alexander Makarov) #7

That’s personal preferences. We should not require using docker as such. There are official Docker images already: https://github.com/yiisoft/yii2-docker

(Alexander Makarov) #8

Also I’d not mix anything about containers into config or composer.json. From my practice these are pretty much unrelated.

(Alexander Makarov) #9

I mean there’s Docker and docker-compose.yml for the purpose.

(Gaz) #10

I’ve tried out yiisoft/yii2-docker and yiisoft/yii-docker and I’m using a modified version of yiisoft//yii2-app-basic as an SPA template. See: https://github.com/gazbond/yii2-app-basic.

I didn’t like yiisoft/yii2-app-advanced because I only need ‘frontend’ and ‘api’ and I like the simplicity of my data model being in the project root directory.

With yiisoft//yii2-app-basic I can specify my api as a module and then remap it with an api specific entry script and config file.

Which is what got be thinking about Yii modules and Docker.

(Alexander Makarov) #11

OK. But how’s that related to asset publishing?

(Gaz) #12

Because if Yii becomes docker only, project templates can be used as docker containers. Provide an asset hub image (php/apache2/Yii), maybe a Yii hub container (also php/apache2/Yii), and then you can specify which api, frontend and backend containers you want with their corresponding repos.

FYI this is a train of thought.

(Gaz) #13

A Yii hub template would specify the ports an application is available on.

Then php containers are added, without specified ports, but link to which hub to use.

  • hub:
    • assets
    • console
    • web
    • api

(Gaz) #14

In terms of yiisoft/yii2-app-advanced:

common -> apche2 | ngnx / php : 8080 -> Yii bootstrap (configs, models, namespaces etc.)

frontend -> php -> Yii module (configs, models, namespaces etc.)

backend -> php -> Yii module

api -> php -> Yii module

(Gaz) #15

Templates - web, api, common (each with own console) and console (just console).

Use ‘composer create-project’ for each template you want in your project directory.

Every project needs a ‘common’ directory that specifies docker-compose.yml and Yii bootstrap config.

Other directories specify Yii module config.

Assets module is a special case. It provides assets publishing config to all other modules.

All docker config is done in ‘common’ as well as all Yii module config.

(Alexander Makarov) #16

That’s not direction we want to move to. Making Yii Docker-only will essentially kill it:

  1. There are many people not using containers. Too many.
  2. Not every case needs a container.
  3. There are other container implementations out there that are popular: LXC/LXD, for example.

(Mehdi Achour) #17

Not to mention web hosting providers that doesn’t provide docker integration.
Docker can’t definitely not be a requirement for Yii.

(Gaz) #18

I see. Thanks for reading my ramble, I was a bit over-excited about v3 possibilities :slight_smile:

What’s the plan with Yii project template and application bases?

Would you use yiisoft/yii-project-template as top level project directory and checkout application bases into it?

I like the idea of having application bases that can also be modules. Load yiisoft/yii-base-api as a module in yiisoft/yii-base-web and also on its own as a Yii application.

(Mehdi Achour) #19

@gazbond random thought: having a Docker setup for tests on each package would be something truly amazing.

(Mehdi Achour) #20

That’s indeed how it’s meant to be used for now, see https://github.com/yiisoft/yii-project-template#installation.

(Gaz) #21

DI’m thinking the following (which could allow multiple test containers):

     public/index.php <- run as vhost 
     config/modules.php <- load api + other 
     public/index.php <- run as vhost 
     Module.php <- or as module 
     Module.php <- only run as module 
docket-compose.yml <- run dev container