Last active
November 10, 2020 16:37
-
-
Save ajardin/4be6914eeb42693da5464ece609e4fe7 to your computer and use it in GitHub Desktop.
Compiling Symfony projects into PHAR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compiles the project into a PHAR archive. | |
docker run --rm --interactive --tty --volume="$(pwd):/app" ajardin/humbug-box compile -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer create-project symfony/skeleton my-console | |
cd my-console && git init && git add . & git commit --message="Initial commit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /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