198 lines
5.1 KiB
Markdown
198 lines
5.1 KiB
Markdown
## To install add Build/composer.json to the project
|
|
```json
|
|
{
|
|
"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"
|
|
}
|
|
}
|
|
```
|
|
|
|
## Add to Build/alias.sh with
|
|
```shell
|
|
#!/bin/bash
|
|
|
|
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 \
|
|
--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=production
|
|
production-%: TYPO3_CONTEXT=Production
|
|
staging-%: ENVIRONMENT=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) with '$(TASK)' started"
|
|
source $(ALIAS_FILE); \
|
|
ENVIRONMENT="$(ENVIRONMENT)" \
|
|
composer --working-dir=$(BUILD_DIR) exec dep -- $(VERBOSE) --file=$(DEPLOY_FILE) $(TASK) environment=$(ENVIRONMENT)
|
|
echo "Release for $(ENVIRONMENT) 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
|
|
make staging-release
|
|
```
|
|
|
|
Deploy tag 1.0.0 to production
|
|
```bash
|
|
make production-release 1.0.0
|
|
```
|
|
|
|
## Overriding default values per host in hosts.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
|
|
|
|
remote_user: sebastian
|
|
identity_file: ~/.ssh/rsync_id_ed25519
|
|
deploy_path: '{{CI_PROJECT_DIR}}/Build/cache/{{ENVIRONMENT}}'
|
|
|
|
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/public/fileadmin
|
|
|
|
shared_dirs:
|
|
- public/fileadmin
|
|
|
|
writable_recursive: true
|
|
writable_dirs:
|
|
- public/typo3temp
|
|
- var
|
|
- var/cache
|
|
- var/log
|
|
|
|
rsync:
|
|
exclude_download:
|
|
- current
|
|
- shared/
|
|
- var/*
|
|
- '-,p public/typo3temp'
|
|
|
|
remote_path: /srv/{{INSTANCE_ID}}/data/htdocs/{{ENVIRONMENT}}
|
|
app_container_path: /usr/local/apache2/htdocs/{{ENVIRONMENT}}
|
|
|
|
hosts:
|
|
staging.evoweb.de:
|
|
hostname: '{{CI_HOST}}'
|
|
labels:
|
|
environment: staging
|
|
application_context: Production/Staging
|
|
htaccess: evoweb:website
|
|
|
|
www.evoweb.de:
|
|
hostname: '{{CI_HOST}}'
|
|
labels:
|
|
environment: production
|
|
application_context: Production
|
|
|
|
```
|