Skip to content

Instantly share code, notes, and snippets.

@ajardin
Last active November 10, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajardin/4be6914eeb42693da5464ece609e4fe7 to your computer and use it in GitHub Desktop.
Save ajardin/4be6914eeb42693da5464ece609e4fe7 to your computer and use it in GitHub Desktop.
Compiling Symfony projects into PHAR
# Compiles the project into a PHAR archive.
docker run --rm --interactive --tty --volume="$(pwd):/app" ajardin/humbug-box compile -vvv
composer create-project symfony/skeleton my-console
cd my-console && git init && git add . & git commit --message="Initial commit"
rm -rf \
config/packages/prod/ \
config/packages/routing.yaml \
config/routes.yaml \
config/routes/ \
public/ \
src/Controller
--- config/services.yaml
+++ config/services.yaml
- # controllers are imported separately to make sure services can be injected
- # as action arguments even if you don't extend any base controller class
- App\Controller\:
- resource: '../src/Controller/'
- tags: ['controller.service_arguments']
-
--- src/Kernel.php
+++ src/Kernel.php
- $routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
- $routes->import('../config/{routes}/*.yaml');
-
- if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
- $routes->import('../config/{routes}.yaml');
- } elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) {
- (require $path)($routes->withPath($path), $this);
- }
git add . && git commit --message="Remove useless files"
--- a/composer.json
+++ b/composer.json
"scripts": {
"auto-scripts": {
- "cache:clear": "symfony-cmd",
- "assets:install %PUBLIC_DIR%": "symfony-cmd"
+ "cache:clear": "symfony-cmd"
},
- "post-install-cmd": [
- "@auto-scripts"
- ],
- "post-update-cmd": [
+ "post-autoload-dump": [
"@auto-scripts"
]
},
--- a/box.json
+++ b/box.json
+{
+ "main": "bin/console",
+ "directories": [
+ "config",
+ "src",
+ "vendor"
+ ],
+ "files": [
+ ".env.local.php"
+ ],
+ "output": "build/my-console.phar"
+}
git add . && git commit --message="Add the PHAR compilation support"
--- /dev/null
+++ b/Makefile
+##
+## ----------------------------------------------------------------------------
+## MY CONSOLE
+## ----------------------------------------------------------------------------
+##
+
+# Checks if the GITHUB_ACTIONS environment variable is defined, useful for allowing the "--tty" flag locally but not in GitHub Actions.
+export TTY := $(shell if [ -z "$${GITHUB_ACTIONS}" ]; then echo "--tty"; else echo ""; fi)
+
+box: ## Compiles the project into a PHAR archive
+ composer dump-env prod
+ ./bin/console cache:clear
+ ./bin/console cache:warmup
+ docker run --rm --interactive $${TTY} --volume="$$(pwd):/app:delegated" ajardin/humbug-box compile -vvv
+ rm .env.local.php
+.PHONY: box
+
+help:
+ @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) \
+ | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' \
+ | sed -e 's/\[32m##/[33m/'
+.DEFAULT_GOAL := help
git add . && git commit --message="Add the Makefile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment