Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make task runners great again

GBProd
June 12, 2017

Make task runners great again

GBProd

June 12, 2017
Tweet

More Decks by GBProd

Other Decks in Programming

Transcript

  1. MAKE
    TASK RUNNER GREAT AGAIN
    @GillesRoustan

    View Slide

  2. BASH PHING COMPOSER
    ROBO BLDR GRUMPHP
    NPM GULP GRUNT...
    @GillesRoustan

    View Slide

  3. View Slide

  4. MAKE
    ONE TOOL TO RULE THEM ALL
    @GillesRoustan

    View Slide

  5. INDEPENDANT

    View Slide

  6. HOW-TO ?
    @GillesRoustan

    View Slide

  7. # Makefile
    target:[prerequisites]
    [recipe]

    View Slide

  8. # Makefile
    target:[prerequisites]
    \t [recipe]

    View Slide

  9. $ make target

    View Slide

  10. MAKE
    IS NOT A TASK RUNNER

    View Slide

  11. file.o: file.c
    gcc file.c -o file.o

    View Slide

  12. .PHONY: install
    install: file.o
    file.o: file.c
    gcc file.c -o file.o

    View Slide

  13. $ make install
    gcc file.c -o file.o
    ...

    View Slide

  14. $ make install
    Rien à faire pour la
    règle
    ...

    View Slide

  15. MAKE
    ME UP, BEFORE YOU GO GO
    @GillesRoustan

    View Slide

  16. vendor: composer.lock
    composer install
    composer.lock: composer.json
    composer update

    View Slide

  17. .PHONY: install
    install: vendor
    [...]

    View Slide

  18. $ make install
    composer install
    ...

    View Slide

  19. $ make --always-make install
    composer update
    ...

    View Slide

  20. .PHONY: install update
    update:
    $(MAKE) --always-make install
    install: vendor

    View Slide

  21. MAKE
    CONFIGURATION
    @GillesRoustan

    View Slide

  22. ENV = dev

    View Slide

  23. ENV ?= dev

    View Slide

  24. ENV ?= dev
    vendor: composer.lock
    ifeq ($(ENV), prod)
    composer install --no-dev
    --optimize-autoloader
    else
    composer install
    endif

    View Slide

  25. $ make install
    composer install
    ...

    View Slide

  26. $ make install ENV=prod
    composer install --no-dev
    --optimize-autoloader
    ...

    View Slide

  27. GREATER ?
    @GillesRoustan

    View Slide

  28. ENV ?= dev
    COMPOSER_ARGS ?=
    ifeq ($(ENV), prod)
    COMPOSER_ARGS= --no-dev
    --optimize-autoloader
    endif
    vendor: composer.lock
    composer install $(COMPOSER_ARGS)

    View Slide

  29. INCLUDE
    EH MAKE, ELLE EST OÙ MA CAISSE ?
    @GillesRoustan

    View Slide

  30. include *.mk

    View Slide

  31. include .env

    View Slide

  32. https://github.com/symfony/dotenv

    View Slide

  33. .env:
    @if [ ! -e .env ]; then \
    cp env.dist .env; \
    fi
    include .env

    View Slide

  34. MAKE
    CONTINOUS INTEGRATION GREAT AGAIN
    @GillesRoustan

    View Slide

  35. test-unit: install
    vendor/bin/phpunit $(PHPUNIT_ARGS)

    View Slide

  36. # .travis.yml
    sudo: required
    services:
    - docker
    script:
    - make test-unit

    View Slide

  37. MAKE
    IT WITH DOCKER
    @GillesRoustan

    View Slide

  38. test-unit: install
    docker exec -it my-container
    vendor/bin/phpunit

    View Slide

  39. EXEC=docker exec -it my-container
    test-unit: install
    $(EXEC) vendor/bin/phpunit

    View Slide

  40. MAKE
    FUNCTIONS ?
    @GillesRoustan

    View Slide

  41. test-unit: install
    $(call execute, vendor/bin/phpunit)
    define execute
    docker exec -it my-container $(1)
    @echo $(1) >> make.log
    endef

    View Slide

  42. DOCKER EST UN
    ENVIRONNEMENT

    View Slide

  43. # .env
    ENV=dev
    DOCKER=true

    View Slide

  44. ifeq ($(DOCKER), true)
    define execute
    docker exec -it my-container $(1)
    endef
    else
    define execute
    $(1)
    endef
    endif

    View Slide

  45. clean:
    $(call execute, \
    chmod -R 0777 var && \
    rm -Rf var/cache/prod && \
    rm -Rf var/cache/dev \
    )

    View Slide

  46. MAKE
    MONO-REPOSITORY
    @GillesRoustan

    View Slide

  47. .PHONY: install
    install:
    $(MAKE) --directory=app-php install

    View Slide

  48. .PHONY: install
    install:
    $(MAKE) -directory=app-php install
    $(MAKE) -directory=app-js install
    $(MAKE) -C app-ologies install
    $(MAKE) -C app-artement install
    $(MAKE) -C app-toum install
    $(MAKE) -C app-app-app install

    View Slide

  49. .PHONY: install
    install:
    $(MAKE) -directory=app-php install
    $(MAKE) -directory=app-js install
    $(MAKE) -C app-ologies install
    $(MAKE) -C app-artement install
    $(MAKE) -C app-toum install
    $(MAKE) -C app-app-app install

    View Slide

  50. MAKE
    MONO-REPOSITORY EASY !
    @GillesRoustan

    View Slide

  51. DIRS:=$(dir $(wildcard */))
    .PHONY: install $(DIRS)
    install: $(DIRS)
    test-unit: $(DIRS)
    $(DIRS):
    $(MAKE) [email protected] $(MAKECMDGOALS)

    View Slide

  52. MAKE
    I HELP YOU ?
    @GillesRoustan

    View Slide

  53. help: ## This help
    @grep -E '^[a-zA-Z_-]+:.*?## .*$$'
    $(TARGETS) | sort | awk 'BEGIN {FS =
    ":.*?## "}; {printf
    "\033[36m%-30s\033[0m %s\n", $$1,
    $$2}'

    View Slide

  54. help: ## This help
    @grep -E '^[a-zA-Z_-]+:.*?## .*$$'
    $(TARGETS) | sort | awk 'BEGIN {FS =
    ":.*?## "}; {printf
    "\033[36m%-30s\033[0m %s\n", $$1,
    $$2}'
    https://marmelab.com/blog/2016/02/29/au
    to-documented-makefile.html

    View Slide

  55. $ make help
    install Install app
    undate Update app
    test-unit Unit test app
    minify Minify js/css
    serve Run server
    ...

    View Slide

  56. ADOPTE UN
    MAKE

    View Slide

  57. https://github.com/gbprod/conf-makefile

    View Slide

  58. THANK YOU
    QUESTIONS ?

    View Slide