diff --git a/README.md b/README.md index 8bbfd12..ab81113 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# manala-recipes \ No newline at end of file +# manala-recipes +Manala recipes for EDRom. diff --git a/edrom.app-docker/.manala.yaml b/edrom.app-docker/.manala.yaml new file mode 100644 index 0000000..768f075 --- /dev/null +++ b/edrom.app-docker/.manala.yaml @@ -0,0 +1,50 @@ +manala: + description: EDRom - Generic application using Docker + template: .manala.yaml.tmpl + sync: + - .manala/ + - docker-compose.yaml.tmpl + - php.ini.tmpl + +system: + # @option {"label": "App name (in kebab-case)"} + # @schema {"type": "string"} + app_name: ~ + # @schema {"type": ["string"], "pattern": "^[a-zA-Z]+/[a-zA-Z]+$"} + timezone: Etc/UTC + php: + # @schema { + # "items": {"type": "object", + # "additionalProperties": false, + # "properties": { + # "config": {"type": ["object", "string", "array"]} + # } + # } + # } + configs: [] + mariadb: + # @option {"label": "MariaDB version"} + # @schema {"enum": [null, 10.5, 10.4, 10.3, 10.2, 10.1, "10.0"]} + version: ~ + # @schema {"type": ["string", "null"]} + init: ~ + mysql: + # @option {"label": "MySQL version"} + # @schema {"enum": [null, 5.7, 8, "8.0"]} + version: ~ + # @schema {"type": ["string", "null"]} + init: ~ + postgresql: + # @option {"label": "PostgreSQL version"} + # @schema {"enum": [null, 13, 12, 11, 10, 9.6]} + version: ~ + redis: + # @option {"label": "Redis version"} + # @schema {"enum": [null, "*"]} + version: ~ + # @schema {"type": ["object", "array"]} + config: { } + mongo: + # @option {"label": "MongoDB version"} + # @schema {"enum": [null, "3.6", "4"]} + version: ~ diff --git a/edrom.app-docker/.manala.yaml.tmpl b/edrom.app-docker/.manala.yaml.tmpl new file mode 100644 index 0000000..dffd447 --- /dev/null +++ b/edrom.app-docker/.manala.yaml.tmpl @@ -0,0 +1,64 @@ +{{- with .Vars.system -}} + +#################################################################### +# !!! REMINDER !!! # +# Don't forget to run `manala up` each time you update this file ! # +#################################################################### + +manala: + recipe: edrom.app-docker + repository: https://github.com/RomulusED69/manala-recipes.git + +########## +# System # +########## + +system: + app_name: {{ .app_name | toYaml }} + timezone: Etc/UTC + + php: + configs: + # XDebug + - config: | + ; Comment/uncomment the following lines to disable/enable XDebug + ;zend_extension=xdebug.so + ;xdebug.remote_enable=1 + ;xdebug.remote_autostart=1 + + # App + - config: | + ;App specific configuration + + {{- if .mariadb.version }} + mariadb: + version: {{ .mariadb.version | toYaml }} + init: | + CREATE DATABASE IF NOT EXISTS `app_test`; + GRANT ALL ON `app_test`.* TO 'app'@'%'; + {{- end }} + + {{- if .mysql.version }} + mysql: + version: {{ .mysql.version | toYaml }} + init: | + CREATE DATABASE IF NOT EXISTS `app_test`; + GRANT ALL ON `app_test`.* TO 'app'@'%'; + {{- end }} + + {{- if .postgresql.version }} + postgresql: + version: {{ .postgresql.version | toYaml }} + {{- end }} + + {{- if .redis.version }} + redis: + version: {{ .redis.version | toYaml }} + {{- end }} + + {{- if .mongo.version }} + mongo: + version: {{ .mongo.version | toYaml }} + {{- end }} + +{{- end }} diff --git a/edrom.app-docker/.manala/.dockerignore b/edrom.app-docker/.manala/.dockerignore new file mode 100644 index 0000000..a415801 --- /dev/null +++ b/edrom.app-docker/.manala/.dockerignore @@ -0,0 +1,2 @@ +/.cache/ +/.docker/ diff --git a/edrom.app-docker/.manala/.gitignore b/edrom.app-docker/.manala/.gitignore new file mode 100644 index 0000000..a415801 --- /dev/null +++ b/edrom.app-docker/.manala/.gitignore @@ -0,0 +1,2 @@ +/.cache/ +/.docker/ diff --git a/edrom.app-docker/.manala/DOT_NOT_MANUALLY_EDIT b/edrom.app-docker/.manala/DOT_NOT_MANUALLY_EDIT new file mode 100644 index 0000000..03e8f1d --- /dev/null +++ b/edrom.app-docker/.manala/DOT_NOT_MANUALLY_EDIT @@ -0,0 +1,10 @@ +############################################################### +# !!! DO NOT DIRECTLY EDIT FILES IN THIS DIRECTORY !!! # +# # +# The files in this directory must not updated directly. # +# By doing this, you will lost ALL your modifications when # +# updating your .manala.yaml and running "manala up". # +# # +# If you really need to update those files, contribute to the # +# recipe or create one that will fill your requirements! # +############################################################### diff --git a/edrom.app-docker/.manala/Makefile.tmpl b/edrom.app-docker/.manala/Makefile.tmpl new file mode 100644 index 0000000..44e2684 --- /dev/null +++ b/edrom.app-docker/.manala/Makefile.tmpl @@ -0,0 +1,121 @@ +{{- $has_postgresql := .Vars.system.postgresql.version -}} +{{- $has_mariadb := .Vars.system.mariadb.version -}} +{{- $has_mysql := .Vars.system.mysql.version -}} +{{- $has_redis := .Vars.system.redis.version -}} +{{- $has_mongo := .Vars.system.mongo.version -}} + +# Relative root dir ("."|".."|"../.."|…) +_ROOT_DIR := $(patsubst ./%,%,$(patsubst %/.manala/Makefile,%,./$(filter %.manala/Makefile,$(MAKEFILE_LIST)))) +# Is current dir root ? (""|"1") +_ROOT := $(if $(filter .,$(_ROOT_DIR)),1) +# Relative current dir ("."|"foo"|"foo/bar"|…) +_DIR := $(patsubst ./%,%,.$(patsubst $(realpath $(CURDIR)/$(_ROOT_DIR))%,%,$(CURDIR))) + +include $(_ROOT_DIR)/.manala/make/text.mk +include $(_ROOT_DIR)/.manala/make/help.mk +include $(_ROOT_DIR)/.manala/make/os.mk +include $(_ROOT_DIR)/.manala/make/git.mk + +.DEFAULT_GOAL := help + +user := $(shell id -u) +group := $(shell id -g) + +dc := USER_ID=$(user) GROUP_ID=$(group) docker-compose +symfony := symfony +php := $(symfony) php +composer := $(symfony) composer + +HELP += $(call help_section, Environment) + +HELP += $(call help,setup, Setup the development environment) +setup: setup-symfony + $(MAKE) up + $(setup) + @echo + @$(call message_success, The development environment has been successfully set up.) + @echo + +HELP += $(call help,setup@integration, Setup the integration environment) +setup@integration: export APP_ENV=test +setup@integration: setup-symfony@integration + $(MAKE) _up + $(setup_integration) + @echo + @$(call message_success, The integration environment has been successfully set up.) + @echo + +setup-symfony: + $(symfony) server:ca:install + $(symfony) proxy:start + $(MAKE) setup-domain + +setup-symfony@integration: + $(symfony) server:ca:install + +setup-domain: + $(symfony) proxy:domain:attach {{ .Vars.system.app_name }} + +_up: + $(dc) up --detach + {{- if or ($has_postgresql) ($has_mariadb) ($has_mysql) }} database{{ end }} + {{- if $has_redis }} redis{{ end }} + {{- if $has_mongo }} mongo{{ end }} + + {{ if or ($has_postgresql) ($has_mariadb) ($has_mysql) -}} + @$(call message_warning, Waiting for the database to be ready...) + @until docker inspect -f {{ "{{.State.Health.Status}}" }} `$(dc) ps -q database` | grep -q "healthy"; do \ + $(call message_warning, Waiting...); \ + sleep 1; \ + done + @$(call message_success, The database is ready!) + {{- end }} + +HELP += $(call help,up, Start the development environment) +up: + $(MAKE) _up + $(symfony) proxy:start + @echo + @$(call message_success, You can now run the Symfony server) + @echo + +HELP += $(call help,halt, Stop the development environment) +halt: + $(dc) stop + +HELP += $(call help,destroy, Destroy the development environment) +destroy: halt + $(dc) down --volumes + @echo + @$(call message_error, ALL CONTAINERS HAVE BEEN DESTROYED) + @echo + +HELP += $(call help_section, Development tools) + +{{- if $has_postgresql -}} +HELP += $(call help,run-phppgadmin, Start a PhpPgAdmin web interface) +run-phppgadmin: + $(dc) up --detach phppgadmin + @echo + @$(call message_success, You can now open http://`$(dc) port phppgadmin 8080` to access PhpPgAdmin) + @echo +{{- end }} + +{{ if or ($has_mariadb) ($has_mysql) -}} +HELP += $(call help,run-phpmyadmin, Start a PhpMyAdmin web interface) +run-phpmyadmin: + $(dc) up --detach phpmyadmin + @echo + @$(call message_success, You can now open http://`$(dc) port phpmyadmin 80` to access PhpMyAdmin) + @echo +{{- end }} + +{{ if $has_redis -}} +HELP += $(call help,run-phpredisadmin, Start a PhpRedisAdmin web interface) +run-phpredisadmin: + $(dc) up --detach phpredisadmin + @echo + @$(call message_success, You can now open http://`$(dc) port phpredisadmin 80` to access PhpRedisAdmin) + @echo{{- end }} + +HELP += $(call help_section, Project) diff --git a/edrom.app-docker/.manala/init-db/01.sql.tmpl b/edrom.app-docker/.manala/init-db/01.sql.tmpl new file mode 100644 index 0000000..b9624b6 --- /dev/null +++ b/edrom.app-docker/.manala/init-db/01.sql.tmpl @@ -0,0 +1,7 @@ +{{- if .Vars.system.mariadb.init -}} +{{- .Vars.system.mariadb.init -}} +{{- end -}} + +{{- if .Vars.system.mysql.init -}} +{{- .Vars.system.mysql.init -}} +{{- end -}} diff --git a/edrom.app-docker/.manala/make/git.mk b/edrom.app-docker/.manala/make/git.mk new file mode 100644 index 0000000..69b036d --- /dev/null +++ b/edrom.app-docker/.manala/make/git.mk @@ -0,0 +1,30 @@ +######## +# Diff # +######## + +# Returns the list of changed files for some given extensions and some given folders. +# +# @param $1 The file extensions of changed files +# @param $2 The relative folders to parse for changed files +# +# Examples: +# +# Example #1: list PHP and Javascript files changed in the src and test folders +# +# $(call git_diff, php js, src test) + +define git_diff +$(shell \ + for ext in $(if $(strip $(1)),$(strip $(1)),"") ; \ + do \ + for dir in $(if $(strip $(2)),$(strip $(2)),"") ; \ + do \ + git --no-pager diff --name-status "$$(git merge-base HEAD origin/master)" \ + | grep "$${ext}\$$" \ + | grep "\\s$${dir}" \ + | grep -v '^D' \ + | awk '{ print $$NF }' || true ; \ + done ; \ + done \ +) +endef diff --git a/edrom.app-docker/.manala/make/help.mk b/edrom.app-docker/.manala/make/help.mk new file mode 100644 index 0000000..686017b --- /dev/null +++ b/edrom.app-docker/.manala/make/help.mk @@ -0,0 +1,42 @@ +######## +# Help # +######## + +HELP = \ + \nUsage: make [$(COLOR_INFO)target$(COLOR_RESET)] \ + $(call help_section, Help) \ + $(call help,help,This help) + +define help_section + \n\n$(COLOR_COMMENT)$(strip $(1)):$(COLOR_RESET) +endef + +define help + \n $(COLOR_INFO)$(1)$(COLOR_RESET) $(2) +endef + +help: + @printf "$(HELP)$(HELP_SUFFIX)" + @awk ' \ + /^[-a-zA-Z0-9_.@%\/]+:/ { \ + hasMessage = match(lastLine, /^## (.*)/); \ + if (hasMessage) { \ + lines++; \ + helpCommands[lines] = substr($$1, 0, index($$1, ":")); \ + helpLenght = length(helpCommands[lines]); \ + if (helpLenght > helpLenghtMax) { \ + helpLenghtMax = helpLenght; \ + } \ + helpMessages[lines] = substr(lastLine, RSTART + 3, RLENGTH); \ + } \ + } \ + { lastLine = $$0 } \ + END { \ + for (i = 1; i <= lines; i++) { \ + printf "\n $(COLOR_INFO)%-" helpLenghtMax "s$(COLOR_RESET) %s", helpCommands[i], helpMessages[i]; \ + } \ + } \ + ' $(MAKEFILE_LIST) + @printf "\n\n" + +.PHONY: help diff --git a/edrom.app-docker/.manala/make/os.mk b/edrom.app-docker/.manala/make/os.mk new file mode 100644 index 0000000..d7ff1e9 --- /dev/null +++ b/edrom.app-docker/.manala/make/os.mk @@ -0,0 +1,21 @@ +###### +# Os # +###### + +# Os detection helpers. +# +# Examples: +# +# Example #1: conditions on linux +# +# echo $(if $(OS_LINUX),Running on Linux,*NOT* running on Linux) + +ifeq ($(OS),Windows_NT) + OS = windows +else + OS = $(shell uname | tr '[:upper:]' '[:lower:]') +endif + +OS_LINUX = $(if $(findstring $(OS),linux),1,) +OS_DARWIN = $(if $(findstring $(OS),darwin),1,) +OS_WINDOWS = $(if $(findstring $(OS),windows),1,) diff --git a/edrom.app-docker/.manala/make/text.mk b/edrom.app-docker/.manala/make/text.mk new file mode 100644 index 0000000..51add33 --- /dev/null +++ b/edrom.app-docker/.manala/make/text.mk @@ -0,0 +1,91 @@ +########## +# Colors # +########## + +COLOR_RESET := \033[0m +COLOR_ERROR := \033[31m +COLOR_INFO := \033[32m +COLOR_WARNING := \033[33m +COLOR_COMMENT := \033[36m + +###################### +# Special Characters # +###################### + +# Usage: +# $(call message, Foo$(,) bar) = Foo, bar + +, := , + +######## +# Time # +######## + +# Usage: +# $(call time) = 11:06:20 + +define time +`date -u +%T` +endef + +########### +# Message # +########### + +# Usage: +# $(call message, Foo bar) = Foo bar +# $(call message_success, Foo bar) = (っ◕‿◕)っ Foo bar +# $(call message_warning, Foo bar) = ¯\_(ツ)_/¯ Foo bar +# $(call message_error, Foo bar) = (╯°□°)╯︵ ┻━┻ Foo bar + +define message + printf "$(COLOR_INFO)$(strip $(1))$(COLOR_RESET)\n" +endef + +define message_success + printf "$(COLOR_INFO)(っ◕‿◕)っ $(strip $(1))$(COLOR_RESET)\n" +endef + +define message_warning + printf "$(COLOR_WARNING)$(strip $(1))$(COLOR_RESET)\n" +endef + +define message_error + printf "$(COLOR_ERROR)(╯°□°)╯︵ ┻━┻ $(strip $(1))$(COLOR_RESET)\n" +endef + +########### +# Confirm # +########### + +# Usage: +# $(call confirm, Foo bar) = ༼ つ ◕_◕ ༽つ Foo bar (y/N): + +define confirm + $(if $(CONFIRM),, \ + printf "$(COLOR_INFO) ༼ つ ◕_◕ ༽つ $(COLOR_WARNING)$(strip $(1)) $(COLOR_RESET)$(COLOR_WARNING)(y/N)$(COLOR_RESET): "; \ + read CONFIRM ; if [ "$$CONFIRM" != "y" ]; then printf "\n"; exit 1; fi; \ + ) +endef + +####### +# Log # +####### + +# Usage: +# $(call log, Foo bar) = [11:06:20] [target] Foo bar +# $(call log_warning, Foo bar) = [11:06:20] [target] ¯\_(ツ)_/¯ Foo bar +# $(call log_error, Foo bar) = [11:06:20] [target] (╯°□°)╯︵ ┻━┻ Foo bar +# $(call log_and_call, echo 'Message') = [11:06:20] [target] echo 'Message' then execute the command + +define log + printf "[$(COLOR_COMMENT)$(call time)$(COLOR_RESET)] [$(COLOR_COMMENT)$(@)$(COLOR_RESET)] " ; $(call message, $(1)) +endef + +define log_warning + printf "[$(COLOR_COMMENT)$(call time)$(COLOR_RESET)] [$(COLOR_COMMENT)$(@)$(COLOR_RESET)] " ; $(call message_warning, $(1)) +endef + +define log_error + printf "[$(COLOR_COMMENT)$(call time)$(COLOR_RESET)] [$(COLOR_COMMENT)$(@)$(COLOR_RESET)] " ; $(call message_error, $(1)) +endef diff --git a/edrom.app-docker/README.md b/edrom.app-docker/README.md new file mode 100644 index 0000000..4272ea1 --- /dev/null +++ b/edrom.app-docker/README.md @@ -0,0 +1,313 @@ +# EDRom - App (Docker) + +A [Manala recipe](https://github.com/manala/manala-recipes) for projects using the Symfony CLI, PHP, Node.js, PostgreSQL/MariaDB and Redis. + +--- + +## Requirements + +* [manala](https://manala.github.io/manala/) +* [Docker Desktop 2.2.0+](https://docs.docker.com/engine/install/) +* Symfony CLI (with [local proxy support](https://symfony.com/doc/current/setup/symfony_server.html#setting-up-the-local-proxy)), PHP and Node.js must be installed by yourself on your machine + +## Init + +``` +$ cd [workspace] +$ manala init -i edrom.app-docker --repository https://github.com/RomulusED69/manala-recipes.git [project] +``` + +## Configure PHP and Node.js versions + +Since this recipe relies on having PHP and Node.js by yourself (with phpenv, ondrej's PPA, brew, nvm, etc...), +it's important to create two files `.php-version` and `.nvmrc` which will contains the PHP and Node.js versions to use for your project. + +```shell +cd /path/to/my/app +echo 8.0 > .php-version # Use PHP 8.0 +echo 14 > .nvmrc # Use Node.js 14 +``` + +Those files will be used by: +- The Symfony CLI when using `symfony php` and `symfony composer` (eg: `symfony console cache:clear, `symfony composer install) +- NVM when using `nvm use` +- GitHub Actions, thanks to [the action `setup-environment`](#github-actions) + +**It is important to use `symfony php` and not `php` directly for running commands, thanks to its [Docker integration](https://symfony.com/doc/current/setup/symfony_server.html#docker-integration) +it automatically exposes environments variables from Docker (eg: `DATABASE_URL`, `REDIS_URL`, ...) to PHP.** + +## Quick start + +In a shell terminal, change directory to your app, and run the following commands: + +```shell +cd /path/to/my/app +manala init --repository https://github.com/RomulusED69/manala-recipes.git +Select the "edrom.app-docker" recipe +``` + +Edit the `Makefile` at the root directory of your project and add the following lines at the beginning of the file: + +```makefile +-include .manala/Makefile + +# This function will be called at the end of "make setup" +define setup + # For example: + # $(MAKE) install-app + # $(MAKE) init-db@test +endef + +# This function will be called at the end of "make setup@integration" +define setup_integration + # For example: + # $(MAKE) install-app@integration +endef +``` + +Then update the `.manala.yaml` file (see [the releases example](#releases) below) and then run the `manala up` command: + +```shell +manala up +``` + +**Don't forget to run the `manala up` command each time you update the `.manala.yaml` file to actually apply your changes** + +From now on, if you execute the `make help` command in your console, you should obtain the following output: + +```shell +Usage: make [target] + +Help: + help This help + +Environment: + setup Setup the development environment + setup@integration Setup the integration environment + up Start the development environment + halt Stop the development environment + destroy Destroy the development environment + +Project: + install-app: Install application + install-app@integration: Install application in integration environment +``` + +## Docker interaction + +Initialise Docker Compose containers and your app: +```bash +make setup +``` + +Start Docker Compose containers: +```bash +make up +``` + +Stop Docker Compose containers: +```bash +make halt +``` + +Stop and remove Docker Compose containers: +```shell +make destroy +``` + +## System + +Here is an example of a system configuration in `.manala.yaml`: + +```yaml +########## +# System # +########## + +system: + app_name: your-app + postgresql: + version: 12 + redis: + version: '*' +``` + +## Integration + +### GitHub Actions + +Since this recipe generates a `docker-compose.yaml` file, it can +be used to provide a fully-fledged environnement according to your project needs on GitHub Actions. + +```yaml +name: CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +env: + TZ: UTC + +jobs: + php: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + # The code of this local action can be found below + - uses: ./.github/actions/setup-environment + + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.PHP_VERSION }} # PHP_VERSION comes from setup-environment local action + coverage: none + extensions: iconv, intl + ini-values: date.timezone=${{ env.TZ }} + tools: symfony + + - uses: actions/setup-node@v2 + with: + node-version: ${{ env.NODE_VERSION }} # NODE_VERSION comes from setup-environment local action + + - uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - uses: actions/cache@v2 + with: + path: ${{ env.YARN_CACHE_DIR }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- + + # Will setup the Symfony CLI and build Docker Compose containers + # No need to create DATABASE_URL or REDIS_URL environment variables, they will be + # automatically injected to PHP/Symfony thanks to the Symfony CLI's Docker Integration + - run: make setup@integration + + # Check versions + - run: symfony php -v # PHP 8.0.3 + - run: node -v # Node.js 14.16.0 + + # Run some tests... remember to use "symfony php" and not "php" + - run: symfony console cache:clear + - run: symfony console lint:twig templates + - run: symfony console lint:yaml config --parse-tags + - run: symfony console lint:xliff translations + +``` + +This is the code of local action `setup-environment`: +```yaml +# .github/actions/setup-environment/action.yml +name: Setup environment +description: Setup environment +runs: + using: 'composite' + steps: + - run: echo "PHP_VERSION=$(cat .php-version | xargs)" >> $GITHUB_ENV + shell: bash + + - run: echo "NODE_VERSION=$(cat .nvmrc | xargs)" >> $GITHUB_ENV + shell: bash + + # Composer cache + - id: composer-cache + run: echo "::set-output name=dir::$(composer global config cache-files-dir)" + shell: bash + + - run: echo "COMPOSER_CACHE_DIR=${{ steps.composer-cache.outputs.dir }}" >> $GITHUB_ENV + shell: bash + + # Yarn cache + - id: yarn-cache-dir + run: echo "::set-output name=dir::$(yarn cache dir)" + shell: bash + + - run: echo "YARN_CACHE_DIR=${{ steps.yarn-cache-dir.outputs.dir }}" >> $GITHUB_ENV + shell: bash +``` + +### Common integration tasks + +Add in your `Makefile`: + +```makefile +# ... + +# This function will be called during "make setup" +define setup + $(MAKE) install-app + $(MAKE) init-db@test +endef + +# This function will be called during "make setup@integration" +define setup_integration + $(MAKE) install-app@integration +endef + +########### +# Install # +########### + +## Install application +install-app: composer-install init-db +install-app: + $(symfony) console cache:clear + yarn install + yarn dev + +## Install application in integration environment +install-app@integration: export APP_ENV=test +install-app@integration: + $(composer) install --ansi --no-interaction --no-progress --prefer-dist --optimize-autoloader + yarn install --color=always --no-progress --frozen-lockfile + yarn dev + $(MAKE) init-db@integration + +################ +# Common tasks # +################ + +composer-install: + $(composer) install --ansi --no-interaction + +init-db: + $(symfony) console doctrine:database:drop --force --if-exists --no-interaction + $(symfony) console doctrine:database:create --no-interaction + $(symfony) console doctrine:schema:update --force --no-interaction # to remove when we will use migrations + # $(symfony) console doctrine:migrations:migrate --no-interaction + $(symfony) console hautelook:fixtures:load --no-interaction + +init-db@test: export APP_ENV=test +init-db@test: init-db + +init-db@integration: export APP_ENV=test +init-db@integration: + $(symfony) console doctrine:database:create --if-not-exists --no-interaction + $(symfony) console doctrine:schema:update --force --no-interaction # to remove when we will use migrations + # $(symfony) console doctrine:migrations:migrate --no-interaction + $(symfony) console hautelook:fixtures:load --no-interaction + +reload-db@test: export APP_ENV=test +reload-db@test: + $(symfony) console hautelook:fixtures:load --purge-with-truncate --no-interaction +``` + +### Tools + +#### Admin UI for database + +- If you use PostgreSQL, run `make run-phppgadmin` to run a local [PhpPgAdmin](https://github.com/phppgadmin/phppgadmin) instance +- If using MariaDB, run `make run-phpmyadmin` to run a local [PhpMyAdmin](https://github.com/phpmyadmin/phpmyadmin) instance + +#### Admin UI for Redis + +Run `make run-phpredisadmin` to run a local [PhpRedisAdmin](https://github.com/erikdubbelboer/phpRedisAdmin) instance. + +#### Admin UI for Mongo + +You can use `Compass` a GUI for MongoDB, install it from here : [Compass](https://www.mongodb.com/try/download/compass). +Once installed, retrieve Mongo Docker exposed port with `docker ps --filter "name=mongo"` and use this port in the connection string. diff --git a/edrom.app-docker/docker-compose.yaml.tmpl b/edrom.app-docker/docker-compose.yaml.tmpl new file mode 100644 index 0000000..51533af --- /dev/null +++ b/edrom.app-docker/docker-compose.yaml.tmpl @@ -0,0 +1,146 @@ +################################################################## +# This file is automatically generated when running "manala up". # +################################################################## + +version: '3.6' + +{{- $has_postgresql := .Vars.system.postgresql.version -}} +{{- $has_mariadb := .Vars.system.mariadb.version -}} +{{- $has_mysql := .Vars.system.mysql.version -}} +{{- $has_redis := .Vars.system.redis.version -}} +{{- $has_mongo := .Vars.system.mongo.version -}} + +{{ if or ($has_postgresql) ($has_mariadb) ($has_mysql) ($has_redis) ($has_mongo) }} + +volumes: + {{ if or ($has_postgresql) ($has_mariadb) ($has_mysql) -}} + db-data: + {{- end }} + {{ if $has_redis -}} + redis-data: + {{- end }} + {{ if $has_mongo -}} + mongo-data: + {{- end }} +{{- end }} + +services: +{{- if $has_postgresql -}} +{{- $postgresql := .Vars.system.postgresql }} + + database: + image: 'postgres:{{ $postgresql.version }}-alpine' + ports: [5432] + environment: + POSTGRES_USER: 'app' + POSTGRES_PASSWORD: 'app' + POSTGRES_DB: 'app' + TZ: {{ .Vars.system.timezone }} + PGTZ: {{ .Vars.system.timezone }} + volumes: + - db-data:/var/lib/postgresql/data + healthcheck: + test: pg_isready + interval: 10s + timeout: 5s + retries: 5 + + phppgadmin: + image: bitnami/phppgadmin + ports: [8080] + environment: + DATABASE_HOST: 'database' + +{{- end }} + +{{- if $has_mariadb -}} +{{- $mariadb := .Vars.system.mariadb }} + + database: + image: 'mariadb:{{ $mariadb.version }}' + ports: [3306] + environment: + MYSQL_USER: 'app' + MYSQL_PASSWORD: 'app' + MYSQL_DATABASE: 'app' + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + TZ: {{ .Vars.system.timezone }} + volumes: + - db-data:/var/lib/mysql + - .manala/init-db:/docker-entrypoint-initdb.d + healthcheck: + test: mysqladmin ping --silent + interval: 10s + timeout: 5s + retries: 5 + +{{- end }} + +{{- if $has_mysql -}} +{{- $mysql := .Vars.system.mysql }} + + database: + image: 'mysql:{{ $mysql.version }}' + ports: [3306] + environment: + MYSQL_USER: 'app' + MYSQL_PASSWORD: 'app' + MYSQL_DATABASE: 'app' + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + TZ: {{ .Vars.system.timezone }} + volumes: + - db-data:/var/lib/mysql + - .manala/init-db:/docker-entrypoint-initdb.d + healthcheck: + test: mysqladmin ping --silent + interval: 10s + timeout: 5s + retries: 5 + +{{- end }} + +{{- if or ($has_mariadb) ($has_mysql) }} + + phpmyadmin: + image: phpmyadmin + ports: [80] + environment: + PMA_HOST: 'database' + PMA_USER: 'app' + PMA_PASSWORD: 'app' + +{{- end }} + +{{- if $has_redis }} + + redis: + image: 'redis:alpine' + ports: [6379] + environment: + TZ: {{ .Vars.system.timezone }} + volumes: + - redis-data:/data + + phpredisadmin: + image: erikdubbelboer/phpredisadmin + ports: [80] + environment: + REDIS_1_HOST: 'redis' + +{{- end }} + +{{- if $has_mongo }} +{{- $mongo := .Vars.system.mongo }} + + mongo: + image: 'mongo:{{ $mongo.version }}-stretch' + ports: [27017] + environment: + MONGO_INITDB_DATABASE: 'app' + MONGO_INITDB_ROOT_USERNAME: 'app' + MONGO_INITDB_ROOT_PASSWORD: 'app' + TZ: {{ .Vars.system.timezone }} + volumes: + - mongo-data:/data/db + +{{- end }} diff --git a/edrom.app-docker/php.ini.tmpl b/edrom.app-docker/php.ini.tmpl new file mode 100644 index 0000000..2b008bf --- /dev/null +++ b/edrom.app-docker/php.ini.tmpl @@ -0,0 +1,10 @@ +;################################################################## +;# This file is automatically generated when running "manala up". # +;################################################################## + +[Date] +date.timezone = {{ .Vars.system.timezone }} + +{{ range .Vars.system.php.configs }} + {{- .config }} +{{ end -}} diff --git a/edrom.app/.manala.yaml b/edrom.app/.manala.yaml new file mode 100644 index 0000000..f18cf76 --- /dev/null +++ b/edrom.app/.manala.yaml @@ -0,0 +1,141 @@ +manala: + description: EDRom - Generic application with PHP and Node.js support + template: .manala.yaml.tmpl + sync: + - .manala/ansible + - .manala/docker + - .manala/github + - .manala/make + - .manala/vagrant + - .manala/.dockerignore + - .manala/.gitignore + - .manala/DO_NOT_MANUALLY_EDIT + - .manala/Dockerfile.tmpl + - .manala/Makefile.tmpl + - .manala/Vagrantfile.tmpl + - Makefile.tmpl + - vagrant-wrapper.sh + +system: + # @option {"label": "System version"} + # @schema {"enum": [10]} + version: ~ + # @option {"label": "Hostname"} + # @schema {"type": "string", "format": "domain"} + hostname: ~ + # @schema {"type": ["integer", "null"]} + memory: 2048 + # @schema {"type": ["integer", "null"]} + cpus: 2 + # @schema {"type": ["string"], "pattern": "^[a-zA-Z]+/[a-zA-Z]+$"} + timezone: Etc/UTC + locales: + # @schema {"type": ["string"]} + default: C.UTF-8 + # @schema {"items": {"type": "string"}} + codes: [] + # @schema { + # "additionalProperties": {"type": ["string", "integer"]}, + # "propertyNames": {"pattern": "^[A-Z_]+$"} + # } + env: {} + apt: + # @schema {"items": {"type": "string"}} + repositories: [] + # @schema {"items": {"type": "string"}} + preferences: [] + # @schema {"items": {"type": "string"}} + packages: [] + # @schema {"items": {"type": "string"}} + holds: [] + # @schema {"items": {"type": "object"}} + files: [] + nginx: + # @schema { + # "items": {"type": "object", + # "additionalProperties": false, + # "properties": { + # "template": {"type": "string"}, + # "file": {"type": "string"}, + # "config": {"type": ["string", "array"]}, + # "content": {"type": "string"} + # } + # } + # } + configs: [] + php: + # @option {"label": "Php version"} + # @schema {"enum": [null, "8.0", 7.4, 7.3, 7.2, 7.1, "7.0", 5.6]} + version: ~ + # @schema {"items": {"type": "string"}} + extensions: [] + # @schema { + # "items": {"type": "object", + # "additionalProperties": false, + # "properties": { + # "template": {"type": "string"}, + # "file": {"type": "string"}, + # "config": {"type": ["object", "string", "array"]} + # } + # } + # } + configs: [] + composer: + # @schema {"enum": [null, 1]} + version: ~ + blackfire: + agent: + config: + # @schema {"type": ["string", "null"]} + server_id: ~ + # @schema {"type": ["string", "null"]} + server_token: ~ + client: + config: + # @schema {"type": ["string", "null"]} + client_id: ~ + # @schema {"type": ["string", "null"]} + client_token: ~ + nodejs: + # @option {"label": "Nodejs version"} + # @schema {"enum": [null, 14, 12, 10, 8, 6]} + version: ~ + # @schema {"items": {"type": "object"}} + packages: [] + mariadb: + # @option {"label": "MariaDB version"} + # @schema {"enum": [null, 10.5, 10.4, 10.3, 10.2, 10.1, "10.0"]} + version: ~ + postgresql: + # @option {"label": "PostgreSQL version"} + # @schema {"enum": [null, 13, 12, 11, 10, 9.6]} + version: ~ + redis: + # @option {"label": "Redis version"} + # @schema {"enum": [null, "*"]} + version: ~ + # @schema {"type": ["object", "array"]} + config: {} + influxdb: + # @option {"label": "InfluxDB version"} + # @schema {"enum": [null, "*"]} + version: ~ + # @schema {"type": ["object", "array"]} + config: {} + # @schema {"items": {"type": "string"}} + databases: [] + # @schema {"items": {"type": "object"}} + users: [] + # @schema {"items": {"type": "object"}} + privileges: [] + + # @schema {"type": "boolean"} + scalingo: false + + ssh: + client: + # @schema {"type": ["null", "string", "array"]} + config: ~ + docker: + # @schema {"items": {"type": "object"}} + containers: [] diff --git a/edrom.app/.manala.yaml.tmpl b/edrom.app/.manala.yaml.tmpl new file mode 100644 index 0000000..7982602 --- /dev/null +++ b/edrom.app/.manala.yaml.tmpl @@ -0,0 +1,119 @@ +{{- with .Vars.system -}} + +#################################################################### +# !!! REMINDER !!! # +# Don't forget to run `manala up` each time you update this file ! # +#################################################################### + +manala: + recipe: edrom.app + repository: https://github.com/RomulusED69/manala-recipes.git + +########## +# System # +########## + +system: + version: {{ .version | toYaml }} + hostname: {{ .hostname | toYaml }} + nginx: + configs: + - template: nginx/gzip.j2 + {{- if .php.version }} + - template: nginx/php_fpm_app.j2 + {{- end }} + # App + - file: app.conf + config: | + server { + listen 443 ssl; + listen 4430 ssl; + listen 4431 ssl; + + server_name ~.; + root /srv/app/public; + + ssl_certificate /srv/app/var/{{ .hostname | toYaml }}+1.pem; + ssl_certificate_key /srv/app/var/{{ .hostname | toYaml }}+1-key.pem; + + access_log /srv/log/nginx.access.log; + error_log /srv/log/nginx.error.log; + + include conf.d/gzip; + {{- if .php.version }} + location / { + try_files $uri /index.php$is_args$args; + } + location ~ ^/index\.php(/|$) { + include conf.d/php_fpm_app; + set $APP_ENV dev; + if ( $server_port = 4430 ) { + set $APP_ENV test; + } + if ( $server_port = 4431 ) { + set $APP_ENV prod; + } + fastcgi_param APP_ENV $APP_ENV; + internal; + } + {{- end }} + } + {{- if .php.version }} + php: + version: {{ .php.version | toYaml }} + extensions: + # Symfony + - intl + - curl + - mbstring + - xml + # App + {{- if (not (empty .mariadb.version)) }} + - mysql + {{- end }} + {{- if (not (empty .postgresql.version)) }} + - pgsql + {{- end }} + configs: + - template: php/opcache.ini.j2 + - template: php/app.ini.j2 + config: + date.timezone: UTC + {{- end }} + + {{- if .nodejs.version }} + nodejs: + version: {{ .nodejs.version | toYaml }} + {{- end }} + + {{- if .mariadb.version }} + mariadb: + version: {{ .mariadb.version | toYaml }} + {{- end }} + + {{- if .postgresql.version }} + postgresql: + version: {{ .postgresql.version | toYaml }} + {{- end }} + + {{- if .redis.version }} + redis: + version: {{ .redis.version | toYaml }} + {{- end }} + + {{- if .influxdb.version }} + influxdb: + version: {{ .influxdb.version | toYaml }} + {{- end }} + + files: + - path: /srv/app/var/log + src: /srv/log + state: link_directory + force: true + - path: /srv/app/var/cache + src: /srv/cache + state: link_directory + force: true + +{{- end }} diff --git a/edrom.app/.manala/.dockerignore b/edrom.app/.manala/.dockerignore new file mode 100644 index 0000000..ed1d155 --- /dev/null +++ b/edrom.app/.manala/.dockerignore @@ -0,0 +1,2 @@ +/.cache/ +/.vagrant/ diff --git a/edrom.app/.manala/.gitignore b/edrom.app/.manala/.gitignore new file mode 100644 index 0000000..ed1d155 --- /dev/null +++ b/edrom.app/.manala/.gitignore @@ -0,0 +1,2 @@ +/.cache/ +/.vagrant/ diff --git a/edrom.app/.manala/DOT_NOT_EDIT_MANUALLY b/edrom.app/.manala/DOT_NOT_EDIT_MANUALLY new file mode 100644 index 0000000..e69de29 diff --git a/edrom.app/.manala/Dockerfile.tmpl b/edrom.app/.manala/Dockerfile.tmpl new file mode 100644 index 0000000..a1727c2 --- /dev/null +++ b/edrom.app/.manala/Dockerfile.tmpl @@ -0,0 +1,108 @@ +{{- with .Vars.system -}} + +FROM debian:{{ .version }}-slim + +LABEL maintainer="EDRom" + +ARG UID=1000 +ARG GID=1000 + +######### +# Setup # +######### + +# The 'container' environment variable tells systemd that it's running inside a +# Docker container environment. +# It's also internally used for checking we're running inside a container too. +ENV \ + container="docker" + +RUN \ + # Disable irrelevants apt-key warnings + export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE="1" \ + # Disable all debian user interaction + && export DEBIAN_FRONTEND="noninteractive" \ + && apt-get update \ + && apt-get install --yes --no-install-recommends \ + bash-completion \ + gnupg dirmngr \ + ca-certificates \ + sudo \ + # Srv + && mkdir -p /srv \ + && chmod 777 /srv \ + # User + && addgroup --gid ${GID} docker \ + && adduser --disabled-password --gecos "" docker --uid ${UID} --ingroup docker \ + # Bash + && sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' \ + /home/docker/.bashrc \ + # Sudo + && echo "docker ALL=(ALL) NOPASSWD:ALL" \ + > /etc/sudoers.d/docker \ + # Ansible + {{- if eq (.version|int) 8 }} + && echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" \ + {{- else if eq (.version|int) 9 }} + && echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main" \ + {{- else if eq (.version|int) 10 }} + && echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu bionic main" \ + {{- end }} + > /etc/apt/sources.list.d/ppa_launchpad_net_ansible_ansible_ubuntu.list \ + && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 \ + && apt-get update \ + && apt-get install --yes --no-install-recommends \ + {{- if eq (.version|int) 8 }} + ansible python python-apt \ + {{- else }} + ansible python3 python3-apt \ + {{- end }} + # Cypress dependencies (https://docs.cypress.io/guides/continuous-integration/introduction#Dependencies) + && apt-get install --yes --no-install-recommends \ + libgtk2.0-0 \ + libgtk-3-0\ + libgbm-dev \ + libnotify-dev \ + libgconf-2-4 \ + libnss3 \ + libxss1 \ + libasound2 \ + libxtst6 \ + xauth \ + xvfb + +COPY docker/bin/entrypoint.sh /usr/local/bin/entrypoint.sh + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +########## +# System # +########## + +COPY ansible/collections /tmp/ansible/collections/ +COPY ansible/inventories/system.yaml /tmp/ansible/inventories/ +COPY ansible/templates /tmp/ansible/templates/ +COPY ansible/ansible.cfg ansible/system.yaml /tmp/ansible/ + +COPY --from=symfonycorp/cli /symfony /usr/local/bin/symfony + +RUN \ + cd /tmp/ansible \ + && ansible-galaxy collection install \ + --requirements-file collections/requirements.yaml \ + --force \ + && ansible-playbook system.yaml \ + --inventory-file inventories \ + --limit integration \ + && rm -Rf /tmp/ansible + +RUN \ + # NodeJs + mkdir -p /usr/etc \ + && echo "cache=\${XDG_CACHE_HOME}/npm" > /usr/etc/npmrc + +WORKDIR /srv/app + +USER docker + +{{- end }} diff --git a/edrom.app/.manala/Makefile.tmpl b/edrom.app/.manala/Makefile.tmpl new file mode 100644 index 0000000..9764108 --- /dev/null +++ b/edrom.app/.manala/Makefile.tmpl @@ -0,0 +1,120 @@ +# Relative root dir ("."|".."|"../.."|…) +_ROOT_DIR := $(patsubst ./%,%,$(patsubst %/.manala/Makefile,%,./$(filter %.manala/Makefile,$(MAKEFILE_LIST)))) +# Is current dir root ? (""|"1") +_ROOT := $(if $(filter .,$(_ROOT_DIR)),1) +# Relative current dir ("."|"foo"|"foo/bar"|…) +_DIR := $(patsubst ./%,%,.$(patsubst $(realpath $(CURDIR)/$(_ROOT_DIR))%,%,$(CURDIR))) + +include $(_ROOT_DIR)/.manala/make/text.mk +include $(_ROOT_DIR)/.manala/make/help.mk +include $(_ROOT_DIR)/.manala/make/os.mk +include $(_ROOT_DIR)/.manala/make/git.mk + +############### +# Environment # +############### + +include $(_ROOT_DIR)/.manala/vagrant/make.mk + +# Vagrant commands only available *OUTSIDE* vagrant environment +ifneq ($(container),vagrant) + +export VAGRANT_CWD = $(_ROOT_DIR)/.manala + +HELP += $(call help_section, Environment) + +# Setup commands only available *IN* root directory +ifdef _ROOT +HELP += $(call help,setup, Setup environment) +setup: + $(setup_before) + vagrant up --provision + $(setup) +endif + +HELP += $(call help,up, Start the environment) +up: + vagrant up + +HELP += $(call help,halt, Stop the environment) +halt: + vagrant halt + +HELP += $(call help,reload, Restart the environment) +reload: + vagrant reload + +HELP += $(call help,ssh, Connect to the environment via SSH) +ssh: export WORKDIR = /srv/app/$(_DIR) +ssh: + vagrant ssh + +HELP += $(call help,destroy, Stop and delete environment) +destroy: + vagrant destroy + +HELP += $(call help,provision, Provision the environment (TAGS|DIFF|VERBOSE)) +provision: + vagrant provision --provision-with system + +else + +HELP += $(call help_section, Environment) + +HELP += $(call help,provision, Provision the environment (TAGS|DIFF|VERBOSE)) +provision: + $(call log, Install ansible galaxy collection) + cd $(_ROOT_DIR)/.manala/ansible \ + && ansible-galaxy collection install \ + --requirements-file collections/requirements.yaml \ + --force + $(call log, Run ansible playbook) + cd $(_ROOT_DIR)/.manala/ansible \ + && ansible-playbook system.yaml \ + --inventory-file inventories \ + --limit development \ + --become \ + $(if $(TAGS),--tags $(TAGS)) \ + $(if $(VERBOSE),-vvv) \ + $(if $(DIFF),--check --diff) + +endif + +HELP += $(call help,provision.apt, Provision the environment - Apt (DIFF|VERBOSE)) +provision.apt: export TAGS = apt +provision.apt: provision + +HELP += $(call help,provision.files, Provision the environment - Files (DIFF|VERBOSE)) +provision.files: export TAGS = files +provision.files: provision + +HELP += $(call help,provision.nginx, Provision the environment - Nginx (DIFF|VERBOSE)) +provision.nginx: export TAGS = nginx +provision.nginx: provision + +HELP += $(call help,provision.php, Provision the environment - Php (DIFF|VERBOSE)) +provision.php: export TAGS = php +provision.php: provision + +########## +# Docker # +########## + +include $(_ROOT_DIR)/.manala/docker/make.mk + +# Docker commands only available *OUTSIDE* docker environment +ifneq ($(container),docker) + +HELP += $(call help_section, Docker) + +HELP += $(call help,docker,Run docker container) +docker: + $(call docker_run) + +endif + +########### +# Project # +########### + +HELP += $(call help_section, Project) diff --git a/edrom.app/.manala/Vagrantfile.tmpl b/edrom.app/.manala/Vagrantfile.tmpl new file mode 100644 index 0000000..fccd042 --- /dev/null +++ b/edrom.app/.manala/Vagrantfile.tmpl @@ -0,0 +1,111 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.require_version '>= 2.2.10' + +Vagrant.configure(2) do |config| + # Ssh + config.ssh.forward_agent = true + config.ssh.insert_key = false + config.ssh.extra_args = ['-q'] # Quiet mode + config.ssh.forward_env = ['WORKDIR'] + + # Force vagrant to use virtualbox provider + config.vm.provider "virtualbox" + + # Vm + config.vm.box = 'bento/debian-{{ .Vars.system.version }}' + config.vm.hostname = '{{ .Vars.system.hostname }}' + config.vm.network 'private_network', type: 'dhcp' + config.vm.define 'development' do |development| end + config.vm.synced_folder '..', '/srv/app', + type: 'nfs', + mount_options: ['vers=3', 'tcp', 'rw', 'nolock', 'actimeo=1'], + linux__nfs_options: ['rw', 'all_squash', 'async'] + + # Vm - Virtualbox + config.vm.provider 'virtualbox' # Force provider + config.vm.provider :virtualbox do |virtualbox| + virtualbox.name = '{{ regexReplaceAll "^(.*)\\.[^.]*$" .Vars.system.hostname "${1}" }}' + virtualbox.memory = ENV['BOX_MEMORY'] || {{ .Vars.system.memory }} + virtualbox.cpus = ENV['BOX_CPUS'] || {{ .Vars.system.cpus }} + virtualbox.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] + virtualbox.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] + end + + # Plugins - Landrush + config.vagrant.plugins = ['landrush'] + config.landrush.enabled = true + config.landrush.tld = config.vm.hostname + config.landrush.guest_redirect_dns = false + + # Vm - Provision - Dotfiles + for dotfile in ['.ssh/config', '.gitconfig', '.gitignore', '.gitignore_global', '.composer/auth.json', '.gnupg/private-keys-v1.d', '.gnupg/pubring.kbx', '.gnupg/pubring.kbx~', '.gnupg/trustdb.gpg'] + if File.exists?(File.join(Dir.home, dotfile)) then + config.vm.provision dotfile, type: 'file', run: 'always' do |file| + file.source = '~/' + dotfile + file.destination = dotfile + end + end + end + + # Vm - Provision - mkcert CA + Dir['/usr/local/share/ca-certificates/mkcert_*'].each do |path| + filename = path.split('/').last + + config.vm.provision 'file', run: 'always' do |file| + file.source = path + file.destination = "/tmp/#{filename}" # file provisionner can't write in /usr/local/... due to permissions, we have to use a trigger + end + + # copy to /usr/local/..., apply permissions and update CA certificates + config.trigger.after [:up, :provision] do |trigger| + trigger.name = "mkcert" + trigger.info = "Copying mkcert's CA file..." + trigger.run_remote = { + inline: 'if [ -f "%{source}" ]; then mv "%{source}" "%{path}" && chown root:staff "%{path}" && update-ca-certificates; fi' % { source: "/tmp/#{filename}", path: path } + } + end + end + + # Vm - Provision - Setup + config.vm.provision 'setup', type: 'shell' do |setup| + setup.keep_color = true + setup.privileged = true + setup.reset = true + setup.path = 'vagrant/bin/setup.sh' + end + + # Vm - Provision - System + config.vm.provision 'system', type: 'ansible_local' do |system| + system.provisioning_path = '/vagrant/ansible' + system.playbook = 'system.yaml' + system.inventory_path = 'inventories' + system.become = true + system.galaxy_role_file = 'collections/requirements.yaml' + system.galaxy_command = 'ansible-galaxy collection install --requirements-file=%{role_file} --force' + system.tags = ENV['TAGS'] + system.verbose = ENV['VERBOSE'] ? 'vvv' : false + system.raw_arguments = ENV['DIFF'] ? ['--check', '--diff'] : [] + end + + # Start nginx after mkcert has generated certificates + config.trigger.after :up do |trigger| + trigger.name = "nginx" + trigger.info = "Starting nginx..." + trigger.run_remote = {inline: "if systemctl cat nginx >/dev/null 2>&1; then sudo systemctl start nginx; fi"} + end + + config.trigger.after :up do |trigger| + trigger.ruby do |env,machine| + puts " \e[32m,\e[0m" + puts " \e[31m\\\e[0m \e[32m:\e[0m \e[31m/\e[0m" + puts "\e[32m`.\e[0m \e[33m__/ \\__\e[0m \e[32m.'\e[0m{{ if .Vars.system.mariadb.version }} PhpMyAdmin: http://{{ .Vars.system.hostname }}:1979{{ end }}" + puts "\e[31m_ _\e[0m\e[33m\\ /\e[0m\e[31m_ _\e[0m{{ if .Vars.system.postgresql.version }} PhpPgAdmin: http://{{ .Vars.system.hostname }}:1980{{ end }}" + puts " \e[33m/_ _\\\e[0m{{ if .Vars.system.redis.version }} PhpRedisAdmin: http://{{ .Vars.system.hostname }}:1981{{ end }}" + puts " \e[32m.'\e[0m \e[33m\\ /\e[0m \e[32m`.\e[0m" + puts " \e[31m/\e[0m \e[32m:\e[0m \e[31m\\\e[0m" + puts " \e[32m'\e[0m" + end + end +end diff --git a/edrom.app/.manala/ansible/ansible.cfg b/edrom.app/.manala/ansible/ansible.cfg new file mode 100644 index 0000000..be5e9e3 --- /dev/null +++ b/edrom.app/.manala/ansible/ansible.cfg @@ -0,0 +1,63 @@ +# Config file for ansible -- https://ansible.com/ +# =============================================== + +# For a full list of available options, run ansible-config list or see the +# documentation: https://docs.ansible.com/ansible/latest/reference_appendices/config.html. + +[defaults] + +force_color = True + +# This only affects the gathering done by a play's gather_facts directive, +# by default gathering retrieves all facts subsets +# all - gather all subsets +# network - gather min and network facts +# hardware - gather hardware facts (longest facts to retrieve) +# virtual - gather min and virtual facts +# facter - import facts from facter +# ohai - import facts from ohai +# You can combine them using comma (ex: network,virtual) +# You can negate them using ! (ex: !hardware,!facter,!ohai) +# A minimal set of facts is always gathered. + +gather_subset = all,!hardware + +# By default, ansible-playbook will display "Skipping [host]" if it determines a task +# should not be run on a host. Set this to "False" if you don't want to see these "Skipping" +# messages. NOTE: the task header will still be shown regardless of whether or not the +# task is skipped. + +display_skipped_hosts = False + +# If set to a persistent type (not 'memory', for example 'redis') fact values +# from previous runs in Ansible will be stored. This may be useful when +# wanting to use, for example, IP information from one group of servers +# without having to talk to them in the same playbook run to get their +# current IP information. + +fact_caching = jsonfile + +# This option tells Ansible where to cache facts. The value is plugin dependent. +# For the jsonfile plugin, it should be a path to a local directory. +# For the redis plugin, the value is a host:port:database triplet: fact_caching_connection = localhost:6379:0 + +fact_caching_connection = /tmp + +# retry files +# When a playbook fails a .retry file can be created that will be placed in ~/ +# You can enable this feature by setting retry_files_enabled to True +# and you can change the location of the files by setting retry_files_save_path + +retry_files_enabled = False + +[ssh_connection] + +# Enabling pipelining reduces the number of SSH operations required to +# execute a module on the remote server. This can result in a significant +# performance improvement when enabled, however when using "sudo:" you must +# first disable 'requiretty' in /etc/sudoers +# +# By default, this option is disabled to preserve compatibility with +# sudoers configurations that have requiretty (the default on many distros). + +pipelining = True diff --git a/edrom.app/.manala/ansible/collections/requirements.yaml b/edrom.app/.manala/ansible/collections/requirements.yaml new file mode 100644 index 0000000..3d61319 --- /dev/null +++ b/edrom.app/.manala/ansible/collections/requirements.yaml @@ -0,0 +1,4 @@ +--- + +collections: + - manala.roles diff --git a/edrom.app/.manala/ansible/inventories/system.yaml.tmpl b/edrom.app/.manala/ansible/inventories/system.yaml.tmpl new file mode 100644 index 0000000..e6114cc --- /dev/null +++ b/edrom.app/.manala/ansible/inventories/system.yaml.tmpl @@ -0,0 +1,232 @@ +{{- with .Vars.system -}} + +system: + + vars: + + # Ansible + ansible_connection: local + ansible_python_interpreter: /usr/bin/python{{ if gt (.version|int) 8 }}3{{ end }} + + # Accounts + system_accounts: false + # Alternatives + system_alternatives: false + # App + system_app: false + system_app_dir: /srv/app + system_app_log_dir: /srv/log + system_app_cache_dir: /srv/cache + system_app_sessions_dir: /srv/sessions + # Apt + system_apt: false + {{- dict "system_apt_repositories" .apt.repositories | toYaml | nindent 8 }} + {{- dict "system_apt_preferences" .apt.preferences | toYaml | nindent 8 }} + {{- dict "system_apt_holds" .apt.holds | toYaml | nindent 8 }} + # Docker + system_docker: false + {{- dict "system_docker_containers" .docker.containers | toYaml | nindent 8 }} + # Environment + system_environment: false + {{- dict "system_env" .env | toYaml | nindent 8 }} + # Files + system_files: false + {{- dict "system_files_attributes" .files | toYaml | nindent 8 }} + # Git + system_git: false + # Gomplate + system_gomplate: false + # InfluxDB + system_influxdb: false + {{- dict "system_influxdb_config" .influxdb.config | toYaml | nindent 8 }} + {{- dict "system_influxdb_databases" .influxdb.databases | toYaml | nindent 8 }} + {{- dict "system_influxdb_users" .influxdb.users | toYaml | nindent 8 }} + {{- dict "system_influxdb_privileges" .influxdb.privileges | toYaml | nindent 8 }} + # Locales + system_locales: false + system_locales_default: {{ .locales.default }} + {{- dict "system_locales_codes" .locales.codes | toYaml | nindent 8 }} + # MariaDB + system_mariadb: false + system_mariadb_version: {{ .mariadb.version | toYaml }} + system_mariadb_install_packages: + - mariadb-server + - mariadb-client + system_mariadb_configs_dir: {{ ge (.mariadb.version|float64) 10.5 | ternary + "/etc/mysql/mariadb.conf.d" + "/etc/mysql/conf.d" + }} + # PostgreSQL + system_postgresql: false + system_postgresql_version: {{ .postgresql.version | toYaml }} + # Nginx + system_nginx: false + {{- dict "system_nginx_configs" .nginx.configs | toYaml | nindent 8 }} + # Ngrok + system_ngrok: false + # NodeJS + system_nodejs: false + system_nodejs_version: {{ .nodejs.version | toYaml }} + system_nodejs_npm: {{ `"{{ system_nodejs }}"` }} + {{- dict "system_nodejs_packages" .nodejs.packages | toYaml | nindent 8 }} + system_nodejs_yarn: {{ `"{{ system_nodejs }}"` }} + # Oh my zsh + system_ohmyzsh: false + # Php + system_php: false + system_php_version: {{ .php.version }} + system_php_composer: {{ `"{{ system_php }}"` }} + system_php_composer_version: {{ .php.composer.version | toYaml }} + system_php_sapis: + - cli + - fpm + {{- dict "system_php_extensions" .php.extensions | toYaml | nindent 8 }} + {{- dict "system_php_configs" .php.configs | toYaml | nindent 8 }} + system_php_blackfire: false + system_php_blackfire_agent_config: + - server-id: {{ .php.blackfire.agent.config.server_id }} + - server-token: {{ .php.blackfire.agent.config.server_token }} + system_php_blackfire_client_config: + - client-id: {{ .php.blackfire.client.config.client_id }} + - client-token: {{ .php.blackfire.client.config.client_token }} + # Redis + system_redis: false + system_redis_version: {{ .redis.version | toYaml }} + {{- dict "system_redis_server_config" .redis.config | toYaml | nindent 8 }} + # Scalingo + system_scalingo: {{ .scalingo | ternary "true" "false" }} + # Ssh + system_ssh: false + system_ssh_server: false + {{- dict "system_ssh_client_config" .ssh.client.config | toYaml | nindent 8 }} + # Timezone + system_timezone: false + system_timezone_default: {{ .timezone | toYaml }} + # Vim + system_vim: false + # Zsh + system_zsh: false + + hosts: + + ############### + # Development # + ############### + + development: + + # Accounts + system_accounts: true + # Alternatives + system_alternatives: true + # App + system_app: true + system_app_group: vagrant + system_app_user: vagrant + # Apt + system_apt: true + system_apt_packages: + - xz-utils + - rsync + - wget + - curl + - make + - less + - ssl-cert + - htop + - pv # for real-time progress on streams (e.g mysql import) + {{- if .apt.packages }} + # App + {{- .apt.packages | toYaml | nindent 16 }} + {{- end }} + # Docker + system_docker: true + # Environment + system_environment: true + # Files + system_files: true + # Git + system_git: true + # Gomplate + system_gomplate: true + # InfluxDB + system_influxdb: {{ not (empty .influxdb.version) | ternary "true" "false" }} + # Locales + system_locales: true + # MariaDB + system_mariadb: {{ not (empty .mariadb.version) | ternary "true" "false" }} + # PostgreSQL + system_postgresql: {{ not (empty .postgresql.version) | ternary "true" "false" }} + # Nginx + system_nginx: {{ not (empty .nginx.configs) | ternary "true" "false" }} + # Ngrok + system_ngrok: true + # NodeJS + system_nodejs: {{ not (empty .nodejs.version) | ternary "true" "false" }} + # Oh my zsh + system_ohmyzsh: true + # Php + system_php: {{ not (empty .php.version) | ternary "true" "false" }} + system_php_blackfire: {{ not (empty .php.blackfire.agent.config.server_id) | ternary "true" "false" }} + # Redis + system_redis: {{ not (empty .redis.version) | ternary "true" "false" }} + # Ssh + system_ssh: true + system_ssh_server: true + system_ssh_client_config_template: {{ `"{{ + 'ssh/development/ssh_config.j2' + if (system_ssh_client_config is string) else + 'config/client/default.dev.j2' + }}"` }} + # Timezone + system_timezone: true + # Vim + system_vim: true + # Zsh + system_zsh: true + + ############### + # Integration # + ############### + + integration: + + # App + system_app: true + system_app_group: docker + system_app_user: docker + # Apt + system_apt: true + system_apt_packages: + - xz-utils + - rsync + - wget + - curl + - make + - less + - ssl-cert + - procps + - vim-tiny + {{- if .apt.packages }} + # App + {{- .apt.packages | toYaml | nindent 16 }} + {{- end }} + # Git + system_git: true + # Locales + system_locales: true + # NodeJS + system_nodejs: {{ not (empty .nodejs.version) | ternary "true" "false" }} + # Php + system_php: {{ not (empty .php.version) | ternary "true" "false" }} + system_php_sapis: + - cli + # Ssh + system_ssh: true + system_ssh_client_config_template: {{ `"{{ + 'ssh/integration/ssh_config.j2' + if (system_ssh_client_config is string) else + 'config/client/default.test.j2' + }}"` }} + +{{- end }} diff --git a/edrom.app/.manala/ansible/system.yaml b/edrom.app/.manala/ansible/system.yaml new file mode 100644 index 0000000..99b28fe --- /dev/null +++ b/edrom.app/.manala/ansible/system.yaml @@ -0,0 +1,558 @@ +--- + +- hosts: system + + collections: + - manala.roles + + vars: + + ############ + # Accounts # + ############ + + manala_accounts_groups: + - group: docker + system: true + state: "{{ 'present' if (system_docker) else 'absent' }}" + + manala_accounts_users: + - user: "{{ system_app_user }}" + group: "{{ system_app_group }}" + groups: "{{ + ['docker'] if (system_docker) else [] + }}" + state: "{{ 'present' if (system_app) else 'absent' }}" + + ################ + # Alternatives # + ################ + + manala_alternatives_selections: + - selection: editor + path: "{{ manala_vim_bin }}" + + ####### + # Apt # + ####### + + manala_apt: + update: true + + manala_apt_configs: + - file: archive + config: | + Acquire::Check-Valid-Until "false"; + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + + manala_apt_components: + - main + + manala_apt_sources_list_template: apt/sources.list.j2 + + manala_apt_repositories_exclusive: true + manala_apt_repositories: "{{ system_apt_repositories }}" + + manala_apt_preferences_exclusive: true + manala_apt_preferences: + # Jessie + - preference: git@backports + state: "{{ 'present' if (system_git and (ansible_distribution_release in ['jessie'])) else 'ignore' }}" + - preference: python-websocket@manala + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + - preference: python-ipaddress@manala + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + - preference: python-backports.ssl-match-hostname@manala + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + - preference: python-docker@manala + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + - preference: python-httplib2@manala + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + - preference: python-jinja2@manala + state: "{{ 'present' if (ansible_distribution_release in ['jessie']) else 'ignore' }}" + # Ansible + - ansible@ansible + # NodeJS + - preference: "nodejs@{{ + 'nodesource_' ~ system_nodejs_version|string|replace('.', '_') if (system_nodejs) else + 'default' + }}" + state: "{{ 'present' if (system_nodejs) else 'ignore' }}" + # Yarn + - preference: yarn@yarn + state: "{{ 'present' if (system_nodejs_yarn) else 'ignore' }}" + # Php + - preference: php@sury_php + state: "{{ 'present' if (system_php) else 'ignore' }}" + # Php - Blackfire (agent) + - preference: blackfire-agent@blackfire + state: "{{ 'present' if (system_php) else 'ignore' }}" + # Php - Blackfire (php) + - preference: blackfire-php@blackfire + state: "{{ 'present' if (system_php) else 'ignore' }}" + # Docker + - preference: docker@docker + state: "{{ 'present' if (system_docker) else 'ignore' }}" + # InfluxDB + - preference: influxdb@influxdata + state: "{{ 'present' if (system_influxdb) else 'ignore' }}" + # Nginx + - preference: nginx@nginx + state: "{{ 'present' if (system_nginx) else 'ignore' }}" + # MariaDB + - preference: "mariadb@{{ + 'mariadb_' ~ system_mariadb_version|string|replace('.', '_') if (system_mariadb) else + 'default' + }}" + state: "{{ 'present' if (system_mariadb) else 'ignore' }}" + # PostgreSQL + - preference: postgresql@postgresql + state: "{{ 'present' if (system_postgresql) else 'ignore' }}" + # Redis + - preference: redis@backports + state: "{{ 'present' if ( + (system_redis_version|string == '5.0') and (ansible_distribution_release in ['stretch']) + or (system_redis_version|string == '6.0') and (ansible_distribution_release in ['buster']) + ) else 'ignore' }}" + - "{{ system_apt_preferences }}" + + manala_apt_holds_exclusive: true + manala_apt_holds: + - "{{ system_apt_holds }}" + + manala_apt_packages: + - "{{ system_apt_packages }}" + + ############ + # Composer # + ############ + + manala_composer_version: "{{ system_php_composer_version }}" + + ########## + # Docker # + ########## + + manala_docker_containers: + - name: phpmyadmin + image: phpmyadmin/phpmyadmin + state: "{{ 'started' if (system_mariadb) else 'absent' }}" + restart_policy: unless-stopped + env: + PMA_USER: root + # Default docker host ip + PMA_HOST: 172.17.0.1 + UPLOAD_LIMIT: 64M + ports: + - 1979:80 + - name: phppgadmin + image: dockage/phppgadmin + state: "{{ 'started' if (system_postgresql) else 'absent' }}" + restart_policy: unless-stopped + env: + # Default docker host ip + PHP_PG_ADMIN_SERVER_HOST: 172.17.0.1 + UPLOAD_LIMIT: 64M + ports: + - 1980:80 + - name: phpredisadmin + image: erikdubbelboer/phpredisadmin + state: "{{ 'started' if (system_redis) else 'absent' }}" + restart_policy: unless-stopped + env: + # Default docker host ip + REDIS_1_HOST: 172.17.0.1 + ports: + - 1981:80 + - "{{ system_docker_containers }}" + + ############### + # Environment # + ############### + + manala_environment_files: + - zsh + + manala_environment_variables: "{{ {}|combine( + system_env, + system_php_composer|ternary( + {'COMPOSER_MEMORY_LIMIT': -1,}, + {} + ) + ) }}" + + ######### + # Files # + ######### + + manala_files_attributes_defaults: + - parents: true + force: true + - path: "^{{ system_app_log_dir }}" + user: "{{ system_app_user }}" + group: "{{ system_app_group }}" + - path: "^{{ system_app_cache_dir }}" + user: "{{ system_app_user }}" + group: "{{ system_app_group }}" + - path: "^{{ system_app_sessions_dir }}" + user: "{{ system_app_user }}" + group: "{{ system_app_group }}" + manala_files_attributes: + - path: "{{ system_app_log_dir }}" + state: directory + - path: "{{ system_app_cache_dir }}" + state: directory + - path: "{{ system_app_sessions_dir }}" + state: directory + - path: /usr/share/nginx/html/404.html + template: nginx/html/404.html.j2 + mode: "0644" + - "{{ system_files_attributes }}" + + ####### + # Git # + ####### + + manala_git_config_template: git/gitconfig.j2 + + ############ + # Gomplate # + ############ + + manala_gomplate_version: 3.7.0 + + ############ + # InfluxDB # + ############ + + manala_influxdb_config_template: "{{ + 'config/influxdata/influxdb.conf.j2' + if (system_influxdb_config is mapping) else + None + }}" + manala_influxdb_config: "{{ system_influxdb_config }}" + + manala_influxdb_databases: "{{ system_influxdb_databases }}" + + manala_influxdb_users: "{{ system_influxdb_users }}" + + manala_influxdb_privileges: "{{ system_influxdb_privileges }}" + + ########### + # Locales # + ########### + + manala_locales_codes_default: "{{ system_locales_default }}" + manala_locales_codes: "{{ system_locales_codes }}" + + ################### + # MySQL / MariaDB # + ################### + + manala_mysql_install_packages: "{{ + system_mariadb_install_packages + if (system_mariadb) else + system_mysql_install_packages + }}" + + manala_mysql_configs_dir: "{{ + system_mariadb_configs_dir + if (system_mariadb) else + system_mysql_configs_dir + }}" + manala_mysql_configs: + - template: mysql/zz-mysqld.cnf.j2 + + manala_mysql_users: + # Create a password-less/any-host root user... + - name: root + password: ~ + host: "%" + priv: "*.*:ALL,GRANT" + # ...then remove anonymous localhost user (MySQL 5.6) + - name: '' + host: localhost + state: absent + # ...then remove root localhost user (socket based authentication on MySQL 5.7+/MariaDB) + - name: root + host: localhost + state: absent + + ############## + # PostgreSQL # + ############## + + manala_postgresql_version: "{{ system_postgresql_version }}" + manala_postgresql_config_template: config/default.dev.j2 + manala_postgresql_config_hba_template: config/hba/default.dev.j2 + manala_postgresql_roles: + - role: app + password: ~ + attributes: ['SUPERUSER'] + + ######### + # Nginx # + ######### + + manala_nginx_config_template: nginx/nginx.conf.j2 + + manala_nginx_configs_exclusive: true + manala_nginx_configs: + - template: nginx/default.conf.j2 + - template: nginx/ssl_offloading.conf.j2 + - "{{ system_nginx_configs }}" + + ######### + # Ngrok # + ######### + + manala_ngrok_configs_exclusive: true + manala_ngrok_configs: + - template: ngrok/ngrok.yml.j2 + + ####### + # Npm # + ####### + + manala_npm_packages: "{{ system_nodejs_packages }}" + + ############# + # Oh my zsh # + ############# + + manala_ohmyzsh_custom_themes_exclusive: true + manala_ohmyzsh_custom_themes: + - template: ohmyzsh/theme.zsh-theme.j2 + + manala_ohmyzsh_users: + - user: "{{ system_app_user }}" + group: "{{ system_app_group }}" + template: ohmyzsh/.zshrc.j2 + state: "{{ 'present' if (system_app) else 'ignore' }}" + + ####### + # Php # + ####### + + manala_php_version: "{{ system_php_version }}" + + manala_php_sapis_exclusive: true + manala_php_sapis: "{{ system_php_sapis }}" + + manala_php_fpm_pools_exclusive: true + manala_php_fpm_pools: + - file: app.conf + template: fpm_pools/sury/pools.conf.j2 + config: + app: + user: "{{ system_app_user }}" + group: "{{ system_app_group }}" + listen: /run/php-fpm.app.sock + pm.max_children: 20 + env: "{{ system_env }}" + php_admin_value: + error_log: "{{ system_app_log_dir }}/php.error.log" + + manala_php_extensions_exclusive: true + manala_php_extensions: + - opcache + - readline + - extension: json + state: "{{ 'present' if (manala_php_version and manala_php_version|string is version('8.0', '<')) else 'ignore' }}" + - extension: xdebug + enabled: false + - "{{ system_php_extensions }}" + manala_php_extensions_pecl_versioned: "{{ (ansible_distribution_release not in ['jessie']) or system_php_dotdeb }}" + + manala_php_configs_exclusive: true + manala_php_configs: + - template: php/50-xdebug.ini.j2 + - "{{ system_php_configs }}" + + manala_php_blackfire: "{{ system_php_blackfire }}" + + manala_php_blackfire_agent_config: "{{ system_php_blackfire_agent_config }}" + manala_php_blackfire_client_config: "{{ system_php_blackfire_client_config }}" + + ######### + # Redis # + ######### + + manala_redis_server_config_template: "{{ + 'config/debian/redis.conf.j2' + if (system_redis_server_config is mapping) else + 'config/default.dev.j2' + }}" + manala_redis_server_config: "{{ + { + 'bind': '0.0.0.0', + }|combine(system_redis_server_config) + if (system_redis_server_config is mapping) else + system_redis_server_config + }}" + + ####### + # Ssh # + ####### + + manala_ssh_server: "{{ system_ssh_server }}" + manala_ssh_server_config_template: ssh/sshd_config.j2 + manala_ssh_server_config: + AcceptEnv: WORKDIR + + manala_ssh_client_config_template: "{{ system_ssh_client_config_template }}" + manala_ssh_client_config: "{{ system_ssh_client_config }}" + + manala_ssh_known_hosts: + - github.com + + ############ + # Timezone # + ############ + + manala_timezone_default: "{{ system_timezone_default }}" + + ####### + # Vim # + ####### + + manala_vim_config_template: vim/vimrc.local.j2 + + tasks: + + - import_role: + name: zsh + when: system_zsh + tags: [zsh] + + - import_role: + name: environment + when: system_environment + tags: [environment, env] + + - import_role: + name: apt + when: system_apt + tags: [apt] + + - import_role: + name: accounts + when: system_accounts + tags: [accounts] + + - import_role: + name: locales + when: system_locales + tags: [locales] + + - import_role: + name: ssh + when: system_ssh + tags: [ssh] + + - import_role: + name: timezone + when: system_timezone + tags: [timezone] + + - import_role: + name: vim + when: system_vim + tags: [vim] + + - import_role: + name: git + when: system_git + tags: [git] + + - import_role: + name: ohmyzsh + when: system_ohmyzsh + tags: [ohmyzsh] + + - import_role: + name: alternatives + when: system_alternatives + tags: [alternatives] + + - import_role: + name: files + when: system_files + tags: [files] + + - import_role: + name: nodejs + when: system_nodejs + tags: [nodejs, node] + + - import_role: + name: npm + when: system_nodejs_npm + tags: [npm, nodejs, node] + + - import_role: + name: yarn + when: system_nodejs_yarn + tags: [yarn, nodejs, node] + + - import_role: + name: php + when: system_php + tags: [php] + + - import_role: + name: composer + when: system_php_composer + tags: [composer] + + - import_role: + name: nginx + when: system_nginx + tags: [nginx] + + - import_role: + name: redis + when: system_redis + tags: [redis] + + - import_role: + name: mysql + when: system_mariadb + tags: [mariadb] + + - import_role: + name: postgresql + when: system_postgresql + tags: [postgresql] + + - import_role: + name: docker + when: system_docker + tags: [docker] + + - import_role: + name: influxdb + when: system_influxdb + tags: [influxdb] + + - import_role: + name: gomplate + when: system_gomplate + tags: [gomplate] + + - import_role: + name: ngrok + when: system_ngrok + tags: [ngrok] + + - name: "scalingo cli > download" + when: system_scalingo + tags: [scalingo] + get_url: + url: https://cli-dl.scalingo.io/install + dest: /tmp/scalingo-cli-install + + - name: "scalingo cli > install" + when: system_scalingo + tags: [scalingo] + command: bash /tmp/scalingo-cli-install --yes diff --git a/edrom.app/.manala/ansible/templates/apt/sources.list.j2 b/edrom.app/.manala/ansible/templates/apt/sources.list.j2 new file mode 100644 index 0000000..59bbe80 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/apt/sources.list.j2 @@ -0,0 +1,5 @@ +deb http://deb.debian.org/debian {{ ansible_distribution_release }} {{ manala_apt_components|flatten|join(' ') }} +{% if ansible_distribution_release not in ['jessie'] -%} +deb http://deb.debian.org/debian {{ ansible_distribution_release }}-updates {{ manala_apt_components|flatten|join(' ') }} +{% endif %} +deb http://security.debian.org/debian-security {{ ansible_distribution_release }}/updates {{ manala_apt_components|flatten|join(' ') }} diff --git a/edrom.app/.manala/ansible/templates/git/gitconfig.j2 b/edrom.app/.manala/ansible/templates/git/gitconfig.j2 new file mode 100644 index 0000000..1f7962e --- /dev/null +++ b/edrom.app/.manala/ansible/templates/git/gitconfig.j2 @@ -0,0 +1,23 @@ +{%- set config = { + 'core': {}, + 'oh-my-zsh': {}, +} | combine(manala_git_config|default({}, true)) -%} + +[core] + ; See: http://git.661346.n2.nabble.com/git-status-takes-30-seconds-on-Windows-7-Why-td7580816.html + {{ config.core | manala.roles.git_config_parameter('preloadindex', default=true) | indent(4) }} + ; See: https://news.ycombinator.com/item?id=11388479 + {{ config.core | manala.roles.git_config_parameter('untrackedCache', default=true) | indent(4) }} + {{- config.core | manala.roles.git_config_section(exclude=[ + 'preloadindex', + 'untrackedCache' + ]) }} + +[oh-my-zsh] + ; See: http://marc-abramowitz.com/archives/2012/04/10/fix-for-oh-my-zsh-git-svn-prompt-slowness/ + {{ config['oh-my-zsh'] | manala.roles.git_config_parameter('hide-status', default=1) | indent(4) }} + {{- config['oh-my-zsh'] | manala.roles.git_config_section(exclude=[ + 'hide-status' + ]) }} + +{{ config | manala.roles.git_config(exclude=['core', 'oh-my-zsh']) }} diff --git a/edrom.app/.manala/ansible/templates/mysql/zz-mysqld.cnf.j2.tmpl b/edrom.app/.manala/ansible/templates/mysql/zz-mysqld.cnf.j2.tmpl new file mode 100644 index 0000000..f759a49 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/mysql/zz-mysqld.cnf.j2.tmpl @@ -0,0 +1,2 @@ +[mysqld] +bind-address = 0.0.0.0 diff --git a/edrom.app/.manala/ansible/templates/nginx/cors.j2 b/edrom.app/.manala/ansible/templates/nginx/cors.j2 new file mode 100644 index 0000000..7e0a3ca --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/cors.j2 @@ -0,0 +1,8 @@ +add_header Access-Control-Allow-Origin "*" always; +add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" always; +add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept-Encoding, Cache-Control" always; +add_header Access-Control-Allow-Credentials "true" always; +add_header Access-Control-Expose-Headers "Content-Disposition"; +if ($request_method = OPTIONS) { + return 204; +} diff --git a/edrom.app/.manala/ansible/templates/nginx/default.conf.j2 b/edrom.app/.manala/ansible/templates/nginx/default.conf.j2 new file mode 100644 index 0000000..434627a --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/default.conf.j2 @@ -0,0 +1,8 @@ +server { + listen * default_server; + error_page 404 /404.html; + location /404.html { + root /usr/share/nginx/html; + internal; + } +} diff --git a/edrom.app/.manala/ansible/templates/nginx/gzip.j2 b/edrom.app/.manala/ansible/templates/nginx/gzip.j2 new file mode 100644 index 0000000..556b46e --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/gzip.j2 @@ -0,0 +1,7 @@ +gzip off; +gzip_disable msie6; +gzip_vary on; +gzip_proxied expired no-cache no-store private auth; +gzip_comp_level 6; +gzip_min_length 1000; +gzip_types text/css text/javascript text/xml text/plain application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml; diff --git a/edrom.app/.manala/ansible/templates/nginx/html/404.html.j2 b/edrom.app/.manala/ansible/templates/nginx/html/404.html.j2 new file mode 100644 index 0000000..e843334 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/html/404.html.j2 @@ -0,0 +1,36 @@ + + + + Error 404 + + + + + + + + + + + +
+

Error 404

+

Oops. We can't find the page you're looking for. Please try again.

+
+ + diff --git a/edrom.app/.manala/ansible/templates/nginx/nginx.conf.j2 b/edrom.app/.manala/ansible/templates/nginx/nginx.conf.j2 new file mode 100644 index 0000000..5df6b72 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/nginx.conf.j2 @@ -0,0 +1,67 @@ +{%- set config = { + 'events': {}, + 'http': {}, +} | combine(manala_nginx_config|default({}, true)) -%} + +user www-data; +{{ config | manala.roles.nginx_config_parameter('worker_processes', default=1) }} + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +{{ config | manala.roles.nginx_config_parameter('load_module', default=[]) }} + +events { + {{ config.events | manala.roles.nginx_config_parameter('worker_connections', default=1024) }} +} + +http { + server_tokens on; + default_type application/octet-stream; + + {{ config.http | manala.roles.nginx_config_parameter('log_format', default='main \'$remote_addr - $remote_user [$time_local] "$request" \' + \'$status $body_bytes_sent "$http_referer" \' + \'"$http_user_agent" "$http_x_forwarded_for"\'') }} + + access_log /var/log/nginx/access.log; + + # See: http://jeremyfelt.com/code/2013/01/08/clear-nginx-cache-in-vagrant/ + sendfile off; + #tcp_nopush on; + + {{ config.http | manala.roles.nginx_config_parameter('keepalive_timeout', default=65) }} + + # See: http://www.nicogiraud.com/blog/nginx-erreur-502-bad-gateway-sur-les-requetes-en-post.html + {{ config.http | manala.roles.nginx_config_parameter('fastcgi_buffer_size', default='128k') }} + {{ config.http | manala.roles.nginx_config_parameter('fastcgi_buffers', default='4 256k') }} + {{ config.http | manala.roles.nginx_config_parameter('fastcgi_busy_buffers_size', default='256k') }} + + # See: http://charles.lescampeurs.org/2008/11/14/fix-nginx-increase-server_names_hash_bucket_size + {{ config.http | manala.roles.nginx_config_parameter('server_names_hash_bucket_size', default=128) }} + + include mime.types; + include /etc/nginx/conf.d/*.conf; +{{ config.http | manala.roles.nginx_config_section(exclude=[ + 'server_tokens', + 'default_type', + 'log_format', + 'access_log', + 'sendfile', + 'tcp_nopush', + 'keepalive_timeout', + 'fastcgi_buffer_size', + 'fastcgi_buffers', + 'fastcgi_busy_buffers_size', + 'server_names_hash_bucket_size', + 'include', +]) | indent(4) }} +} +{{ config | manala.roles.nginx_config_section(exclude=[ + 'user', + 'worker_processes', + 'error_log', + 'pid', + 'load_module', + 'events', + 'http', +]) }} diff --git a/edrom.app/.manala/ansible/templates/nginx/no_index.j2 b/edrom.app/.manala/ansible/templates/nginx/no_index.j2 new file mode 100644 index 0000000..1d7ddd5 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/no_index.j2 @@ -0,0 +1 @@ +add_header X-Robots-Tag "noindex"; diff --git a/edrom.app/.manala/ansible/templates/nginx/php_fpm_app.j2 b/edrom.app/.manala/ansible/templates/nginx/php_fpm_app.j2 new file mode 100644 index 0000000..bc9975e --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/php_fpm_app.j2 @@ -0,0 +1,6 @@ +fastcgi_pass unix:/run/php-fpm.app.sock; +fastcgi_split_path_info ^(.+\.php)(/.*)$; +fastcgi_read_timeout 60s; +include fastcgi_params; +fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; +fastcgi_param DOCUMENT_ROOT $realpath_root; diff --git a/edrom.app/.manala/ansible/templates/nginx/ssl_offloading.conf.j2 b/edrom.app/.manala/ansible/templates/nginx/ssl_offloading.conf.j2 new file mode 100644 index 0000000..f6506e3 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/nginx/ssl_offloading.conf.j2 @@ -0,0 +1,19 @@ +server { + + listen 443 ssl; + server_name _; + + ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem; + ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key; + + + location / { + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_pass http://127.0.0.1; + client_max_body_size 0; + } +} diff --git a/edrom.app/.manala/ansible/templates/ngrok/ngrok.yml.j2 b/edrom.app/.manala/ansible/templates/ngrok/ngrok.yml.j2 new file mode 100644 index 0000000..6480f00 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ngrok/ngrok.yml.j2 @@ -0,0 +1 @@ +web_addr: 0.0.0.0:4040 diff --git a/edrom.app/.manala/ansible/templates/ohmyzsh/.zshrc.j2 b/edrom.app/.manala/ansible/templates/ohmyzsh/.zshrc.j2 new file mode 100644 index 0000000..fb8c741 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ohmyzsh/.zshrc.j2 @@ -0,0 +1,147 @@ +{%- set config = item.config|default({}) -%} + +# If you come from bash you might have to change your $PATH. +{{ config | manala.roles.zsh_config_parameter('export PATH', comment='# export PATH=$HOME/bin:/usr/local/bin:$PATH') }} + +# Path to your oh-my-zsh installation. +{{ config | manala.roles.zsh_config_parameter('export ZSH', default=manala_ohmyzsh_dir) }} + +# Ensure per-user cache +{{ config | manala.roles.zsh_config_parameter('ZSH_CACHE_DIR', default='$HOME/.oh-my-zsh/cache') }} + +if [[ ! -d $ZSH_CACHE_DIR ]]; then + mkdir -p $ZSH_CACHE_DIR +fi + +# Set name of the theme to load --- if set to "random", it will +# load a random theme each time oh-my-zsh is loaded, in which case, +# to know which specific one was loaded, run: echo $RANDOM_THEME +# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes +{{ config | manala.roles.zsh_config_parameter('ZSH_THEME', default='theme') }} + +# Set list of themes to pick from when loading at random +# Setting this variable when ZSH_THEME=random will cause zsh to load +# a theme from this variable instead of looking in $ZSH/themes/ +# If set to an empty array, this variable will have no effect. +{{ config | manala.roles.zsh_config_parameter('ZSH_THEME_RANDOM_CANDIDATES', comment='# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )') }} + +# Uncomment the following line to use case-sensitive completion. +{{ config | manala.roles.zsh_config_parameter('CASE_SENSITIVE', default=true, comment=true) }} + +# Uncomment the following line to use hyphen-insensitive completion. +# Case-sensitive completion must be off. _ and - will be interchangeable. +{{ config | manala.roles.zsh_config_parameter('HYPHEN_INSENSITIVE', default=true, comment=true) }} + +# Uncomment the following line to disable bi-weekly auto-update checks. +{{ config | manala.roles.zsh_config_parameter('DISABLE_AUTO_UPDATE', default=true, comment=true) }} + +# Uncomment the following line to automatically update without prompting. +{{ config | manala.roles.zsh_config_parameter('DISABLE_UPDATE_PROMPT', default=true, comment=true) }} + +# Uncomment the following line to change how often to auto-update (in days). +{{ config | manala.roles.zsh_config_parameter('export UPDATE_ZSH_DAYS', default=13, comment=true) }} + +# Uncomment the following line if pasting URLs and other text is messed up. +{{ config | manala.roles.zsh_config_parameter('DISABLE_MAGIC_FUNCTIONS', default=true, comment=true) }} + +# Uncomment the following line to disable colors in ls. +{{ config | manala.roles.zsh_config_parameter('DISABLE_LS_COLORS', default=true, comment=true) }} + +# Uncomment the following line to disable auto-setting terminal title. +{{ config | manala.roles.zsh_config_parameter('DISABLE_AUTO_TITLE', default=true, comment=true) }} + +# Uncomment the following line to enable command auto-correction. +{{ config | manala.roles.zsh_config_parameter('ENABLE_CORRECTION', default=true, comment=true) }} + +# Uncomment the following line to display red dots whilst waiting for completion. +# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) +# See https://github.com/ohmyzsh/ohmyzsh/issues/5765 +{{ config | manala.roles.zsh_config_parameter('COMPLETION_WAITING_DOTS', default=true, comment=true) }} + +# Uncomment the following line if you want to disable marking untracked files +# under VCS as dirty. This makes repository status check for large repositories +# much, much faster. +{{ config | manala.roles.zsh_config_parameter('DISABLE_UNTRACKED_FILES_DIRTY', default=true, comment=true) }} + +# Uncomment the following line if you want to change the command execution time +# stamp shown in the history command output. +# You can set one of the optional three formats: +# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" +# or set a custom format using the strftime function format specifications, +# see 'man strftime' for details. +{{ config | manala.roles.zsh_config_parameter('HIST_STAMPS', default='mm/dd/yyyy', comment=true) }} + +# Would you like to use another custom folder than $ZSH/custom? +{{ config | manala.roles.zsh_config_parameter('ZSH_CUSTOM', comment='# ZSH_CUSTOM=/path/to/new-custom-folder') }} + +# Which plugins would you like to load? +# Standard plugins can be found in $ZSH/plugins/ +# Custom plugins may be added to $ZSH_CUSTOM/plugins/ +# Example format: plugins=(rails git textmate ruby lighthouse) +# Add wisely, as too many plugins slow down shell startup. +{{ config | manala.roles.zsh_config_parameter('plugins', default=['git', 'debian', 'common-aliases', 'history', 'history-substring-search', 'symfony2', 'yarn']) }} + +source $ZSH/oh-my-zsh.sh + +# User configuration + +{{ config | manala.roles.zsh_config_parameter('export MANPATH', default='/usr/local/man:$MANPATH', comment=true) }} + +# You may need to manually set your language environment +{{ config | manala.roles.zsh_config_parameter('export LANG', comment='# export LANG=en_US.UTF-8') }} + +# Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='mvim' +# fi + +# Compilation flags +{{ config | manala.roles.zsh_config_parameter('export ARCHFLAGS', default='-arch x86_64', comment=true) }} + +# Set personal aliases, overriding those provided by oh-my-zsh libs, +# plugins, and themes. Aliases can be placed here, though oh-my-zsh +# users are encouraged to define aliases within the ZSH_CUSTOM folder. +# For a full list of active aliases, run `alias`. +{{ config | manala.roles.zsh_config_parameter('alias', comment='#\n# Example aliases\n# alias zshconfig="mate ~/.zshrc"\n# alias ohmyzsh="mate ~/.oh-my-zsh"') }} + +{{ config | manala.roles.zsh_config(exclude=[ + 'export PATH', + 'export ZSH', + 'ZSH_CACHE_DIR', + 'ZSH_THEME', + 'ZSH_THEME_RANDOM_CANDIDATES', + 'CASE_SENSITIVE', + 'HYPHEN_INSENSITIVE', + 'DISABLE_AUTO_UPDATE', + 'DISABLE_UPDATE_PROMPT', + 'UPDATE ZSH_DAYS', + 'DISABLE_MAGIC_FUNCTIONS', + 'DISABLE_LS_COLORS', + 'DISABLE_AUTO_TITLE', + 'ENABLE_CORRECTION', + 'COMPLETION_WAITING_DOTS', + 'DISABLE_UNTRACKED_FILES_DIRTY', + 'HIST_STAMPS', + 'ZSH_CUSTOM', + 'plugins', + 'export MANPATH', + 'export LANG', + 'export ARCHFLAGS', + 'alias' +]) }} + +echo + +{% include 'functions/ip.j2' %} + +{% include 'functions/php_xdebug.j2' %} + +{% include 'functions/nginx_timeout.j2' %} + +{% include 'functions/ngrok_http.j2' %} + +if [ -d ${WORKDIR:-{{ system_app_dir }}} ]; then + cd ${WORKDIR:-{{ system_app_dir }}} +fi diff --git a/edrom.app/.manala/ansible/templates/ohmyzsh/functions/ip.j2 b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/ip.j2 new file mode 100644 index 0000000..b2ce589 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/ip.j2 @@ -0,0 +1,7 @@ +manala_ip () { + wget http://ipecho.net/plain -O - -q ; echo +} + +echo -e " \e[36m‣\e[0m \e[36mSHOW PUBLIC IP\e[0m + manala_ip +" diff --git a/edrom.app/.manala/ansible/templates/ohmyzsh/functions/nginx_timeout.j2 b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/nginx_timeout.j2 new file mode 100644 index 0000000..905cd43 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/nginx_timeout.j2 @@ -0,0 +1,9 @@ +manala_nginx_timeout () { + if [[ $1 == off ]]; then sudo sed -ri 's/fastcgi_read_timeout (.*);$/fastcgi_read_timeout 999s;#origin\1/' /etc/nginx/conf.d/app_php_fpm + else sudo sed -ri 's/^fastcgi_read_timeout 999s;#origin(.*)/fastcgi_read_timeout \1;/' /etc/nginx/conf.d/app_php_fpm; fi + sudo /etc/init.d/nginx restart +} + +echo -e " \e[36m‣\e[0m \e[36mENABLE/DISABLE NGINX TIMEOUT\e[0m + manala_nginx_timeout [on|off] +" diff --git a/edrom.app/.manala/ansible/templates/ohmyzsh/functions/ngrok_http.j2 b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/ngrok_http.j2 new file mode 100644 index 0000000..e9c794c --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/ngrok_http.j2 @@ -0,0 +1,7 @@ +manala_ngrok_http () { + ngrok http -config=/etc/ngrok/config.yml 80 +} + +echo -e " \e[36m‣\e[0m \e[36mSTART NGROK HTTP\e[0m + manala_ngrok_http +" diff --git a/edrom.app/.manala/ansible/templates/ohmyzsh/functions/php_xdebug.j2 b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/php_xdebug.j2 new file mode 100644 index 0000000..d3d7431 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ohmyzsh/functions/php_xdebug.j2 @@ -0,0 +1,31 @@ +manala_php_xdebug () { + if [[ $1 == on ]]; then + if [ -f /usr/sbin/php5enmod ]; then + sudo php5enmod xdebug; + sudo service php5-fpm restart; + else + PHP_VERSION=`php -v | head -n 1 | cut -d ' ' -f 2 | cut -c 1-3` + sudo phpenmod -v ${PHP_VERSION} -s ALL xdebug; + sudo service php${PHP_VERSION}-fpm restart; + fi + elif [[ $1 == off ]]; then + if [ -f /usr/sbin/php5dismod ]; then + sudo php5dismod xdebug; + sudo service php5-fpm restart; + else + PHP_VERSION=`php -v | head -n 1 | cut -d ' ' -f 2 | cut -c 1-3` + sudo phpdismod -v ${PHP_VERSION} -s ALL xdebug; + sudo service php${PHP_VERSION}-fpm restart; + fi + else + if [[ $(/usr/bin/php -v 2>/dev/null) != *Xdebug* ]]; then + echo off + else + echo on + fi + fi +} + +echo -e " \e[36m‣\e[0m \e[36mENABLE/DISABLE PHP XDEBUG\e[0m + manala_php_xdebug [on|off] +" diff --git a/edrom.app/.manala/ansible/templates/ohmyzsh/theme.zsh-theme.j2 b/edrom.app/.manala/ansible/templates/ohmyzsh/theme.zsh-theme.j2 new file mode 100644 index 0000000..6d71111 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ohmyzsh/theme.zsh-theme.j2 @@ -0,0 +1,36 @@ +{%- set config = item.config|default({}, true) -%} + +# Inspired by Pygmalion: https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/pygmalion.zsh-theme + +prompt_setup_theme(){ + setopt localoptions extendedglob + + ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}" + ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " + ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}" + ZSH_THEME_GIT_PROMPT_CLEAN="" + + FULL_HOSTNAME=`hostname -f` + + base_prompt='%{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}$FULL_HOSTNAME%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}' + post_prompt='%{$fg[cyan]%}⇒%{$reset_color%} ' + + base_prompt_nocolor=${base_prompt//\%\{[^\}]##\}} + post_prompt_nocolor=${post_prompt//\%\{[^\}]##\}} + + autoload -U add-zsh-hook + add-zsh-hook precmd prompt_theme_precmd +} + +prompt_theme_precmd(){ + setopt localoptions extendedglob + + local gitinfo=$(git_prompt_info) + local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}} + local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")" + local prompt_length={% raw %}${#exp_nocolor}{% endraw %} + + PROMPT="%{$bg[green]%}%{$fg[black]%}❱Dev❰%{$reset_color%} ${base_prompt}${gitinfo}${post_prompt}" +} + +prompt_setup_theme diff --git a/edrom.app/.manala/ansible/templates/php/50-xdebug.ini.j2 b/edrom.app/.manala/ansible/templates/php/50-xdebug.ini.j2 new file mode 100644 index 0000000..76d21d3 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/php/50-xdebug.ini.j2 @@ -0,0 +1,19 @@ +{%- set config = item.config|default({}) -%} + +{{ config | manala.roles.php_config_parameter('xdebug.mode', default='develop,debug,coverage') }} +{{ config | manala.roles.php_config_parameter('xdebug.discover_client_host', default=1) }} +{{ config | manala.roles.php_config_parameter('xdebug.max_nesting_level', default=300) }} +{{ config | manala.roles.php_config_parameter('xdebug.var_display_max_children', default=128) }} +{{ config | manala.roles.php_config_parameter('xdebug.var_display_max_data', default=512) }} +{{ config | manala.roles.php_config_parameter('xdebug.var_display_max_depth', default=4) }} +{{ config | manala.roles.php_config_parameter('xdebug.cli_color', default=1) }} + +{{ config | manala.roles.php_config(exclude=[ + 'xdebug.mode', + 'xdebug.discover_client_host', + 'xdebug.max_nesting_level', + 'xdebug.var_display_max_children', + 'xdebug.var_display_max_data', + 'xdebug.var_display_max_depth', + 'xdebug.cli_color' +]) }} diff --git a/edrom.app/.manala/ansible/templates/php/app.ini.j2 b/edrom.app/.manala/ansible/templates/php/app.ini.j2 new file mode 100644 index 0000000..f8410da --- /dev/null +++ b/edrom.app/.manala/ansible/templates/php/app.ini.j2 @@ -0,0 +1,39 @@ +{%- set config = item.config|default({}) -%} + +{# Upstream - [PHP] - Error handling and logging #} +{{ config | manala.roles.php_config_parameter('error_reporting', default='E_ALL') }} +{{ config | manala.roles.php_config_parameter('display_errors', default=True) }} +{{ config | manala.roles.php_config_parameter('display_startup_errors', default=True) }} + +{# Upstream - [Assertion] #} +{{ config | manala.roles.php_config_parameter('zend.assertions', default=1) }} + +{# [PHP] - Miscellaneous #} +{{ config | manala.roles.php_config_parameter('expose_php', default=True) }} + +{# [PHP] - Resource Limits #} +{{ config | manala.roles.php_config_parameter('memory_limit', default='512M') }} + +{# [PHP] - Error handling and logging #} +{{ config | manala.roles.php_config_parameter('error_log', default='/var/log/php' ~ manala_php_version|string ~ '/error.log') }} + +{# Enable apc in cli as soon as apcu/apcu-bc extension is installed #} +{{ config | manala.roles.php_config_parameter('apc.enable_cli', default=True) }} + +{# [PHP] - Language Options - Dev #} +{# See: http://stackoverflow.com/questions/12905404/symfony2-slow-initialization-time #} +{{ config | manala.roles.php_config_parameter('realpath_cache_size', default='4096k') }} +{{ config | manala.roles.php_config_parameter('realpath_cache_ttl', default=7200) }} + +{{ config | manala.roles.php_config(exclude=[ + 'error_reporting', + 'display_errors', + 'display_startup_errors', + 'zend.assertions', + 'expose_php', + 'memory_limit', + 'error_log', + 'apc.enable_cli', + 'realpath_cache_size', + 'realpath_cache_ttl', +]) }} diff --git a/edrom.app/.manala/ansible/templates/php/opcache.ini.j2 b/edrom.app/.manala/ansible/templates/php/opcache.ini.j2 new file mode 100644 index 0000000..7369b36 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/php/opcache.ini.j2 @@ -0,0 +1,15 @@ +{%- set config = item.config|default({}) -%} + +{{ config | manala.roles.php_config_parameter('opcache.memory_consumption', default=128) }} +{{ config | manala.roles.php_config_parameter('opcache.interned_strings_buffer', default=8) }} +{{ config | manala.roles.php_config_parameter('opcache.max_accelerated_files', default=4000) }} +{{ config | manala.roles.php_config_parameter('opcache.revalidate_freq', default=2) }} +{{ config | manala.roles.php_config_parameter('opcache.fast_shutdown', default=1) }} + +{{ config | manala.roles.php_config(exclude=[ + 'opcache.memory_consumption', + 'opcache.interned_strings_buffer', + 'opcache.max_accelerated_files', + 'opcache.revalidate_freq', + 'opcache.fast_shutdown', +]) -}} diff --git a/edrom.app/.manala/ansible/templates/ssh/development/ssh_config.j2 b/edrom.app/.manala/ansible/templates/ssh/development/ssh_config.j2 new file mode 100644 index 0000000..0e65a47 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ssh/development/ssh_config.j2 @@ -0,0 +1,9 @@ +{%- set config = manala_ssh_client_config|default('', True) -%} + +Host * + HashKnownHosts yes + GSSAPIAuthentication yes + GSSAPIDelegateCredentials no + StrictHostKeyChecking no + +{{ config }} diff --git a/edrom.app/.manala/ansible/templates/ssh/integration/ssh_config.j2 b/edrom.app/.manala/ansible/templates/ssh/integration/ssh_config.j2 new file mode 100644 index 0000000..390191b --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ssh/integration/ssh_config.j2 @@ -0,0 +1,11 @@ +{%- set config = manala_ssh_client_config|default('', True) -%} + +Host * + HashKnownHosts no + GSSAPIAuthentication yes + GSSAPIDelegateCredentials no + StrictHostKeyChecking no + UserKnownHostsFile /dev/null + LogLevel ERROR + +{{ config }} diff --git a/edrom.app/.manala/ansible/templates/ssh/sshd_config.j2 b/edrom.app/.manala/ansible/templates/ssh/sshd_config.j2 new file mode 100644 index 0000000..7453580 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/ssh/sshd_config.j2 @@ -0,0 +1,25 @@ +{%- set config = manala_ssh_server_config|default({}, True) -%} + +{{ config | manala.roles.ssh_config_parameter('PermitRootLogin', default=True) }} +{{ config | manala.roles.ssh_config_parameter('PermitEmptyPasswords', default=True) }} +{{ config | manala.roles.ssh_config_parameter('ChallengeResponseAuthentication', default=False) }} +{{ config | manala.roles.ssh_config_parameter('PasswordAuthentication', default=True) }} +{{ config | manala.roles.ssh_config_parameter('X11Forwarding', default=True) }} +{{ config | manala.roles.ssh_config_parameter('PrintMotd', default=False) }} +{{ config | manala.roles.ssh_config_parameter('Subsystem', default='sftp /usr/lib/openssh/sftp-server') }} +{{ config | manala.roles.ssh_config_parameter('UsePAM', default=True) }} +{{ config | manala.roles.ssh_config_parameter('UseDNS', default=False) }} +{{ config | manala.roles.ssh_config_parameter('PrintLastLog', default=False) }} + +{{ config | manala.roles.ssh_config(exclude=[ + 'PermitRootLogin', + 'PermitEmptyPasswords', + 'ChallengeResponseAuthentication', + 'PasswordAuthentication', + 'X11Forwarding', + 'PrintMotd', + 'Subsystem', + 'UsePAM', + 'UseDNS', + 'PrintLastLog', +]) }} diff --git a/edrom.app/.manala/ansible/templates/vim/vimrc.local.j2 b/edrom.app/.manala/ansible/templates/vim/vimrc.local.j2 new file mode 100644 index 0000000..d29cb39 --- /dev/null +++ b/edrom.app/.manala/ansible/templates/vim/vimrc.local.j2 @@ -0,0 +1,17 @@ +{%- set config = manala_vim_config|default({}, true) -%} + +syntax on + +{{ config | manala.roles.vim_config_parameter('encoding', default='utf8') }} +{{ config | manala.roles.vim_config_parameter('expandtab', default=True) }} +{{ config | manala.roles.vim_config_parameter('smarttab', default=True) }} +{{ config | manala.roles.vim_config_parameter('shiftwidth', default=4) }} +{{ config | manala.roles.vim_config_parameter('tabstop', default=4) }} + +{{ config | manala.roles.vim_config(exclude=[ + 'encoding', + 'expandtab', + 'smarttab', + 'shiftwidth', + 'tabstop' +]) }} diff --git a/edrom.app/.manala/docker/bin/entrypoint.sh b/edrom.app/.manala/docker/bin/entrypoint.sh new file mode 100644 index 0000000..f384c07 --- /dev/null +++ b/edrom.app/.manala/docker/bin/entrypoint.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -e + +# Cache (Composer and Yarn both follows XDG Base Directory Specification. For +# the others, related environment variables must be expanded at runtime) +if [ -n "${XDG_CACHE_HOME}" ]; then + mkdir -p ${XDG_CACHE_HOME} + # Bash + export HISTFILE="${XDG_CACHE_HOME}/.bash_history" + # Ansible + export ANSIBLE_CACHE_PLUGIN_CONNECTION="${XDG_CACHE_HOME}/ansible" +fi + +# Ssh authorization socket +if [ -n "${SSH_AUTH_SOCK}" ]; then + sudo chmod 777 ${SSH_AUTH_SOCK} +fi + +# Ssh key +if [ -n "${SSH_KEY}" ]; then + eval `ssh-agent` 1>/dev/null + ssh-add ${SSH_KEY} 2>/dev/null +fi + +exec "$@" diff --git a/edrom.app/.manala/docker/make.mk.tmpl b/edrom.app/.manala/docker/make.mk.tmpl new file mode 100644 index 0000000..66d0dbb --- /dev/null +++ b/edrom.app/.manala/docker/make.mk.tmpl @@ -0,0 +1,46 @@ +########## +# Docker # +########## + +# Run docker container. +# +# Examples: +# +# Example #1: +# +# $(call docker_run) +# +# Example #2: +# +# $(call docker_run, whoami) + +define docker_run + $(call message, Building docker image...) \ + && ID=$$( \ + docker build \ + --quiet \ + $(_ROOT_DIR)/.manala \ + ) \ + && docker run \ + --rm \ + --tty \ + --interactive \ + --hostname {{ .Vars.system.hostname }} \ + --mount 'type=bind,consistency=delegated,source=$(realpath $(_ROOT_DIR)),target=/srv/app' \ + --workdir /srv/app/$(_DIR) \ + --env XDG_CACHE_HOME=/docker/.cache/docker \ + --mount 'type=bind,consistency=delegated,source=$(realpath $(_ROOT_DIR)/.manala),target=/docker' \ + $(if $(OS_DARWIN),\ + --env SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock \ + --volume /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock, \ + --env SSH_KEY=/home/docker/.ssh/id_rsa \ + --mount 'type=bind$(,)consistency=cached$(,)source=$(HOME)/.ssh/id_rsa$(,)target=/home/docker/.ssh/id_rsa' \ + ) \ + --mount 'type=bind,consistency=cached,source=$(HOME)/.gitconfig,target=/home/docker/.gitconfig' \ + $${ID} \ + $(if $(1),$(strip $(1)),bash) +endef + +ifneq ($(container),docker) +DOCKER_SHELL = $(call docker_run,$(SHELL)) +endif diff --git a/edrom.app/.manala/github/.env.tmpl b/edrom.app/.manala/github/.env.tmpl new file mode 100644 index 0000000..737c001 --- /dev/null +++ b/edrom.app/.manala/github/.env.tmpl @@ -0,0 +1,2 @@ +APP_ENV=test +APP_DOMAIN={{ .Vars.system.hostname }} diff --git a/edrom.app/.manala/github/docker-compose.yaml.tmpl b/edrom.app/.manala/github/docker-compose.yaml.tmpl new file mode 100644 index 0000000..17f7bb2 --- /dev/null +++ b/edrom.app/.manala/github/docker-compose.yaml.tmpl @@ -0,0 +1,61 @@ +version: '3.8' +services: + + manala_ci: + image: manala_ci + build: + context: ../ + args: + UID: ${MANALA_CI_UID} + GID: ${MANALA_CI_GID} + network_mode: 'host' + ipc: 'host' # Prevent Cypress/Chrome to crash, see https://github.com/cypress-io/cypress/issues/350 + command: 'tail -f /dev/null' + env_file: + - ./.env + environment: + XDG_CACHE_HOME: '/docker/.cache/docker' + SSH_AUTH_SOCK: ${SSH_AUTH_SOCK:-/ssh-agent} + volumes: + - type: bind + consistency: cached + source: ${GITHUB_WORKSPACE} + target: /srv/app + - type: bind + consistency: delegated + source: ${GITHUB_WORKSPACE}/.manala + target: /docker + - type: bind + source: ${SSH_AUTH_SOCK:-/home/runner/ssh-agent} + target: ${SSH_AUTH_SOCK:-/ssh-agent} + - type: tmpfs + target: /dev/shm + +{{- if .Vars.system.postgresql.version -}} +{{- $postgresql := .Vars.system.postgresql }} + + postgres: + image: 'postgres:{{ $postgresql.version }}' + network_mode: 'host' + environment: + POSTGRES_USER: 'app' + POSTGRES_PASSWORD: 'app' +{{- end }} + +{{- if .Vars.system.mariadb.version -}} +{{- $mariadb := .Vars.system.mariadb }} + + mariadb: + image: 'mariadb:{{ $mariadb.version }}' + network_mode: 'host' + command: '--port=3306' + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' +{{- end }} + +{{- if .Vars.system.redis.version }} + + redis: + image: 'redis' + network_mode: 'host' +{{- end }} diff --git a/edrom.app/.manala/make/git.mk b/edrom.app/.manala/make/git.mk new file mode 100644 index 0000000..69b036d --- /dev/null +++ b/edrom.app/.manala/make/git.mk @@ -0,0 +1,30 @@ +######## +# Diff # +######## + +# Returns the list of changed files for some given extensions and some given folders. +# +# @param $1 The file extensions of changed files +# @param $2 The relative folders to parse for changed files +# +# Examples: +# +# Example #1: list PHP and Javascript files changed in the src and test folders +# +# $(call git_diff, php js, src test) + +define git_diff +$(shell \ + for ext in $(if $(strip $(1)),$(strip $(1)),"") ; \ + do \ + for dir in $(if $(strip $(2)),$(strip $(2)),"") ; \ + do \ + git --no-pager diff --name-status "$$(git merge-base HEAD origin/master)" \ + | grep "$${ext}\$$" \ + | grep "\\s$${dir}" \ + | grep -v '^D' \ + | awk '{ print $$NF }' || true ; \ + done ; \ + done \ +) +endef diff --git a/edrom.app/.manala/make/help.mk b/edrom.app/.manala/make/help.mk new file mode 100644 index 0000000..e606dbf --- /dev/null +++ b/edrom.app/.manala/make/help.mk @@ -0,0 +1,42 @@ +######## +# Help # +######## + +HELP = \ + \nUsage: make [$(COLOR_INFO)target$(COLOR_RESET)] \ + $(call help_section, Help) \ + $(call help,help,This help) + +define help_section + \n\n$(COLOR_COMMENT)$(strip $(1)):$(COLOR_RESET) +endef + +define help + \n $(COLOR_INFO)$(1)$(COLOR_RESET) $(2) +endef + +help: + @printf "$(HELP)$(HELP_SUFFIX)" + awk ' \ + /^[-a-zA-Z0-9_.@%\/]+:/ { \ + hasMessage = match(lastLine, /^## (.*)/); \ + if (hasMessage) { \ + lines++; \ + helpCommands[lines] = substr($$1, 0, index($$1, ":")); \ + helpLenght = length(helpCommands[lines]); \ + if (helpLenght > helpLenghtMax) { \ + helpLenghtMax = helpLenght; \ + } \ + helpMessages[lines] = substr(lastLine, RSTART + 3, RLENGTH); \ + } \ + } \ + { lastLine = $$0 } \ + END { \ + for (i = 1; i <= lines; i++) { \ + printf "\n $(COLOR_INFO)%-" helpLenghtMax "s$(COLOR_RESET) %s", helpCommands[i], helpMessages[i]; \ + } \ + } \ + ' $(MAKEFILE_LIST) + @printf "\n\n" + +.PHONY: help diff --git a/edrom.app/.manala/make/os.mk b/edrom.app/.manala/make/os.mk new file mode 100644 index 0000000..d7ff1e9 --- /dev/null +++ b/edrom.app/.manala/make/os.mk @@ -0,0 +1,21 @@ +###### +# Os # +###### + +# Os detection helpers. +# +# Examples: +# +# Example #1: conditions on linux +# +# echo $(if $(OS_LINUX),Running on Linux,*NOT* running on Linux) + +ifeq ($(OS),Windows_NT) + OS = windows +else + OS = $(shell uname | tr '[:upper:]' '[:lower:]') +endif + +OS_LINUX = $(if $(findstring $(OS),linux),1,) +OS_DARWIN = $(if $(findstring $(OS),darwin),1,) +OS_WINDOWS = $(if $(findstring $(OS),windows),1,) diff --git a/edrom.app/.manala/make/text.mk b/edrom.app/.manala/make/text.mk new file mode 100644 index 0000000..fa1b0e0 --- /dev/null +++ b/edrom.app/.manala/make/text.mk @@ -0,0 +1,90 @@ +########## +# Colors # +########## + +COLOR_RESET := \033[0m +COLOR_ERROR := \033[31m +COLOR_INFO := \033[32m +COLOR_WARNING := \033[33m +COLOR_COMMENT := \033[36m + +###################### +# Special Characters # +###################### + +# Usage: +# $(call message, Foo$(,) bar) = Foo, bar + +, := , + +######## +# Time # +######## + +# Usage: +# $(call time) = 11:06:20 + +define time +`date -u +%T` +endef + +########### +# Message # +########### + +# Usage: +# $(call message, Foo bar) = Foo bar +# $(call message_success, Foo bar) = (っ◕‿◕)っ Foo bar +# $(call message_warning, Foo bar) = ¯\_(ツ)_/¯ Foo bar +# $(call message_error, Foo bar) = (╯°□°)╯︵ ┻━┻ Foo bar + +define message + printf "$(COLOR_INFO)$(strip $(1))$(COLOR_RESET)\n" +endef + +define message_success + printf "$(COLOR_INFO)(っ◕‿◕)っ $(strip $(1))$(COLOR_RESET)\n" +endef + +define message_warning + printf "$(COLOR_WARNING)¯\_(ツ)_/¯ $(strip $(1))$(COLOR_RESET)\n" +endef + +define message_error + printf "$(COLOR_ERROR)(╯°□°)╯︵ ┻━┻ $(strip $(1))$(COLOR_RESET)\n" +endef + +########### +# Confirm # +########### + +# Usage: +# $(call confirm, Foo bar) = ༼ つ ◕_◕ ༽つ Foo bar (y/N): + +define confirm + $(if $(CONFIRM),, \ + printf "$(COLOR_INFO) ༼ つ ◕_◕ ༽つ $(COLOR_WARNING)$(strip $(1)) $(COLOR_RESET)$(COLOR_WARNING)(y/N)$(COLOR_RESET): "; \ + read CONFIRM ; if [ "$$CONFIRM" != "y" ]; then printf "\n"; exit 1; fi; \ + ) +endef + +####### +# Log # +####### + +# Usage: +# $(call log, Foo bar) = [11:06:20] [target] Foo bar +# $(call log_warning, Foo bar) = [11:06:20] [target] ¯\_(ツ)_/¯ Foo bar +# $(call log_error, Foo bar) = [11:06:20] [target] (╯°□°)╯︵ ┻━┻ Foo bar + +define log + printf "[$(COLOR_COMMENT)$(call time)$(COLOR_RESET)] [$(COLOR_COMMENT)$(@)$(COLOR_RESET)] " ; $(call message, $(1)) +endef + +define log_warning + printf "[$(COLOR_COMMENT)$(call time)$(COLOR_RESET)] [$(COLOR_COMMENT)$(@)$(COLOR_RESET)] " ; $(call message_warning, $(1)) +endef + +define log_error + printf "[$(COLOR_COMMENT)$(call time)$(COLOR_RESET)] [$(COLOR_COMMENT)$(@)$(COLOR_RESET)] " ; $(call message_error, $(1)) +endef diff --git a/edrom.app/.manala/vagrant/bin/setup.sh.tmpl b/edrom.app/.manala/vagrant/bin/setup.sh.tmpl new file mode 100644 index 0000000..00c7ff6 --- /dev/null +++ b/edrom.app/.manala/vagrant/bin/setup.sh.tmpl @@ -0,0 +1,142 @@ +{{- with .Vars.system -}} + +#!/usr/bin/env sh + +set -e + +export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 +export DEBIAN_FRONTEND=noninteractive + +############### +# Environment # +############### + +printf "[\033[36mEnvironment\033[0m] \033[32mSetup...\033[0m\n" + +# Notes: +# - set `container` environment variable for environment checks +cat < /etc/environment +container="vagrant" +EOF + +######## +# Root # +######## + +printf "[\033[36mRoot\033[0m] \033[32mPassword...\033[0m\n" + +echo "root:root" | chpasswd + +########### +# Cleanup # +########### + +PACKAGES="" + +# `exim4` package comes pre-installed on jessie bento debian vagrant images +if dpkg -s exim4 > /dev/null 2>&1 ; then + PACKAGES="$PACKAGES exim4 exim4-base exim4-config exim4-daemon-light" +fi + +# `cryptsetup` package comes pre-installed in bento debian vagrant images +if dpkg -s cryptsetup > /dev/null 2>&1 ; then + PACKAGES="$PACKAGES cryptsetup" +fi + +if [ ! -z "$PACKAGES" ] ; then + printf "[\033[36mCleanup\033[0m] \033[32mPackages...\033[0m\n" + + apt-get --quiet --yes -o=Dpkg::Use-Pty=0 --purge autoremove \ + $PACKAGES +fi + +printf "[\033[36mCleanup\033[0m] \033[32mMails...\033[0m\n" + +rm -Rf /var/mail/* + +printf "[\033[36mCleanup\033[0m] \033[32mMotd...\033[0m\n" + +rm -Rf /etc/motd + +{{- if eq (.version|int) 8 }} + +########## +# Manala # +########## + +printf "[\033[36mManala\033[0m] \033[32mSetup...\033[0m\n" + +cat < /etc/apt/sources.list.d/debian_manala_io.list +deb [arch=amd64] http://debian.manala.io jessie main +EOF + +apt-key adv --quiet --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 1394DEA3 + +{{- end }} + +########## +# Update # +########## + +printf "[\033[36mApt\033[0m] \033[32mUpdate...\033[0m\n" + +apt-get --quiet update + +########## +# System # +########## + +printf "[\033[36mSystem\033[0m] \033[32mInstall...\033[0m\n" + +apt-get --quiet --yes -o=Dpkg::Use-Pty=0 --no-install-recommends --verbose-versions install \ +{{- if eq (.version|int) 9 }} + dirmngr \ +{{- end }} + make \ + linux-image-amd64 linux-headers-amd64 + +######## +# Grub # +######## + +printf "[\033[36mGrub\033[0m] \033[32mSet device...\033[0m\n" + +# See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=982182 +echo 'grub-pc grub-pc/install_devices multiselect /dev/sda' | debconf-set-selections + +########### +# Upgrade # +########### + +printf "[\033[36mApt\033[0m] \033[32mUpgrade...\033[0m\n" + +apt-get --quiet --yes -o=Dpkg::Use-Pty=0 --purge --auto-remove dist-upgrade + +########### +# Ansible # +########### + +printf "[\033[36mAnsible\033[0m] \033[32mSetup...\033[0m\n" + +cat < /etc/apt/sources.list.d/ppa_launchpad_net_ansible_ansible_ubuntu.list +{{- if eq (.version|int) 8 }} +deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main +{{- else if eq (.version|int) 9 }} +deb http://ppa.launchpad.net/ansible/ansible/ubuntu xenial main +{{- else if eq (.version|int) 10 }} +deb http://ppa.launchpad.net/ansible/ansible/ubuntu bionic main +{{- end }} +EOF + +apt-key adv --quiet --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 93C4A3FD7BB9C367 +apt-get --quiet update +apt-get --quiet --yes -o=Dpkg::Use-Pty=0 --no-install-recommends --verbose-versions install \ +{{- if eq (.version|int) 8 }} + python ansible +{{- else }} + python3 ansible +{{- end }} + +install --directory /root/.ansible/tmp --verbose + +{{- end }} diff --git a/edrom.app/.manala/vagrant/make.mk b/edrom.app/.manala/vagrant/make.mk new file mode 100644 index 0000000..e1e6674 --- /dev/null +++ b/edrom.app/.manala/vagrant/make.mk @@ -0,0 +1,13 @@ +########### +# Vagrant # +########### + +define VAGRANT_SSH + vagrant ssh -- cd /srv/app/$(_DIR) \&\& +endef + +ifneq ($(container),vagrant) +VAGRANT_MAKE = $(VAGRANT_SSH) make +else +VAGRANT_MAKE = $(MAKE) +endif diff --git a/edrom.app/Makefile.tmpl b/edrom.app/Makefile.tmpl new file mode 100644 index 0000000..c4f75f3 --- /dev/null +++ b/edrom.app/Makefile.tmpl @@ -0,0 +1,64 @@ +{{- with .Vars.system -}} +.SILENT: + +-include .manala/Makefile + +define setup_before + (cd var; mkcert '{{ .hostname | toYaml }}' '*.{{ .hostname | toYaml }}') +endef + +define setup + $(VAGRANT_MAKE) install-app +endef + +########### +# Install # +########### + +## Install application +install-app: composer-install init-db +install-app: + bin/console cache:clear + yarn install + yarn dev + +install-app@test: export APP_ENV=test +install-app@test: install-app + +install-app@integration: export APP_ENV=test +install-app@integration: + # Composer + composer install --ansi --verbose --no-interaction --no-progress --prefer-dist --optimize-autoloader + # Yarn + yarn install --color=always --no-progress --frozen-lockfile + yarn dev + + $(MAKE) init-db@integration + +################ +# Common tasks # +################ + +composer-install: + composer install --verbose --no-interaction + +init-db: + bin/console doctrine:database:drop --force --if-exists --no-interaction + bin/console doctrine:database:create --no-interaction + bin/console doctrine:schema:update --force --no-interaction # to remove when we will use migrations + # bin/console doctrine:migrations:migrate --no-interaction + bin/console hautelook:fixtures:load --no-interaction + +init-db@test: export APP_ENV=test +init-db@test: init-db + +init-db@integration: + bin/console doctrine:database:create --no-interaction + bin/console doctrine:schema:update --force --no-interaction # to remove when we will use migrations + # bin/console doctrine:migrations:migrate --no-interaction + bin/console hautelook:fixtures:load --no-interaction + +reload-db@test: + APP_ENV=test bin/console hautelook:fixtures:load --purge-with-truncate --no-interaction + +{{- end }} diff --git a/edrom.app/README.md b/edrom.app/README.md new file mode 100644 index 0000000..d6e38aa --- /dev/null +++ b/edrom.app/README.md @@ -0,0 +1,259 @@ +# EDRom - App + +A [Manala recipe](https://github.com/manala/manala-recipes) greatly inspired by [elao.app recipe](https://github.com/manala/manala-recipes/tree/master/elao.app) ❤️ + +--- + +* [Requirements](#requirements) +* [Overview](#overview) +* [Init](#init) +* [Quick start](#quick-start) +* [System](#system) +* [Integration](#integration) + * [Github Actions](#github-actions) + * [Common Integration Tasks](#common-integration-tasks) +* [Makefile](#makefile) +* [Tips, Tricks, and Tweaks](#tips-tricks-and-tweaks) + +## Requirements + +* [manala](https://manala.github.io/manala/) +* [VirtualBox 6.1.12+](https://www.virtualbox.org/wiki/Downloads) +* [Vagrant 2.2.10+](https://www.vagrantup.com/downloads.html) +* [Vagrant Landrush 1.3.2+](https://github.com/vagrant-landrush/landrush) +* [Docker Desktop 2.2.0+](https://docs.docker.com/engine/install/) + +## Overview + +This recipe contains some helpful scripts in the context of a php/nodejs app, such as Makefile tasks in order to release and deploy your app. + +## Init + +``` +$ cd [workspace] +$ manala init -i edrom.app --repository https://github.com/RomulusED69/manala-recipes.git [project] +``` + +## Quick start + +In a shell terminal, change directory to your app, and run the following commands: + +```shell +cd /path/to/my/app +manala init --repository https://github.com/RomulusED69/manala-recipes.git +Select the "edrom.app" recipe +``` + +Edit the `Makefile` at the root directory of your project and add the following lines at the beginning of the file: + +```makefile +.SILENT: + +-include .manala/Makefile +``` + +Then update the `.manala.yaml` file (see [the releases example](#releases) below) and then run the `manala up` command: + +```shell +manala up +``` + +!!! Warning +Don't forget to run the `manala up` command each time you update the +`.manala.yaml` file to actually apply your changes !!! + +From now on, if you execute the `make help` command in your console, you should obtain the following output: + +```shell +Usage: make [target] + +Help: + help This help + +Docker: + docker Run docker container + +App: +``` + +## VM interaction + +In your app directory. + +Initialise your app: +```bash +make setup +``` + +Start VM: +```bash +make up +``` + +Stop VM: +```bash +make halt +``` + +VM shell: +```bash +make ssh +``` + + +## System + +Here is an example of a system configuration in `.manala.yaml`: + +```yaml +########## +# System # +########## + +system: + version: 10 + hostname: localhost.your-app.fr + #memory: 4096 # Optional + #cpus: 2 # Optional + nginx: + configs: + - template: nginx/gzip.j2 + - template: nginx/php_fpm_app.j2 + # App + - file: app.conf + config: | + server { + listen 443 ssl; + listen 4430 ssl; + listen 4431 ssl; + + server_name ~.; + root /srv/app/public; + + ssl_certificate /srv/app/var/localhost.your-app.fr+1.pem; + ssl_certificate_key /srv/app/var/localhost.your-app.fr+1-key.pem; + + access_log /srv/log/nginx.access.log; + error_log /srv/log/nginx.error.log; + + include conf.d/gzip; + location / { + try_files $uri /index.php$is_args$args; + } + location ~ ^/index\.php(/|$) { + include conf.d/php_fpm_app; + set $APP_ENV dev; + if ( $server_port = 4430 ) { + set $APP_ENV test; + } + if ( $server_port = 4431 ) { + set $APP_ENV prod; + } + fastcgi_param APP_ENV $APP_ENV; + internal; + } + } + php: + version: 7.4 + extensions: + # Symfony + - intl + - curl + - mbstring + - xml + # App + - pgsql + configs: + - template: php/opcache.ini.j2 + - template: php/app.ini.j2 + config: + date.timezone: UTC + #blackfire: + # agent: + # config: + # server_id: + # server_token: + # client: + # config: + # client_id: + # client_token: + nodejs: + version: 12 + postgresql: + version: 12 + redis: + version: '*' + + files: + - path: /srv/app/var/log + src: /srv/log + state: link_directory + force: true + - path: /srv/app/var/cache + src: /srv/cache + state: link_directory + force: true +``` + +## Integration + +### Github Actions + +The recipes generates a `Dockerfile` and a `docker-compose.yaml` file that can +be used to provide a fully-fledged environnement according to your project needs. + +The [Elao/manala-ci-action](https://github.com/Elao/manala-ci-action) rely on +this to allow you running any CLI command in this environnement, +using Github Action workflows. + +### Common integration tasks + +Add in your `Makefile`: + +```makefile +########### +# Install # +########### + +# ... + +install-app@integration: export APP_ENV=test +install-app@integration: + # Composer + composer install --ansi --verbose --no-interaction --no-progress --prefer-dist --optimize-autoloader + # Yarn + yarn install --color=always --no-progress --frozen-lockfile + yarn dev + + $(MAKE) init-db@integration + +init-db@integration: + bin/console doctrine:database:create --no-interaction + bin/console doctrine:schema:update --force --no-interaction # to remove when migrations will be used + # bin/console doctrine:migrations:migrate --no-interaction + bin/console hautelook:fixtures:load --no-interaction +``` + +## Makefile + +Makefile targets that are supposed to be runned via docker must be prefixed. + +```makefile +foo: SHELL := $(or $(DOCKER_SHELL),$(SHELL)) +foo: + # Do something really foo... +``` + +## Tips, Tricks, and Tweaks + +* [Vagrant root privilege requirement](https://www.vagrantup.com/docs/synced-folders/nfs.html#root-privilege-requirement) +* Debug ansible provisioning: + + ```shell + ansible-galaxy collection install manala.roles --collections-path /vagrant/ansible/collections + ``` +* Update vagrant boxes + ``` + vagrant box outdated --global + vagrant box update --box bento/debian-10 + ``` diff --git a/edrom.app/vagrant-wrapper.sh b/edrom.app/vagrant-wrapper.sh new file mode 100644 index 0000000..113dfa3 --- /dev/null +++ b/edrom.app/vagrant-wrapper.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +vagrant_wrapper() { + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # path where this file lives + + local user_command=$@ + + # we assume that we are outside the VM if command `vagrant` is available + if [[ -x "$(command -v vagrant)" ]]; then + (cd ".manala" && vagrant ssh -- "cd /srv/app && ${user_command}") + else + (cd "${DIR}" && eval ${user_command}) + fi +} + +vagrant_wrapper $@