Deploy full Symfony2 app with composer - symfony

Is there a way to setup a composer.json file in order to deploy a full Symfony 2.3 app?
Suppose I have the app in the git repo https://myrepo#bitbucket.org/myrepo/sfwebapp.git

As far as I know, composer is dependency manager, not deployment manager. Sure, you could:
Pull Git repo
Run composer --install (this is basically the essential step)
Warm up cache
Symlink resources
Install assets
...
PROFIT
BUT, You would need to manually:
Check/perform initial directory structure setup
Keep track of old deployments
...
So, bottom line, you could achieve it but it would be like reinventing the wheel.

Related

How to run symfony cli command with --webapp using local composer.phar?

I run different versions of Symfony and PHP on my Mac for various apps I have to work on (sorry that our clients are so slow to get to upgrade), and I'm trying to install the LTS version of Symfony through the CLI documentation recommendations, but I'm trying to get it to use a composer.phar in the folder I run the command in... it keeps defaulting to the globally-installed one.
Sure I could just go change composer's execution path or upgrade/downgrade it temporarily whenever I want to run the cli for x version of PHP, but that's gonna drive me crazy and I'd rather see how to tell it to run a certain composer.phar file. I'm not seeing in the documentation how to do this to get the benefits of the --webapp option.
The documentation is weird on it anyway; I can't tell if running composer directly (as composer.phar) will give me the benefits of the --webapp option using the symfony command (because the composer commands are identical for 'traditional web application' and 'console application or API'):
https://symfony.com/doc/5.4/setup.html#creating-symfony-applications
# run this if you are building a traditional web application
$ symfony new my_project_directory --version=5.4 --webapp
# run this if you are building a microservice, console application or API
$ symfony new my_project_directory --version=5.4
# run this if you are building a traditional web application
$ composer create-project symfony/skeleton:"^5.4" my_project_directory
$ cd my_project_directory
$ composer require webapp
# run this if you are building a microservice, console application or API
$ composer create-project symfony/skeleton:"^5.4" my_project_directory
When I run the install through composer directly, I can't tell if I'm getting the benefits of the symfony command --webapp option... and I'm not seeing an option for the symfony command to specify to use the folder's composer.phar.
I had to cheat a little bit: I installed the latest composer using the instructions here to a composer.phar file:
https://getcomposer.org/download/
I then created a console alias like php composer.phar, ran the Symfony create composer command with that alias, which created the symfony-5 folder no problem, then I copied the composer.phar file to the new folder and run the alias for any other composer commands, like with require webapp, which is working! Kind of nice to freeze a version of composer for any similar repos.
Maybe not the best answer, but it's working.
Also I discovered that I could just run composer self-update to get the latest version, which worked, then composer self-update [whatever version number] to get back to one I need that works with other repos (since certain version ranges just do not work with certain version ranges of PHP). Annoying, but functional.
Ultimately I think moving forward, it's best to make a copy of composer.phar at a compatible version range for your older PHP apps, depending on their versions, and use those in an alias, rather than totally rely on a global composer version, which has proven not completely workable for my work.

npm install Azure Devops

Please help me set up npm install tall for the project. My project is on the gitlab, I set up the pipeline and release it. I do not understand which folder path I need to specify npm install, since only files from artifacts give me a choice. Perhaps I configured the pipeline incorrectly?
folder1
folder2
To solve this problem, you just need to write a script (npm install)enter image description here in your pipeline for releases

Why is webpack encore required only in dev

I'm currently configuring some docker images for a symfony 5 project and trying to deal with the production build. Doing so, I noticed that webpack encore is installed only on dev mode, as advised on this official documentation : https://symfony.com/doc/current/frontend/encore/installation.html :
yarn add #symfony/webpack-encore --dev
However, this doesn't make sense to me, since even in production, we are supposed to build the assets :
yarn encore production
Does anyone have clues about this ?
Thank you
The Symfony docs on How Do I Deploy My Encore Assets? provide two important things to remember when deploying assets:
1) Compile Assets for Production:
$ ./node_modules/.bin/encore production
Now the important part:
But, what server should you run this command on? That depends on how you deploy. For example, you could execute this locally (or on a build server), and use rsync or something else to transfer the generated files to your production server. Or, you could put your files on your production server first (e.g. via git pull) and then run this command on production (ideally, before traffic hits your code). In this case, you’ll need to install Node.js on your production server.
And the second important thing:
2) Only Deploy the Built Assets
The only files that need to be deployed to your production servers are the final, built assets (e.g. the public/build directory). You do not need to install Node.js, deploy webpack.config.js, the node_modules directory or even your source asset files, unless you plan on running encore production on your production machine. Once your assets are built, these are the only thing that need to live on the production server.
Simply put, in the production environment you only need the generated assets (usually /public/build directory content). In a simple scenario when you only need to load compiled Javascript and CSS files the Webpack is not used at runtime.
A possible solution how to deploy a Symfony application & assets
When deploying a Symfony app manually (without CI/CD) the following steps can be performed on the local machine or in a Docker container (assumes Symfony 4/5):
Export the source code from GIT repository with git-archive, e.g.: git archive --prefix=myApp/ HEAD | tar -xC /tmp/¹
Go to exported source code: cd /tmp/myApp
Install Symfony & other PHP vendors (see also the Symfony docs): composer install --no-dev --optimize-autoloader
Install YARN/NPM vendors (they'll be required to generate assets with Webpack): yarn install
Create production assets: yarn build (or yarn encore production)
(Install Symfony assets if needed: bin/console assets:install)
Now the code is ready to rsync it to the production server. You may exclude or delete the /node_modules, /var and even /assets directories and webpack.config.js (probably package.json & yarn.lock won't be needed either -- didn't tested it!) and run e.g.: rsync --archive --compress --delete . <myProductionServer>:<app/target/path/>
Resources on Symfony deployment:
How to Deploy a Symfony Application (Symfony docs)
How Do I Deploy My Encore Assets? (Symfony Frontend FAQ)
Do I Need to Install Node.js on My Production Server? (Symfony Frontend FAQ)
Production Build & Deployment (SymfonyCast)
¹ Untars on the fly the archived GIT repository into the /tmp/myApp directory instead of into a TAR archive. Don't miss the leading / in the --prefix flag! git-archive docs.

profile-refresh in Fuse 6.2 does not reload snapshot bundle

I am running JBoss Fuse 6.2.0.
I built a small camel application that just writes to the log every 5 seconds.
I built it and installed the SNAPSHOT bundle jar in my local Maven repository.
In the Karaf console I did the following:
fabric:profile-create --parent feature-camel logdemo
fabric:profile-edit --bundle mvn:com.company.project/logdemo logdemo
fabric:container-create-child --profile logdemo root child1
The camel application now worked as intended.
I then made a small change to the application, rebuilt it and installed the new SNAPSHOT bundle jar in my local Maven repo.
In the Karaf console I then did the following to get Karaf to load the new jar:
fabric:profile-refresh logdemo
But the loaded application is still the old version.
How do I get Karaf to look for the updated jar in my local maven repo? It seems like it has some internal cache it looks in instead.
Note: We're not using Maven to build the application, so all answers about using Maven plugins like the fabric8 plugin will be rejected.
You should use the fabric:watch * command for that. This will update all containers that run a snapshot version of an artifact that is updated in the local maven repo. If you want only a specific container to watch for updates use dev:watch * on the shell of that container.
See http://fabric8.io/gitbook/developer.html

Composer misses to install certain files (app/console, AutoLoader.php, app_dev.php, etc.)

I am developing a web application with Symfony 2. The code of my own bundle that forms the heart of my application and some configurations files for application-wide settings are controlled by Git (mostly the directories, src/MyCompany/MyBundle, app/Resources/config, etc.) The rest is under control of Composer (the framework, 3rd party bundles, etc.)
Up to now, I ran a ./composer self-update && ./composer.phar update once in a while, pushed or fetched source code from the origin of my repository and everything has been working well.
Today, I started a new fresh working directory and experienced some odd problems.
I performed
git clone <my git repo url> www
cd www
composer.phar install
The composer.json is part of my repository, hence it normally suffices to excute Composer in order to install the framework and all required bundles to get a fully working copy of my web application.
But today, composer.phar install stopped prematurely complainig about missing files. Luckily, I still had my old working directory, so I could copy over the missing files manually, and restart composer.phar. I had to repeat these steps several times until I ended with a fully working application.
The files that were missing are
app/console
AutoLoader.php
app_dev.php
AppCache.php
I thought that these files are part of the Symfony framework and expected them to be installed by Composer. Fot this reason they are not under control of my revision control system.
I found this related question. The answer is very generic und not particularly helpful. All it says is that for example app/console should be included into revision control, because it is not installed by Composer (any longer) and that there is a change in the directory structure due to the transition from Symfony 2 to 3. But I know for sure that app/console was installed by Composer in the past. Hence, something changed.
This leads me to the following questions
Is there any complete, up-to-date and official documentation
what should be included in the repository
what should be in .gitignore
what is managed by Composer?
Is there any documentation how to do the transistion from the old directory structure to the new one in preperation of Symfony 3?
I thought I read all README.md, all release information and everything in "Living on the Edge" of the Symfony site, but somehow I missed this.
The clean way to install Symfony2 from scratch with composer, is to use the following command:
composer create-project symfony/framework-standard-edition my_project_name
This will ensure that all basic structures are created. After that, you can still insert your customisations from the previous project.
Then you can add everything – except app/config/parameters.yml as well as the contents of vendor/, app/cache and app/logs – to your repository.
About transitioning to SF3, I guess there’ll be an upgrade path as soon as SF3 is stable enough to create such a document.
1.1. that depends how you want people to be able to fetch your bundle
1.2. I share with you my own .gitignore: beware I use git for my own use to have a security for my files, not to allow people to get my bundle:
# Cache and logs (Symfony2)
/app/cache/*
/app/logs/*
!app/cache/.gitkeep
!app/logs/.gitkeep
# Cache and logs (Symfony3)
/var/cache/*
/var/logs/*
!var/cache/.gitkeep
!var/logs/.gitkeep
# Parameters
/app/config/parameters.yml
/app/config/parameters.ini
# Managed by Composer
/app/bootstrap.php.cache
/var/bootstrap.php.cache
/bin/*
!bin/console
!bin/symfony_requirements
/vendor/
# Assets and user uploads
/web/bundles/
/web/uploads/
# PHPUnit
/app/phpunit.xml
/phpunit.xml
# Build data
/build/
# Composer PHAR
1.3. everything that is in composer.json

Resources