Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
b23prodtm committed Aug 26, 2019
1 parent b234611 commit 2405e18
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .circleci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
work_dir=$(echo $0 | awk -F'/' 'BEGIN {ORS="/"} {for ( i=0; ++i<NF;) print $i}')
sed -e /custom_checkout:/s/"\"\""/"\"\/tmp\/_circleci_local_build_repo\""/ $work_dir/config.yml | circleci config process - > $work_dir/config-compat.yml
circleci local execute -c $work_dir/config-compat.yml
207 changes: 207 additions & 0 deletions .circleci/config-compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
version: 2
jobs:
build:
docker:
- image: betothreeprod/cci-composer:0.1.6
- image: betothreeprod/cci-mariadb:10.1.41
environment:
PUID: 1000
PGID: 1000
TZ: Europe/Paris
MYSQL_DATABASE: foo_db
MYSQL_ROOT_PASSWORD: foo_pass
MYSQL_USER: dummy_foo
MYSQL_PASSWORD: foo_pass_test
environment:
- DKR_ARCH: x86_64
- BALENA_MACHINE_NAME: intel-nuc
- PHP_TAG: 7.2-apache
- PHP_OWNER: amd64
- DB_TAG: amd64-latest
- DB: Mysql
- DATABASE_ENGINE: MysqlCms
- DATABASE_SERVICE_NAME: MYSQL
- MYSQL_SERVICE_HOST: 127.0.0.1
- MYSQL_SERVICE_PORT: 3306
- TEST_MYSQL_SERVICE_HOST: 127.0.0.1
- TEST_MYSQL_SERVICE_PORT: 3306
- DATABASE_USER: root
- DATABASE_NAME: foo_db
- DATABASE_PASSWORD: foo_pass
- TEST_DATABASE_NAME: foo_db_test
- TEST_DATABASE_USER: dummy_foo
- TEST_DATABASE_PASSWORD: foo_pass_test
- SERVER_NAME: local
- PHP_CMS_DIR: app/webroot/php_cms
- GET_HASH_PASSWORD: saQlojmPPqVyU
working_directory: /var/www/html/
steps:
- run:
command: mkdir -p $CIRCLE_WORKING_DIRECTORY && cd /tmp/_circleci_local_build_repo
&& git ls-files | tar -T - -c | tar -x -C $CIRCLE_WORKING_DIRECTORY && cp
-a /tmp/_circleci_local_build_repo/.git $CIRCLE_WORKING_DIRECTORY
- run:
command: git submodule sync
- run:
command: git submodule update --init --recursive
- run:
name: Waiting for Mysql to be ready
command: |
set -x
for i in `seq 1 10`;
do
nc -z $TEST_MYSQL_SERVICE_HOST $TEST_MYSQL_SERVICE_PORT && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Mysql
&& exit 1
- restore_cache:
keys:
- v1-dependencies-{{ checksum "composer.lock" }}
- v1-dependencies-
- setup_remote_docker:
docker_layer_caching: true
- run:
command: composer install -n --prefer-dist
- save_cache:
key: v1-dependencies-{{ checksum "composer.lock" }}
paths:
- ./app/Vendor/
- run:
command: |
set -x
mkdir -p ./app/build/logs
mkdir -p ~/phpunit
./test-cake.sh --circle --openshift
when: always
- run:
command: |
set -x
TAG=0.1.$CIRCLE_BUILD_NUM
./Scripts/docker-compose-alias.sh --openshift -v up -d --build
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push $DOCKER_USER/myphpcms:$TAG
- store_test_results:
path: ~/phpunit
- store_artifacts:
path: ~/phpunit
workflows:
build-and-compose:
jobs:
- build
version: 2

# Original config.yml file:
# # PHP CircleCI 2.0 configuration file
# #
# # Check https://circleci.com/docs/2.0/language-php/ for more details
# #
# version: 2.1
# jobs:
# build:
# docker:
# # using custom image, see .circleci/images/primary/Dockerfile
# - image: betothreeprod/cci-composer:0.1.6
# - image: betothreeprod/cci-mariadb:10.1.41
# #- image: linuxserver/mariadb:amd64-latest
# environment:
# PUID: 1000
# PGID: 1000
# TZ: Europe/Paris
# MYSQL_DATABASE: foo_db
# MYSQL_ROOT_PASSWORD: foo_pass
# MYSQL_USER: dummy_foo
# MYSQL_PASSWORD: foo_pass_test
# environment:
# DKR_ARCH: x86_64
# BALENA_MACHINE_NAME: intel-nuc
# PHP_TAG: 7.2-apache
# PHP_OWNER: amd64
# DB_TAG: amd64-latest
# DB: Mysql
# DATABASE_ENGINE: MysqlCms
# DATABASE_SERVICE_NAME: MYSQL
# MYSQL_SERVICE_HOST: 127.0.0.1
# MYSQL_SERVICE_PORT: 3306
# TEST_MYSQL_SERVICE_HOST: 127.0.0.1
# TEST_MYSQL_SERVICE_PORT: 3306
# DATABASE_USER: root
# DATABASE_NAME: foo_db
# DATABASE_PASSWORD: foo_pass
# TEST_DATABASE_NAME: foo_db_test
# TEST_DATABASE_USER: dummy_foo
# TEST_DATABASE_PASSWORD: foo_pass_test
# SERVER_NAME: local
# PHP_CMS_DIR: app/webroot/php_cms
# GET_HASH_PASSWORD: saQlojmPPqVyU
# working_directory: /var/www/html/
# parameters:
# custom_checkout:
# description: use custom local checkout fix in CLI
# type: string
# default: \"\"
# steps:
# - when:
# condition: << parameters.custom_checkout >>
# steps:
# - run: mkdir -p $CIRCLE_WORKING_DIRECTORY && cd << parameters.custom_checkout >> && git ls-files | tar -T - -c | tar -x -C $CIRCLE_WORKING_DIRECTORY && cp -a << parameters.custom_checkout >>/.git $CIRCLE_WORKING_DIRECTORY
# - unless:
# condition: <<parameters.custom_checkout>>
# steps:
# - checkout
# - run: git submodule sync
# - run: git submodule update --init --recursive
# - run:
# name: Waiting for Mysql to be ready
# command: |
# set -x
# for i in `seq 1 10`;
# do
# nc -z $TEST_MYSQL_SERVICE_HOST $TEST_MYSQL_SERVICE_PORT && echo Success && exit 0
# echo -n .
# sleep 1
# done
# echo Failed waiting for Mysql
# && exit 1
# # Download and cache dependencies
# - restore_cache:
# keys:
# # \"composer.lock\" can be used if it is committed to the repo
# - v1-dependencies-{{ checksum \"composer.lock\" }}
# # fallback to using the latest cache if no exact match is found
# - v1-dependencies-
#
# - setup_remote_docker: # (2)
# docker_layer_caching: true # (3)
# - run: composer install -n --prefer-dist
# - save_cache:
# key: v1-dependencies-{{ checksum \"composer.lock\" }}
# paths:
# - ./app/Vendor/
# # PHPUnit tests
# - run:
# command: |
# set -x
# mkdir -p ./app/build/logs
# mkdir -p ~/phpunit
# ./test-cake.sh --circle --openshift
# when: always
# # use a primary image that already has Docker (recommended)
# # build and push Docker image
# # (4)
# - run: |
# set -x
# TAG=0.1.$CIRCLE_BUILD_NUM
# ./Scripts/docker-compose-alias.sh --openshift -v up -d --build
# docker login -u $DOCKER_USER -p $DOCKER_PASS
# docker push $DOCKER_USER/myphpcms:$TAG
# - store_test_results:
# path: ~/phpunit
# - store_artifacts:
# path: ~/phpunit
# workflows:
# build-and-compose:
# jobs:
# - build:
# custom_checkout: \"/tmp/_circleci_local_build_repo\"
28 changes: 22 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
version: 2.1
jobs:
build:
docker:
Expand Down Expand Up @@ -39,11 +39,22 @@ jobs:
TEST_DATABASE_PASSWORD: foo_pass_test
SERVER_NAME: local
PHP_CMS_DIR: app/webroot/php_cms
GET_HASH_PASSWORD: saQlojmPPqVyU
working_directory: /var/www/html/
parameters:
custom_checkout:
description: use custom local checkout fix in CLI
type: string
default: ""
steps:
- checkout
# circleci CLI fix checkout
# - run: mkdir -p /var/www/html && cd /tmp/_circleci_local_build_repo && git ls-files | tar -T - -c | tar -x -C /var/www/html && cp -a /tmp/_circleci_local_build_repo/.git /var/www/html 2> /dev/null
- when:
condition: << parameters.custom_checkout >>
steps:
- run: mkdir -p $CIRCLE_WORKING_DIRECTORY && cd << parameters.custom_checkout >> && git ls-files | tar -T - -c | tar -x -C $CIRCLE_WORKING_DIRECTORY && cp -a << parameters.custom_checkout >>/.git $CIRCLE_WORKING_DIRECTORY
- unless:
condition: <<parameters.custom_checkout>>
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init --recursive
- run:
Expand Down Expand Up @@ -76,7 +87,7 @@ jobs:
# PHPUnit tests
- run:
command: |
set -xu
set -x
mkdir -p ./app/build/logs
mkdir -p ~/phpunit
./test-cake.sh --circle --openshift
Expand All @@ -85,7 +96,7 @@ jobs:
# build and push Docker image
# (4)
- run: |
set -xu
set -x
TAG=0.1.$CIRCLE_BUILD_NUM
./Scripts/docker-compose-alias.sh --openshift -v up -d --build
docker login -u $DOCKER_USER -p $DOCKER_PASS
Expand All @@ -94,3 +105,8 @@ jobs:
path: ~/phpunit
- store_artifacts:
path: ~/phpunit
workflows:
build-and-compose:
jobs:
- build:
custom_checkout: ""
2 changes: 1 addition & 1 deletion .circleci/images/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
export work_dir=$(echo $0 | awk -F'/' 'BEGIN {ORS="/"} {for ( i=0; ++i<NF;) print $i}')
work_dir=$(echo $0 | awk -F'/' 'BEGIN {ORS="/"} {for ( i=0; ++i<NF;) print $i}')
[ "$#" -lt 3 ] && echo -e "Usage: $0 <work_sub_dir> <container_name> <TAG>
work_sub_dir:
Path relative to $0
Expand Down
25 changes: 11 additions & 14 deletions Scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ set -e
source ./Scripts/lib/shell_prompt.sh
source ./Scripts/lib/parsing.sh
openshift=$(parse_arg_exists "-[oO]*|--openshift" $*)
if [ -z ${PHP_CMS_DIR} ]; echo "Please set PHP_CMS_DIR=app/webroot/php_cms pathname environment."; exit 1; fi
if [ -z ${DB} ]; echo "Please set DB=Mysql environment."; exit 1; fi
if [ -z ${DATABASE_PASSWORD} ]; echo "Please set DATABASE_PASSWORD=password environment."; exit 1; fi
if [ $openshift 2> /dev/null ]; then
echo "Real environment bootargs..."
export CAKEPHP_DEBUG_LEVEL=1
Expand All @@ -18,28 +15,28 @@ fi
#; check if file etc/constantes_local.properties exist (~ ./configure.sh was run once)
#;
if [ ! -f ${PHP_CMS_DIR}/e13/etc/constantes.properties ]; then
shell_prompt "./configure.sh -c" "missing file creation constantes.properties"
shell_prompt "./configure.sh -c" "missing file creation constantes.properties"
fi
echo "Configuration begins automatically..."
#; hash file that is stored in webroot to allow administrator privileges
if [[ ! $GET_HASH_PASSWORD ]]; then
hash="${PHP_CMS_DIR}/e13/etc/export_hash_password.sh"
if [ ! -f $hash ]; then
shell_prompt "./configure.sh -c -h " "define a value for missing GET_HASH_PASSWORD"
shell_prompt "./configure.sh -c -h " "define a value for missing GET_HASH_PASSWORD"
fi
source $hash
fi
echo -e "${nc}Password ${green}${GET_HASH_PASSWORD}${nc}"
#; Install PHPUnit, performs unit tests
#; The website must pass health checks in order to be deployed
if [ $openshift 2> /dev/null ]; then
phpunit="./app/Vendor/bin/phpunit"
if [ ! -f $phpunit ]; then
source ./Scripts/composer.sh -o phpunit/phpunit cakephp/cakephp-codesniffer
else
echo -e "PHPUnit ${green}[OK]${nc}"
fi
echo `$phpunit --version`
phpunit="./app/Vendor/bin/phpunit"
if [ ! -f $phpunit ]; then
source ./Scripts/composer.sh -o phpunit/phpunit cakephp/cakephp-codesniffer
else
echo -e "PHPUnit ${green}[OK]${nc}"
fi
echo `$phpunit --version`
fi
source ./Scripts/config_app_database.sh
if [ $(parse_arg_exists "server" $*) 2> /dev/null ]; then
Expand All @@ -52,10 +49,10 @@ if [ $(parse_arg_exists "server" $*) 2> /dev/null ]; then
echo -e "Unit tests ${cyan}${url}/test.php${nc}"
echo -e "Turnoff flags (fix captcha)${cyan}${url}/admin/logoff.php${nc}"
echo -e "==============================================="
lib/Cake/Console/cake $*
./lib/Cake/Console/cake $*
else if [ $(parse_arg_exists "test" $*) 2> /dev/null ]; then
show_password_status "$TEST_DATABASE_USER" "$TEST_DATABASE_PASSWORD" "is running tests"
if [[ "$COLLECT_COVERAGE" == "true" ]]; then
if [[ "${COLLECT_COVERAGE}" == "true" ]]; then
./app/Vendor/bin/phpunit --log-junit ~/phpunit/junit.xml --coverage-clover app/build/logs/clover.xml --stop-on-failure -c app/phpunit.xml.dist app/Test/Case/AllTestsTest.php
else
if [ '${PHPCS}' != '1' ]; then
Expand Down
15 changes: 7 additions & 8 deletions Scripts/lib/parsing.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -x
set -e
#; colorize shell script
nc="\033[0m"
red="\033[0;31m"
Expand Down Expand Up @@ -40,16 +40,15 @@ Please, enter the $4 value now:
}
#; export -f parse_arg_export
parse_arg_exists() {
[ $# -lt 2 ] && echo "Usage: $0 <argument-case> list-or-\$*"
arg=$(echo $1 | awk 'BEGIN{FS="\|"; ORS=" "} {for(i=0;i++<NF;) print $i}')
[ $# -lt 2 ] && echo "Usage: $0 <argument-case> list-or-\$*" && exit 1
args=$1
count=$(echo $1 | awk 'BEGIN{FS="\|"} {print NF}')
shift
while [[ "$count" > 1 ]]; do
parse_arg_exists $(echo $arg | cut -f $count -d ' ') $*
let count--; done
[[ "$count" > 1 && "$#" > 0 ]] && parse_arg_exists $(echo $args | cut -f 2- -d '|') $* 2> /dev/null && return
arg=$(echo $args | cut -f 1 -d '|')
while [[ "$#" > 0 ]]; do case $1 in
$arg ) echo $count; break;;
*) ;;
$arg) echo 1; return;;
*) ;;
esac; shift; done
}
#; export -f parse_arg_exists()
Expand Down
1 change: 1 addition & 0 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ else
echo "Provided local/test bootargs..."
source ./Scripts/fooargs.sh $*
fi
if [ -z ${PHP_CMS_DIR} ]; then echo "Please set PHP_CMS_DIR=app/webroot/php_cms pathname environment."; exit 1; fi
saved=("$*")
#; if the full set of the arguments exists, there won't be any prompt in the shell
while [[ "$#" > 0 ]]; do case $1 in
Expand Down
1 change: 1 addition & 0 deletions test-cake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ while [[ "$#" > 0 ]]; do case $1 in
-[tT]*|--test-sql-password*)
parse_sql_password "$1" "TEST_DATABASE_PASSWORD" "test user ${TEST_DATABASE_USER}";;
-[vV]*|--verbose )
set -x
echo "Passed params : $0 ${saved}";;
-[oO]*|--openshift )
config_args="${config_args} --openshift"
Expand Down

0 comments on commit 2405e18

Please sign in to comment.