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 @@ + + +
+Oops. We can't find the page you're looking for. Please try again.
+