Skip to content

Commit

Permalink
Automatic build handle (pre-Docker image) (#45)
Browse files Browse the repository at this point in the history
* make image from dockerfile scratch

* # This is a combination of 7 commits.
# This is the 1st commit message:

WIP docker-compose
https://onoblog.com/cakephp2-docker-scratch/

docker-compose --build

prepare env

# This is the commit message #2:

Update site.conf
# This is the commit message #3:

Create docker alias forr docker-compose commadline

# This is the commit message #4:

Docker phpenv version

# The commit message #5 will be skipped:

# version docker-compose

# The commit message #6 will be skipped:

# docker-compose update

# The commit message #7 will be skipped:

# Update install-docker-compose.sh

* WIP docker-compose
https://onoblog.com/cakephp2-docker-scratch/

docker-compose --build

Update site.conf

Create docker alias forr docker-compose commadline

Docker phpenv version

Homebrew composer

Update TravisCI-OSX-PHP

7.0 off <= composer symphony php version mismatch

* composer, which check

* latest hhvm package

* Docker @ CircleCi

* config environment

* php lang 1st container mysql 2nd image in docker

* wip docker test cake

* -v log

* composer configure

* Clients
mariadb
composer configure

* Local Test scripts
Install guidelines
  • Loading branch information
b23prodtm authored Mar 7, 2019
1 parent ff74fbf commit 4801040
Show file tree
Hide file tree
Showing 26 changed files with 920 additions and 133 deletions.
94 changes: 94 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
environment:
DB: Mysql
# a host alias or IP address
MYSQL_SERVICE_HOST: 192.168.99.100
MYSQL_SERVICE_PORT: 3306
TEST_MYSQL_SERVICE_HOST: 192.168.99.100
TEST_MYSQL_SERVICE_PORT: 3306
DATABASE_NAME: phpcms
DATABASE_SERVICE_NAME: MYSQL
#(optional)
#WEBHOOK_URL: <discordapp-url>
# Persistent connection credentials
DATABASE_USER: root
# overrides docker-compose-alias.sh -p=<password>
DATABASE_PASSWORD: pdocker
# Just add TEST_DATABASE_USER and TEST_DATABASE_PASSWORD
TEST_DATABASE_USER: ubuntu
# overrides docker-compose-alias.sh -t=<password>
TEST_DATABASE_PASSWORD: ptest
# CakePHP generated
#CAKEPHP_SECRET_TOKEN: <secret-token>
#CAKEPHP_SECRET_SALT: <secret-salt>
#CAKEPHP_SECURITY_CIPHER_SEED: <cipher-seed>
# Generated by ./configure.sh -h
GET_HASH_PASSWORD: ${GET_HASH_PASSWORD}
docker:
# Specify the version you desire here
- image: circleci/php:7.1-node-browsers
environment:
DOCKER_OS_NAME: linux
DOCKER_PHP_VERSION: 7.1

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# Using the RAM variation mitigates I/O contention
# for database intensive operations.
# - image: circleci/mysql:5.7-ram
- image: circleci/mysql:5.7
container_name: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_ROOT_PASSWORD: 'pdocker'
MYSQL_DATABASE: phpcms

steps:
- checkout
- run: git submodule update --init --recursive

- run: sudo apt update # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev
- run: sudo docker-php-ext-install zip
- run: sudo apt-get install mariadb-client

# 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-

- run: composer install -n --prefer-dist

- save_cache:
key: v1-dependencies-{{ checksum "composer.lock" }}
paths:
- ./app/Vendor/

- run: ./test-cake.sh -v --docker -p=$DATABASE_PASSWORD -t=$TEST_DATABASE_PASSWORD #| grep Test
# Installing and Using docker-compose
- run:
name: Install Docker Compose
command: |
curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
- setup_remote_docker: # (2)
docker_layer_caching: true # (3)

# use a primary image that already has Docker (recommended)
# build and push Docker image
# (4)
- run: |
TAG=0.1.$CIRCLE_BUILD_NUM
./docker-compose-alias.sh -dns=b23prodtm.info -p=$DATABASE_PASSWORD -t=$TEST_DATABASE_PASSWORD up -d --build
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push b23dkr/myphpcms:$TAG
56 changes: 27 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ dist: xenial

env:
matrix:
- DB=Mysql _PHP=hhvm
- DB=Mysql _PHP=7.0 _PKG=php
- DB=Mysql _PHP=7.1 _PKG=php
- DB=Mysql _PHP=7.2 _PKG=php
- DB=Mysql _PHP=7.3 _PKG=php
- DB=Sqlite _PHP=7.0 _PKG=php

- _PHP=latest _PKG=hhvm
- _PHP=7.1 _PKG=php
- _PHP=7.2 _PKG=php
- _PHP=7.3 _PKG=php
global:
- _SSL=openssl
- DB=Mysql
- PHPUNIT=4
- PHPCS=3
- COLLECT_COVERAGE=false
Expand All @@ -33,30 +32,27 @@ env:
matrix:
fast_finish: true
exclude:
- os: osx
env: DB=Mysql _PHP=7.0 _PKG=php
- os: windows
- os: linux
include:
- os: linux
language: php
php: 7.0
env: DB=Mysql _PHP=7.0 _PKG=php PHPENV_ROOT=~/.phpenv
php: 7.1
env: _PHP=7.1 _PKG=php PHPENV_ROOT=~/.phpenv
- os: linux
language: php
php: hhvm
env: DB=Mysql _PHP=hhvm PHPENV_ROOT=~/.phpenv
php: 'hhvm'
env: _PHP=latest _PKG=hhvm PHPENV_ROOT=~/.phpenv
- os: osx
- os: windows
env: DB=Mysql _PHP=7.3 _PKG=php
env: _PHP=7.3 _PKG=php _SSL=openssl.light
- os: windows
env: DB=Mysql _PHP=hhvm
env: _PHP=latest _PKG=hhvm _SSL=openssl.light
allow_failures:
- php: hhvm
- php: 'hhvm'
- env: _PHP=latest _PKG=hhvm
- env: _PHP=7.3 _PKG=php
- os: windows
- os: osx
- env: DB=Mysql _PHP=hhvm
- env: DB=Mysql _PHP=7.3 _PKG=php

addons:
coverity_scan:
Expand All @@ -81,27 +77,29 @@ services:
- memcached

before_install:
- source .travis/TravisCI-OSX-PHP/build/phpenv_install.sh
- source .travis/TravisCI-OSX-PHP/build/prepare_${TRAVIS_OS_NAME}_env.sh #; source exports
- cd .travis/TravisCI-OSX-PHP
- source build/phpenv_install.sh
- source build/prepare_${TRAVIS_OS_NAME}_env.sh #; source exports
- if [[ "${TRAVIS_OS_NAME}" == "linux" && "${_PHP}" == 7* ]]; then COLLECT_COVERAGE=true ; fi
- if [[ "${TRAVIS_OS_NAME}" == "linux" && "${COLLECT_COVERAGE}" != "true" ]]; then phpenv config-rm xdebug.ini || true ; fi
- if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then cd .travis/TravisCI-OSX-PHP; source build/custom_php_ini.sh; cd ../..; php --ini; fi
- if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then source build/custom_php_ini.sh; fi
- if [[ "${TRAVIS_OS_NAME}" == "linux" && "${COLLECT_COVERAGE}" != "true" ]]; then echo -n | openssl s_client -connect https://scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-; fi
- cd ../..
- source ./Scripts/configure_tmp.sh
install:
- if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then .travis/TravisCI-OSX-PHP/build/handle_${TRAVIS_OS_NAME}_pkg.sh "openssl.light"; fi
- if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then .travis/TravisCI-OSX-PHP/build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl"; fi
- if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then .travis/TravisCI-OSX-PHP/build/handle_${TRAVIS_OS_NAME}_pkg.sh "composer"; fi
- if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then bash -c 'composer install --dev --no-interaction'; fi
- cd .travis/TravisCI-OSX-PHP
- if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_SSL}"; /usr/local/opt/openssl/bin/c_rehash; fi
- if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl"; fi
- if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "composer"; bash -c 'composer install --dev --no-interaction'; fi
- cd ../..
- if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then curl -s http://getcomposer.org/installer | php && php composer.phar install --dev --no-interaction; fi

before_script:
- if [[ "${TRAVIS_OS_NAME}" == "linux" && "${_PHP}" == "hhvm" ]]; then curl -sSfL -o ~/.phpenv/versions/hhvm/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar; fi
- mkdir -p build/logs
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ./configure.sh "-c" "-h" "-p" "pass" "-s" "word" "--mig-database" "-y"; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then .travis/configure.sh; fi

script:
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ./test-cake.sh | grep Test; fi
- if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then ./test-cake.sh --travis | grep Test; fi
after_script:
- if [[ ("${COLLECT_COVERAGE}" == "true") && ("${COVERITY_SCAN_BRANCH}" != 1) ]];
then travis_retry php app/vendor/bin/php-coveralls -v -r ./app/; fi
Expand Down
2 changes: 1 addition & 1 deletion .travis/TravisCI-OSX-PHP
1 change: 0 additions & 1 deletion .travis/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ optional environment VARIABLES in .travis.yml
==========================
";
[ ! -z $TEST_DATABASE_USER ] && [ ! -z $TEST_DATABASE_PASSWORD ] && [[ (! -z $TEST_MYSQL_SERVICE_HOST) || (! -z $TEST_PGSQL_SERVICE_HOST) ]] || echo "Missing VARIABLES. Please review your settings !"
php bin/composer.phar install --no-interaction
if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then /usr/bin/env bash .travis/TravisCI-OSX-PHP/build/custom_php_ini.sh; fi
mkdir -p build/logs
echo -e "Database Unit Tests... DB=${DB}"
Expand Down
42 changes: 42 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM php:7.0-apache

RUN apt-get update -yqq \
&& apt-get install -yqq --no-install-recommends \
git \
zip \
unzip \
&& rm -rf /var/lib/apt/lists

# Enable PHP extensions
RUN docker-php-ext-install pdo_mysql mysqli

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer

# Add cake and composer command to system path
ENV PATH="${PATH}:/var/www/html/lib/Cake/Console"
ENV PATH="${PATH}:/var/www/html/app/Vendor/bin"

# COPY apache site.conf file
COPY docker/apache/site.conf /etc/apache2/sites-available/000-default.conf

# Copy the source code into /var/www/html/ inside the image
COPY . /var/www/html/

# Set default working directory
WORKDIR /var/www/html/app

# Create tmp directory and make it writable by the web server
RUN mkdir -p \
tmp/cache/models \
tmp/cache/persistent \
&& chown -R :www-data \
tmp \
&& chmod -R 770 \
tmp

# Enable Apache modules and restart
RUN a2enmod rewrite \
&& service apache2 restart

EXPOSE 80
58 changes: 58 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# INSTALLATION
Docker :whale: is able to use web server containers in local (VM/Vbox) or remote (Cloud) machine cluster (Kubernetes).
A typical install script could look like the following script, for instance edit a file :

#!/usr/bin/env bash

cd myphpcms
git pull
git submodule update --init --recursive
./docker-compose-alias.sh -dns=domain.com -S -p=sqlrootpassword -t=testpassword -v $*
cd ..

If you saved the file as _startup.sh_ In bash follows : ```startup.sh --build -d up``` You can add more docker-compose parameters as arguments.
Docker builds up a new container and pushes it in registry.
It will eventually run the container as the startup script succeeds.

## Circle CI, Docker Local testing
The current project is a full php with mariadb container for the Docker Virtual Machine (VM) manager, or Docker-CE, or even a ```Dockerfile``` compatible container interface. We choose Circle CI because it's able to achieve full remote tests with docker :whale: before we deploy to a Cloud Provider, Kubernetes Cluster, OpenShift, etc.

A local test may only run with a complete local Virtual Host (Vbox) configuration. See the requirements below.

### Simple Docker compose tests
To use the built-in CakePHP 2 interface to test with Docker Compose YAML run the test script as follows :

test-cake.sh --docker

### Requirements
- Broadband Internet access to the Worldwide Web, to download the packages and container images dependencies from the remote Docker registries.
- The [VBoxmanager](https://www.virtualbox.org/wiki/Downloads) package.
- The Docker VM described with the Dockerfile. >:whale: [Get Started](https://docs.docker.com/machine/get-started/) application.
- The docker:docker user SSH remote access enabled (Ask the system administrator to enable Remote Session Accounts with Password authentification in /etc/ssh/sshd_config)
- The CircleCI Client installed in ```$PATH```. [CLI Configuration](https://circleci.com/docs/2.0/local-cli/#section=configuration) shell command line :

curl -fLSs https://circle.ci/cli | bash

Once everything is installed, please reboot your system.

### Make local tests with CircleCI CLI
- Enable Docker VM on your system (a virtual Host is instancied)
- Shell command line : ```circleci local execute```

### Startup
Everyting is ready to launch a container in real cluster environment. The process is described further. [Kubespray with Ansible and Kubernetes cluster](https://github.com/b23prodtm/kubesrpay).

### License
Copyright 2016 www.b23prodtm.info

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading

0 comments on commit 4801040

Please sign in to comment.