Commit c2decc44 authored by Stefan Busemann's avatar Stefan Busemann

Merge branch '2-set-up-basic-environment' into 'master'

Resolve "Set up basic environment"

Closes #2

See merge request !1
parents 5771b759 3adc93ec
Pipeline #5401 failed with stages
in 5 minutes and 19 seconds
/import.yaml
/docker-compose.yaml
/db_snapshots
/sequelpro.spf
APIVersion: v1.3.0
name: get.typo3.org
type: typo3
docroot: html
php_version: "7.0"
webserver_type: nginx-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
provider: default
hooks:
post-start:
- exec: cp typo3conf/AdditionalConfiguration.ddev.php typo3conf/AdditionalConfiguration.php
- exec: composer install -d /var/www/html
- exec: npm --prefix typo3conf/ext/t3olayout/Build install
- exec: npm --prefix typo3conf/ext/t3olayout/Build run-script build
- exec: ../vendor/bin/typo3cms install:generatepackagestates
- exec: ../vendor/bin/typo3cms install:extensionsetupifpossible
# This config.yaml was created with ddev version v1.3.0
# webimage: drud/ddev-webserver:v1.3.0
# dbimage: drud/ddev-dbserver:v1.3.0
# dbaimage: drud/phpmyadmin:v1.3.0
# However we do not recommend explicitly wiring these images into the
# config.yaml as they may break future versions of ddev.
# You can update this config.yaml using 'ddev config'.
# Key features of ddev's config.yaml:
# name: <projectname> # Name of the project, automatically provides
# http://projectname.ddev.local and https://projectname.ddev.local
# type: <projecttype> # drupal6/7/8, backdrop, typo3, wordpress, php
# docroot: <relative_path> # Relative path to the directory containing index.php.
# php_version: "7.1" # PHP version to use, "5.6", "7.0", "7.1", "7.2"
# You can explicitly specify the webimage, dbimage, dbaimage lines but this
# is not recommended, as the images are often closely tied to ddev's' behavior,
# so this can break upgrades.
# webimage: <docker_image> # nginx/php docker image.
# dbimage: <docker_image> # mariadb docker image.
# dbaimage: <docker_image>
# router_http_port: <port> # Port to be used for http (defaults to port 80)
# router_https_port: <port> # Port for https (defaults to 443)
# xdebug_enabled: false # Set to true to enable xdebug and "ddev start" or "ddev restart"
# webserver_type: nginx-fpm # Can be set to apache-fpm or apache-cgi as well
# additional_hostnames:
# - somename
# - someothername
# would provide http and https URLs for "somename.ddev.local"
# and "someothername.ddev.local".
# additional_fqdns:
# - example.com
# - sub1.example.com
# would provide http and https URLs for "example.com" and "sub1.example.com"
# Please take care with this because it can cause great confusion.
# upload_dir: custom/upload/dir
# would set the destination path for ddev import-files to custom/upload/dir.
# provider: default # Currently either "default" or "pantheon"
#
# Many ddev commands can be extended to run tasks after the ddev command is
# executed.
# See https://ddev.readthedocs.io/en/latest/users/extending-commands/ for more
# information on the commands that can be extended and the tasks you can define
# for them. Example:
#hooks:
# post-start:
# - exec: composer install -d /var/www/html
\ No newline at end of file
version: '3.6'
services:
web:
environment:
- TYPO3_CONTEXT=Development
/.idea
/vendor
/html/typo3
/html/index.php
/html/typo3temp
/html/uploads
/html/typo3conf/AdditionalConfiguration.php
/html/typo3conf/PackageStates.php
/html/typo3conf/deprecation_*.log
/html/typo3conf/realurl_autoconf.php
/html/typo3conf/l10n
/html/typo3conf/ext/*
!/html/typo3conf/ext/t3oget
variables:
GIT_STRATEGY: "none"
GIT_SSL_NO_VERIFY: "true"
before_script:
- apk add bash --no-cache
stages:
- dump
- test
- build
- layout
- deploy
test:php:
stage: test
image: ekreative/php-cs-fixer:2
variables:
GIT_STRATEGY: "clone"
script:
- php-cs-fixer fix --dry-run --config=.gitlab-ci/build/.php_cs --diff
except:
- assets
build:
stage: build
image: php:7.0-alpine
variables:
GIT_STRATEGY: "clone"
GIT_SUBMODULE_STRATEGY: "recursive"
before_script:
- apk add bash --no-cache
- apk add git --update
- curl https://getcomposer.org/composer.phar -o composer.phar --silent
- chmod +x composer.phar
script:
- ./composer.phar config store-auths false
- ./composer.phar config http-basic.git-t3o.typo3.org gitlab-ci-token ${CI_BUILD_TOKEN}
- ./composer.phar install
artifacts:
paths:
- ./
expire_in: '1h'
except:
- assets
layout:
stage: layout
image: node:8
before_script:
- cd html/typo3conf/ext/t3olayout/Build
script:
- npm install
- npm run build
artifacts:
paths:
- ./
expire_in: '7d'
dependencies:
- build
except:
- assets
.deploy-template: &deploy_template
stage: deploy
image:
name: "torvitas/deployer:4.0.0-alpine"
entrypoint: [""]
before_script:
- mkdir -p /root/.ssh/
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY_STAGE" | ssh-add -
- echo "$SSH_PRIVATE_KEY_PRODUCTION" | ssh-add -
- ssh-keyscan -p 22191 my-stage.typo3.org >> /root/.ssh/known_hosts
- ssh-keyscan -p 22193 my.typo3.org >> /root/.ssh/known_hosts
script:
- dep -f./.gitlab-ci/deployer/deploy.php deploy ${CI_BUILD_REF_NAME}
dependencies:
- layout
except:
- assets
deploy-master:
<<: *deploy_template
environment:
name: master
url: https://my.typo3.org/
only:
- master
deploy-develop:
<<: *deploy_template
environment:
name: develop
url: https://my-stage.typo3.org/
only:
- develop
dump-assets:
<<: *deploy_template
stage: dump
image: alpine:3.5
artifacts:
paths:
- ./assets/
expire_in: '3d'
script:
- apk add rsync --no-cache
- rsync -ah -e "ssh -p 22191" --exclude=typo3conf my@my-stage.typo3.org:ci/shared/ ./assets/
- ssh -p22191 my@my-stage.typo3.org "mysqldump -u${STAGE_DATABASE_USER} -p${STAGE_DATABASE_PASSWORD} -h127.0.0.1 ${STAGE_DATABASE_DB} | gzip -9 -c" > ./assets/db.sql.gz
dependencies:
when:
tags:
- proxy
only:
- assets
except:
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This file represents the configuration for Code Sniffing PSR-2-related
* automatic checks of coding guidelines
* Install @fabpot's great php-cs-fixer tool via
*
* $ composer global require friendsofphp/php-cs-fixer
*
* And then simply run
*
* $ php-cs-fixer fix --config ../Build/.php_cs
*
* inside the TYPO3 directory. Warning: This may take up to 10 minutes.
*
* For more information read:
* https://www.php-fig.org/psr/psr-2/
* https://cs.sensiolabs.org
*/
if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
// Define in which folders to search and which folders to exclude
// Exclude some directories that are excluded by Git anyways to speed up the sniffing
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('typo3temp')
->in(__DIR__ . '/../../');
// Return a Code Sniffing configuration using
// all sniffers needed for PSR-2
// and additionally:
// - Remove leading slashes in use clauses.
// - PHP single-line arrays should not have trailing comma.
// - Single-line whitespace before closing semicolon are prohibited.
// - Remove unused use statements in the PHP source code
// - Ensure Concatenation to have at least one whitespace around
// - Remove trailing whitespace at the end of blank lines.
return PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules([
'@PSR2' => true,
'@DoctrineAnnotation' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'concat_space' => ['spacing' => 'one'],
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'single_quote' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'no_blank_lines_after_phpdoc' => true,
'array_syntax' => ['syntax' => 'short'],
'whitespace_after_comma_in_array' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'no_alias_functions' => true,
'lowercase_cast' => true,
'no_leading_namespace_whitespace' => true,
'native_function_casing' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_trim' => true,
'no_superfluous_elseif' => true,
'no_useless_else' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'cast_spaces' => ['space' => 'none'],
'declare_equal_normalize' => ['space' => 'single'],
'dir_constant' => true,
])->setFinder($finder);
<?php
namespace Deployer;
require_once '/composer/vendor/deployer/deployer/recipe/common.php';
require_once '/composer/vendor/deployer/recipes/rsync.php';
$sharedDirectories = [
'html/fileadmin',
'html/uploads',
'html/.well-known'
];
set('shared_dirs', $sharedDirectories);
$sharedFiles = [
'html/typo3conf/AdditionalConfiguration.php',
'.cachetool.yml'
];
set('shared_files', $sharedFiles);
$writeableDirectories = [
'html/typo3temp',
'html/fileadmin',
'html/uploads'
];
set('writable_dirs', $writeableDirectories);
$exclude = [
'.gitignore',
'.htaccess',
'.git',
'Readme.rst',
'Readme.txt',
'Upgrading.rst',
'Upgrading.txt',
'README',
'*.example',
'AdditionalConfiguration.sample.php'
];
set('rsync', [
'exclude' => array_merge($sharedDirectories, $sharedFiles, $exclude),
'exclude-file' => false,
'include' => [],
'include-file' => false,
'filter' => [],
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'az',
'options' => ['delete'],
'timeout' => 300
]);
set('rsync_src', './');
set('keep_releases', 10);
serverList('./.gitlab-ci/deployer/servers.yml');
set('php', '/opt/php/php70/bin/php');
set('typo3_console', 'vendor/bin/typo3cms');
task('typo3', function () {
run('cd {{release_path}} && {{php}} {{typo3_console}} install:generatepackagestates');
run('cd {{release_path}} && {{php}} {{typo3_console}} install:extensionsetupifpossible');
});
task('cache', function () {
run('cd {{release_path}} && {{php}} vendor/bin/cachetool opcache:reset');
});
task('deploy', [
'deploy:prepare',
'deploy:release',
'rsync:warmup',
'rsync',
'deploy:shared',
'deploy:writable',
'typo3',
'deploy:symlink',
'cache',
'cleanup',
]);
master:
stage: production
host: get.typo3.org
port: 22193
user: my
forward_agent: true
deploy_path: ~/ci
develop:
stage: stage
host: get-stage.typo3.org
port: 22191
user: mystage
forward_agent: true
deploy_path: ~/ci/
#!/bin/bash
#
# Runs composer in a container.
#
# Additional to all inputs that dockerrun.sh accepts, following environment
# variables are available:
#
# - COMPOSER_CACHE: Defaults to $PWD/tmp/composer, directory where Composer will
# save cached files to.
# - COMPOSER_FILE: Path to composer configuration, its directory will be mounted
# into the container. If left empty, no additional mount will occur.
# - ENVIRONMENT_FILE: Path to a shell script to source for environment values.
# Note that variables sourced from this file won't be passed into the Docker
# container automatically, use DOCKER_OPTIONS for this.
#
set -e
SCRIPT_DIR="${BASH_SOURCE%/*}"
VERSION="${VERSION:-1-alpine}"
IMAGE="${IMAGE:-torvitas/composer:$VERSION}"
# You can set an environment file to be used using the $ENVIRONMENT_FILE
# environment variable.
ENVIRONMENT_FILE="${ENVIRONMENT_FILE:-$PWD/.env}"
if [ -e "$ENVIRONMENT_FILE" ]; then
source "$ENVIRONMENT_FILE"
fi
# You can add additional volumes (or any docker run options) using
# the $COMPOSER_OPTIONS environment variable.
DOCKER_OPTIONS+=("${COMPOSER_OPTIONS[@]}")
# You can set the composer cache directory using the $COMPOSER_CACHE
# environment variable.
COMPOSER_CACHE="${COMPOSER_CACHE:-$PWD/tmp/composer}"
if [ -n "${COMPOSER_CACHE}" ]; then
mkdir -p "${COMPOSER_CACHE}"
DOCKER_OPTIONS+=(-v "$(readlink -f "${COMPOSER_CACHE}"):/composer/cache")
fi
# Mount directory of deployer configuration
if [ -n "${COMPOSER_FILE}" ]; then
composer_dir=$(dirname "${COMPOSER_FILE}")
fi
if [ -n "${composer_dir}" ] && [ -d "${composer_dir}" ]; then
DOCKER_OPTIONS+=(-v "$(readlink -f "${composer_dir}"):${composer_dir}")
fi
# shellcheck source=./dockerrun.sh
. "${SCRIPT_DIR}/dockerrun.sh" "${IMAGE}" "$@"
#!/bin/bash
#
# Runs deployer in a container.
#
# Accepts all environment variables that dockerrun.sh accepts as well.
# Additionally, the following environment variables are accepted:
#
# - DEPLOYER_FILE: Path to deployer configuration, its directory will be mounted
# into the container. If left empty, no additional mount will occur.
# - ENVIRONMENT_FILE: Path to a shell script to source for environment values.
# Note that variables sourced from this file won't be passed into the Docker
# container automatically, use DOCKER_OPTIONS for this.
#
# Also mounts current directory in /src.
#
set -e
SCRIPT_DIR="${BASH_SOURCE%/*}"
VERSION="${VERSION:-4.0.0-php5-alpine}"
IMAGE="${IMAGE:-torvitas/deployer:$VERSION}"
# You can set an environment file to be used using the $ENVIRONMENT_FILE
# environment variable.
ENVIRONMENT_FILE=${ENVIRONMENT_FILE:-$PWD/.env}
if [ -e "$ENVIRONMENT_FILE" ]; then
source $ENVIRONMENT_FILE
fi
# You can add additional volumes (or any docker run options) using
# the $DEPLOYER_OPTIONS environment variable.
DOCKER_OPTIONS+=("${DEPLOYER_OPTIONS[@]}")
# Additional mounts
DOCKER_OPTIONS+=(-v "${PWD}:/src")
# Mount directory of deployer configuration
if [ -n "${DEPLOYER_FILE}" ]; then
deployer_dir=$(dirname "${DEPLOYER_FILE}")
fi
if [ -n "${deployer_dir}" ]; then
DOCKER_OPTIONS+=(-v "${deployer_dir}:${deployer_dir}")
fi
# shellcheck source=./dockerrun.sh
. "${SCRIPT_DIR}/dockerrun.sh" "${IMAGE}" "$@"
#!/bin/bash
#
# Runs docker-compose in a container.
#
# Accepts all environment variables that dockerrun.sh accepts as well. Passes
# through all environment variables that docker-compose supports.
#
set -e
SCRIPT_DIR="${BASH_SOURCE%/*}"
VERSION="${VERSION:-1.11.1}"
IMAGE="${IMAGE:-docker/compose:$VERSION}"
# Pass through environment variables that docker-compose supports, see
# https://docs.docker.com/compose/reference/envvars/ for the full list.
DOCKER_OPTIONS+=(
-e COMPOSE_PROJECT_NAME
-e COMPOSE_FILE
-e COMPOSE_API_VERSION
-e COMPOSE_HTTP_TIMEOUT
-e COMPOSE_TLS_VERSION
-e COMPOSE_CONVERT_WINDOWS_PATHS
)
# Setup options for connecting to docker host
# DOCKER_HOST is not just a path to the socket, but may be prefixed with "unix://".
DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}"
docker_host_file="${DOCKER_HOST#unix://}"
if [ -S "${docker_host_file}" ]; then
# Local Docker host.
DOCKER_OPTIONS+=(
-v "${docker_host_file}:${docker_host_file}"
-e DOCKER_HOST
-e DOCKER_TLS_VERIFY
-e DOCKER_CERT_PATH
)
else
# Remote Docker host.
# Prevent docker-compose from being run on remote, instead let docker-compose
# communicate with remote, running locally.
DOCKER_OPTIONS+=(
-e "DOCKER_HOST=${DOCKER_HOST}"
-e "DOCKER_TLS_VERIFY=${DOCKER_TLS_VERIFY}"
-e "DOCKER_CERT_PATH=${DOCKER_CERT_PATH}"
)
unset DOCKER_HOST
unset DOCKER_TLS_VERIFY
unset DOCKER_CERT_PATH
fi
# Mount certificate path if any given.
if [ -n "${DOCKER_CERT_PATH}" ] && [ -d "${DOCKER_CERT_PATH}" ]; then
DOCKER_OPTIONS+=(-v "${DOCKER_CERT_PATH}:${DOCKER_CERT_PATH}")
fi
# Mount directory of compose project file if any given.
if [ -n "${COMPOSE_FILE}" ] && [ -f "${COMPOSE_FILE}" ]; then
compose_dir=$(dirname "${COMPOSE_FILE}")
DOCKER_OPTIONS+=(-v "${compose_dir}:${compose_dir}")
fi
# shellcheck source=./dockerrun.sh
. "${SCRIPT_DIR}/dockerrun.sh" "${IMAGE}" "$@"
#!/bin/bash -e
#
# This script mounts all relevant paths from the host system straight into the
# container to allow for transparent usage of Docker images.
#
# Environment variables that this script will accept:
#
# - DOCKER_PULL_OPTIONS: Flags that will be passed along with `docker pull`.
# - DOCKER_OPTIONS: Flags that will be passed along with `docker run`.
# - NO_PULL: Do not attempt to pull the wanted Docker image before running it.
# By default this script will update to the latest version of the Docker image
# that matches, this environment variable will prevent it from happening if
# set to anything non-zero.
#
# Generates a volume definition that maps the volume into the container at the
# exact same path as the host.
mirror_volume() {
echo -n "$(readlink -f "$1"):$1"
if [ ! -z "$2" ]; then
echo -n ":$2"
fi
}
# Read image to use from arguments.
IMAGE="$1"
shift 1
# Mirror user and group
DOCKER_OPTIONS+=(-u "${UID}:$(id -g)")
if [ -e "${HOME}" ]; then
DOCKER_OPTIONS+=(-v "$(mirror_volume "${HOME}")")
fi
if [ -e "/etc/group" ]; then
DOCKER_OPTIONS+=(-v "$(mirror_volume /etc/group ro)")
fi
if [ -e "/etc/gshadow" ]; then
DOCKER_OPTIONS+=(-v "$(mirror_volume /etc/gshadow ro)")
fi
if [ -e "/etc/passwd" ]; then
DOCKER_OPTIONS+=(-v "$(mirror_volume /etc/passwd ro)")
fi
if [ -e "/etc/shadow" ]; then
DOCKER_OPTIONS+=(-v "$(mirror_volume /etc/shadow ro)")
fi
# Pass through current working directory.
# @TODO - Find a more consistent solution if possible.
if [ "${PWD}" = "/" ]; then
DOCKER_OPTIONS+=(
-v "$(readlink -f "${PWD}"):/host/${PWD}"
-w "/host/${PWD}"
)
else
DOCKER_OPTIONS+=(
-v "$(mirror_volume "${PWD}")"
-w "${PWD}"
)
fi
# Mount SSH known hosts.
# @TODO - Merge in ssh_known_hosts from user & system dirs using temp file?
if [ -n "${SSH_KNOWN_HOSTS}" ]; then
DOCKER_OPTIONS+=(-v "${SSH_KNOWN_HOSTS}:/etc/ssh/ssh_known_hosts")
fi
# Pass through SSH agent, if we can't find an agent, start one.
if [ -z "${SSH_AUTH_SOCK}" ] || [ ! -e "${SSH_AUTH_SOCK}" ]; then
eval "$(ssh-agent -s)"
fi
DOCKER_OPTIONS+=(-e "SSH_AUTH_SOCK=/ssh-agent")
if [ -e "${SSH_AUTH_SOCK}" ]; then
DOCKER_OPTIONS+=(-v "${SSH_AUTH_SOCK}:/ssh-agent")
fi
# Only allocate tty if we detect one
if [ -t 1 ]; then
DOCKER_OPTIONS+=(-t)
fi
if [ -t 0 ]; then
DOCKER_OPTIONS+=(-i)
fi
# Append supplementary groups to DOCKER_OPTIONS
for val in $(id -G); do
DOCKER_OPTIONS+=(--group-add "${val}")
done
if [ -z "${NO_PULL}" ]; then
docker pull \
"${DOCKER_PULL_OPTIONS[@]}" \
"${IMAGE}"
fi
if [ -n "${SCRIPT_DEBUG}" ]; then
echo docker run --rm \
"${DOCKER_OPTIONS[@]}" \
"${IMAGE}" \
"$@"
fi
exec docker run --rm \
"${DOCKER_OPTIONS[@]}" \
"${IMAGE}" \
"$@"
#!/bin/bash
#
# Runs git in a container.
#
# Accepts all environment variables that dockerrun.sh accepts as well. Passes
# through the following environment variables for git:
#
# - GIT_ALTERNATE_OBJECT_DIRECTORIES
# - GIT_AUTHOR_DATE
# - GIT_AUTHOR_EMAIL
# - GIT_AUTHOR_NAME
# - GIT_COMMITTER_DATE
# - GIT_COMMITTER_EMAIL
# - GIT_COMMITTER_NAME
# - GIT_CONFIG_NOSYSTEM
# - GIT_DIFF_OPTS
# - GIT_DIR
# - GIT_GLOB_PATHSPECS
# - GIT_HTTP_USER_AGENT
# - GIT_ICASE_PATHSPECS
# - GIT_INDEX_FILE
# - GIT_LITERAL_PATHSPECS
# - GIT_MERGE_VERBOSITY
# - GIT_NOGLOB_PATHSPECS
# - GIT_OBJECT_DIRECTORY
# - GIT_SSL_NO_VERIFY
# - GIT_WORK_TREE
#
# Accepts the following additional environment variables:
#
# - ENVIRONMENT_FILE: Path to a shell script to source for environment values.
# Note that variables sourced from this file won't be passed into the Docker
# container automatically, use DOCKER_OPTIONS for this.
#
# For a full list of environment variables that Git supports, check
# https://git-scm.com/book/tr/v2/Git-Internals-Environment-Variables.
set -e
SCRIPT_DIR="${BASH_SOURCE%/*}"
VERSION="${VERSION:-alpine-2.11.1-r0}"
IMAGE="${IMAGE:-torvitas/git:$VERSION}"
# You can set an environment file to be used using the $ENVIRONMENT_FILE
# environment variable.
ENVIRONMENT_FILE="${ENVIRONMENT_FILE:-$PWD/.env}"
if [ -e "$ENVIRONMENT_FILE" ]; then
source "$ENVIRONMENT_FILE"
fi
DOCKER_OPTIONS+=(