PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 31, 2022

[FIXED] How to manage version control and production deployments for compiled assets with Git and Grunt/Sass/Composer?

 January 31, 2022     compass-sass, composer-php, git, gruntjs, web-deployment     No comments   

Issue

I'm building an app in PHP + HTML + CSS + JS. This is the setup:

  • my PHP framework depends on Composer to setup/update
  • I'm using SCSS, so I have a folder for scss which gets compiled to the css folder
  • I'm automating compilation (and other stuff) via Grunt
  • I'm tracking everything with Git

When I deploy to staging/production I git clone (or git pull) the needed branch (develop or master) from the online Git repo.

I used to track almost everything with Git, including compiled CSS and installed PHP modules (via Composer), so that it was easy to deploy: I just had to pull from the online repo end everything was done.

But I feel tracking all this stuff in Git is not good as I think I should just track the source files (SCSS for CSS, composer.json/composer.lock for PHP modules).

Now my questions are:

  • is it correct I shouldn't be tracking CSS compiled files but only SCSS files?
  • same for PHP modules installed via Composer
  • if I don't track all the files and I deploy via git pull I'll need to have Grunt/Compass/Composer installed in all machines (staging/production) and that doesn't feel right to me as I consider them building tools and not parts of the app
  • what are best practices in using Git with Grunt/Compass/Composer (or similar stuff) for deployment?

Any advice/suggestion would be greatly appreciated!


Solution

One answer (that we use) is to do your asset compilation on a continuous integration machine. We consider this to be our staging environment.
From here we copy the compiled files to production (i.e. we don't generate them in production as well).

In some cases you may want to allow developers to compile locally (if the framework requires it for development) but ignore those files/directories when pushing to a remote. This is essentially the process we use for our Ruby on Rails gem files that are handled by bundler. A little different from css/js assets but involving similar concepts of compiled or changed files.



Answered By - Michael Durrant
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing