From dc3c80a2a9ae8d64f8394d6303aeeb669672c685 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Thu, 17 Apr 2025 22:29:47 +0200 Subject: [PATCH] [TASK] Update documentation --- .editorconfig | 15 ++- README.md | 271 ++++++++++++++++++++++++++++++++++++++------------ alias.sh | 1 + 3 files changed, 222 insertions(+), 65 deletions(-) diff --git a/.editorconfig b/.editorconfig index f4f67f6..0acfb72 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ insert_final_newline = true trim_trailing_whitespace = true # TS/JS-Files -[*.{ts,js,es6}] +[*.{ts,js}] indent_size = 2 # JSON-Files @@ -21,14 +21,23 @@ indent_size = 2 indent_style = tab # ReST-Files -[*.rst] -indent_size = 3 +[*.{rst,rst.txt}] +indent_size = 4 +max_line_length = 80 + +# Markdown-Files +[*.md] max_line_length = 80 # YAML-Files [*.{yaml,yml}] indent_size = 2 +# NEON-Files +[*.neon] +indent_size = 2 +indent_style = tab + # package.json [package.json] indent_size = 2 diff --git a/README.md b/README.md index 49a5ff8..878ca35 100644 --- a/README.md +++ b/README.md @@ -1,85 +1,232 @@ ## To install add Build/composer.json to the project ```json { - "name": "cp/build", - "description": "Project deployment with support for deployphp", - "repositories": [ - { - "type": "git", - "url": "https://gitlab.cp-compartner.de/cpcompartner/build-config.git" - } - ], - "require": { - "cp/build-config": "^1.7.3" - }, - "scripts": { - "staging": "dep -vv --file=vendor/cp/build-config/deploy.php deploy staging --branch", - "production": "dep --file=vendor/cp/build-config/deploy.php deploy production --tag", - - "phpcs-fixer": "php-cs-fixer fix --config=vendor/cp/build-config/php_cs.php", - "phpstan": "phpstan analyse --configuration=vendor/cp/build-config/phpstan.neon", - "rector": "rector process --config=vendor/cp/build-config/rector.php", - "php72-lint": "find ../packages ../private/typo3conf -name '*.php' -exec php7.2 -l {} 1> /dev/null \\;", - "php74-lint": "find ../packages ../private/typo3conf -name '*.php' -exec php7.4 -l {} 1> /dev/null \\;" - } + "name": "ew/build", + "description": "Project deployment with utilization of deployphp", + "repositories": { + "gitea": { + "type": "git", + "url": "https://gitea.fischer.im/evoWeb/ew_deployer_config.git" + } + }, + "require": { + "evoweb/deployer-config": "dev-develop" + } } ``` -## Usage per composer +## Add to Build/alias.sh with +```shell +#!/bin/bash -Install it with: -```bash -./composer update +function composer() { + mkdir -p "${HOME}/.config/composer" + mkdir -p "${HOME}/.cache/composer" + docker run -t \ + --user $(id -u):33 \ + --env COMPOSER_CACHE_DIR=/cache \ + --env SSH_AUTH_SOCK=/ssh-agent \ + --env CI_HOST \ + --env CI_PROJECT_DIR \ + --env ENVIRONMENT_NAME \ + --env INSTANCE_ID \ + --env ADDITIONAL_CONFIG_FILE \ + --env TYPO3_CONTEXT \ + --env STAGE \ + --network db \ + --volume "$(readlink -f ${SSH_AUTH_SOCK})":/ssh-agent \ + --volume /etc/passwd:/etc/passwd:ro \ + --volume "${HOME}":"${HOME}" \ + --volume "${HOME}/.ssh/known_hosts":/home/.ssh-agent/known_hosts \ + --volume "${HOME}/.config/composer":/tmp \ + --volume "${HOME}/.cache/composer":/cache \ + --volume "${CI_PROJECT_DIR}":"${CI_PROJECT_DIR}" \ + --volume "${PWD%}":/app \ + evoweb/php:composer $@ +} +alias composer=composer ``` +## Add .env to project root +```apacheconf +ALIAS_SCRIPT=Build/alias.sh +DEPLOY_CONFIG=Build/vendor/evoweb/deployer-config/deploy.php + +DOMAIN=www.evoweb.de +CI_HOST=10.10.0.25 +INSTANCE_ID=website-evoweb +HOST=sebastian@10.10.0.25 +PORT=22 + +SHARED=/mnt/Docker/website-evoweb/shared +``` + +## Add Makefile to project root +```makefile +MAKEFLAGS += --warn-undefined-variables +SHELL := /bin/bash +.EXPORT_ALL_VARIABLES: +.ONESHELL: +.SHELLFLAGS := -eu -o pipefail -c +.SILENT: + +# use the rest as arguments for "run" +_ARGS := $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS)) +# ...and turn them into do-nothing targets +$(eval $(_ARGS):;@:) + +production-%: ENVIRONMENT_NAME=production +production-%: TYPO3_CONTEXT=Production +staging-%: ENVIRONMENT_NAME=staging +staging-%: TYPO3_CONTEXT=Production/Staging + +MKFILE_PATH := $(realpath $(firstword $(MAKEFILE_LIST))) +CI_PROJECT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) + +include $(CI_PROJECT_DIR)/.env + +TAG := $(shell git -C $(CI_PROJECT_DIR) describe --abbrev=0) +BUILD_DIR := $(CI_PROJECT_DIR)/Build/ +ALIAS_FILE := $(CI_PROJECT_DIR)/$(ALIAS_SCRIPT) +DEPLOY_FILE := $(CI_PROJECT_DIR)/$(DEPLOY_CONFIG) + +.PHONY: latest-tag +latest-tag: + echo "Latest tag is: $(shell git -C $(CI_PROJECT_DIR) describe --abbrev=0)" + +.PHONY: --build-install +--build-install: + echo "Installed build tools started" + source $(ALIAS_FILE); \ + composer --working-dir=$(BUILD_DIR) install + echo "Installed build tools finished" + +.PHONY: --release +--release: + echo "Release for $(ENVIRONMENT_NAME) with '$(TASK)' started" + source $(ALIAS_FILE); \ + ENVIRONMENT_NAME="$(ENVIRONMENT_NAME)" \ + composer --working-dir=$(BUILD_DIR) exec dep -- $(VERBOSE) --file=$(DEPLOY_FILE) $(TASK) + echo "Release for $(ENVIRONMENT_NAME) with '$(TASK)' finished" + +##@ +##@ Commands to release tag or branch +##@ + +.PHONY: production-release +production-release: ##@ Release latest tag to production +production-release: TASK=deploy --tag $(TAG) +production-release: VERBOSE= +production-release: --build-install --release + + +.PHONY: staging-release +staging-release: ##@ Release develop to staging +staging-release: TASK=deploy --branch develop +staging-release: VERBOSE=-vv +staging-release: --build-install --release +``` + +## Usage per make + Deploy branch develop to staging ```bash -./composer staging develop +make staging-release ``` Deploy tag 1.0.0 to production ```bash -./composer production 1.0.0 +make production-release 1.0.0 ``` -PHPCS fixer usage: -```bash -./composer phpcs-fixer ../package/cp_sitepackage -``` - -PHPStan usage: -```bash -./composer phpstan ../package/cp_sitepackage -``` - -TYPO3 Rector usage: -```bash -./composer rector ../package/cp_sitepackage -``` - -## Overriding default values per host in hosts.yaml +## Overriding default values per host in production.yaml ```yaml -.base: &base - local: true - alias: '{{CI_HOST}}' - deploy_path: '{{CI_PROJECT_DIR}}/cache/{{ENVIRONMENT_NAME}}' - composer_options: '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest --ignore-platform-reqs' +# for more settings look in https://github.com/deployphp/deployer/recipe/common.php +config: + bin/php: 'docker exec -e TYPO3_CONTEXT="{{application_context}}" $(docker ps -q -f name={{INSTANCE_ID}}-php-fpm-1) php' + http_user: sebastian + http_group: www-data + keep_releases: 10 - prepare_dirs: - - .dep - - releases - - shared/fileadmin + repository: git@gitea.fischer.im:evoWeb/website_evoweb_de.git + composer_options: '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest --ignore-platform-reqs' - shared_dirs_private: - - fileadmin + prepare_dirs: + - .dep + - releases + - shared/fileadmin - writable_dirs: - - private/typo3temp - - var - writable_files: - - private/typo3conf/PackageStates.php + shared_dirs: + - fileadmin - rsync: - exclude: - - '-,p private/typo3temp/var/Cache' + writable_recursive: true + writable_dirs: + - public/typo3temp + - var + + rsync: + exclude_download: + - 'current' + - 'shared/' + - 'var/*' + - '-,p public/typo3temp' + + remote_path: /srv/{{INSTANCE_ID}}/data/htdocs/production + app_container_path: /usr/local/apache2/htdocs/production + application_context: Production + web_domain: https://www.evoweb.de/ + + +hosts: + production: + remote_user: sebastian + hostname: '{{CI_HOST}}' + deploy_path: '{{CI_PROJECT_DIR}}/Build/cache/{{ENVIRONMENT_NAME}}' + identity_file: ~/.ssh/rsync_id_ed25519 +``` + +## Overriding default values per host in staging.yaml +```yaml +# for more settings look in https://github.com/deployphp/deployer/recipe/common.php +config: + bin/php: 'docker exec -e TYPO3_CONTEXT="{{application_context}}" $(docker ps -q -f name={{INSTANCE_ID}}-php-fpm-1) php' + http_user: sebastian + http_group: www-data + keep_releases: 5 + + repository: git@gitea.fischer.im:evoWeb/website_evoweb_de.git + composer_options: '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest --ignore-platform-reqs' + + prepare_dirs: + - .dep + - releases + - shared/fileadmin + + shared_dirs: + - public/fileadmin + + writable_recursive: true + writable_dirs: + - public/typo3temp + - var + + rsync: + exclude_download: + - 'current' + - 'shared/' + - 'var/*' + - '-,p public/typo3temp' + + remote_path: /srv/{{INSTANCE_ID}}/data/htdocs/staging + app_container_path: /usr/local/apache2/htdocs/staging + application_context: Production/Staging + web_domain: https://staging.evoweb.de/ + htaccess: evoweb:website + +hosts: + staging: + remote_user: sebastian + hostname: '{{CI_HOST}}' + deploy_path: '{{CI_PROJECT_DIR}}/Build/cache/{{ENVIRONMENT_NAME}}' + identity_file: ~/.ssh/rsync_id_ed25519 ``` diff --git a/alias.sh b/alias.sh index af13124..6ab0f0d 100644 --- a/alias.sh +++ b/alias.sh @@ -18,6 +18,7 @@ function composer() { --volume "$(readlink -f ${SSH_AUTH_SOCK})":/ssh-agent \ --volume /etc/passwd:/etc/passwd:ro \ --volume "${HOME}":"${HOME}" \ + --volume "${HOME}/.ssh/known_hosts":/home/.ssh-agent/known_hosts \ --volume "${HOME}/.config/composer":/tmp \ --volume "${HOME}/.cache/composer":/cache \ --volume "${CI_PROJECT_DIR}":"${CI_PROJECT_DIR}" \