From 2d0ffca1d598f8428ff70ff7e2e8099a6eb008ee Mon Sep 17 00:00:00 2001
From: Alan Nelson <alan.nelson@nebraska.edu>
Date: Thu, 6 Sep 2018 14:33:53 -0500
Subject: [PATCH] Initial commit of PHP and Magento2 containers

---
 .gitattributes                                |  1 +
 Makefile                                      | 47 +++++++++++++
 README.md                                     |  4 +-
 magento2-unit-test/latest/Dockerfile          | 39 +++++++++++
 magento2-unit-test/latest/php.ini             |  5 ++
 magento2-unit-test/latest/set-mg2-credentials | 18 +++++
 php-lint/5.6/Dockerfile                       |  9 +++
 php-lint/5.6/docker-entrypoint                |  8 +++
 php-lint/5.6/php-lint                         | 66 +++++++++++++++++++
 php-lint/7.0/Dockerfile                       |  9 +++
 php-lint/7.0/docker-entrypoint                |  8 +++
 php-lint/7.0/php-lint                         | 66 +++++++++++++++++++
 php-lint/7.1/Dockerfile                       |  9 +++
 php-lint/7.1/docker-entrypoint                |  8 +++
 php-lint/7.1/php-lint                         | 66 +++++++++++++++++++
 php-lint/7.2/Dockerfile                       |  9 +++
 php-lint/7.2/docker-entrypoint                |  8 +++
 php-lint/7.2/php-lint                         | 66 +++++++++++++++++++
 18 files changed, 445 insertions(+), 1 deletion(-)
 create mode 100644 .gitattributes
 create mode 100644 Makefile
 create mode 100644 magento2-unit-test/latest/Dockerfile
 create mode 100644 magento2-unit-test/latest/php.ini
 create mode 100644 magento2-unit-test/latest/set-mg2-credentials
 create mode 100644 php-lint/5.6/Dockerfile
 create mode 100644 php-lint/5.6/docker-entrypoint
 create mode 100644 php-lint/5.6/php-lint
 create mode 100644 php-lint/7.0/Dockerfile
 create mode 100644 php-lint/7.0/docker-entrypoint
 create mode 100644 php-lint/7.0/php-lint
 create mode 100644 php-lint/7.1/Dockerfile
 create mode 100644 php-lint/7.1/docker-entrypoint
 create mode 100644 php-lint/7.1/php-lint
 create mode 100644 php-lint/7.2/Dockerfile
 create mode 100644 php-lint/7.2/docker-entrypoint
 create mode 100644 php-lint/7.2/php-lint

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..6313b56
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto eol=lf
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2f8805e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,47 @@
+######################################
+#    Build File for Docker Images    #
+######################################
+
+.PHONY: magento2-unit-test
+
+all: \
+	php-lint_5.6 \
+	php-lint_7.0 \
+	php-lint_7.1 \
+	php-lint_7.2 \
+	php-lint_latest \
+	magento2-unit-test
+
+# PHP Images
+####################
+php-lint_5.6:
+	docker build -t unl-its/php-lint:5.6 php-lint/5.6
+
+php-lint_7.0:
+	docker build -t unl-its/php-lint:7.0 php-lint/7.0
+
+php-lint_7.1:
+	docker build -t unl-its/php-lint:7.1 php-lint/7.1
+
+php-lint_7.2:
+	docker build -t unl-its/php-lint:7.2 php-lint/7.2
+
+php-lint_latest: php-lint_7.2
+	docker tag unl-its/php-lint:7.2 unl-its/php-lint:latest
+
+
+# Application Images
+####################
+magento2-unit-test:
+	docker build -t unl-its/magento2-unit-test:latest magento2-unit-test/latest
+
+
+# Cleanup
+####################
+clean:
+	docker image rm unl-its/php-lint:5.6; true
+	docker image rm unl-its/php-lint:7.0; true
+	docker image rm unl-its/php-lint:7.1; true
+	docker image rm unl-its/php-lint:7.2; true
+	docker image rm unl-its/php-lint:latest; true
+	docker image rm unl-its/magento2-unit-test:latest; true
diff --git a/README.md b/README.md
index 9415342..995a52e 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
 # docker-ci
+Containers used on CI
 
-Containers used on CI
\ No newline at end of file
+## Building Images
+To build these images, clone this repository onto a machine with docker and make installed. Run `make` and all of the images will be built and installed as local docker images.
diff --git a/magento2-unit-test/latest/Dockerfile b/magento2-unit-test/latest/Dockerfile
new file mode 100644
index 0000000..acee521
--- /dev/null
+++ b/magento2-unit-test/latest/Dockerfile
@@ -0,0 +1,39 @@
+FROM centos:7
+
+# Add additional REPOs
+RUN rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
+  && rpm -i https://rhel7.iuscommunity.org/ius-release.rpm
+
+# Update system and install required packages
+RUN yum update -y \
+  && yum install -y \
+  unzip \
+  php71u-cli \
+  php71u-json \
+  php71u-pdo \
+  php71u-mysqlnd \
+  php71u-opcache \
+  php71u-xml \
+  php71u-mcrypt \
+  php71u-gd \
+  php71u-devel \
+  php71u-intl \
+  php71u-mbstring \
+  php71u-bcmath \
+  php71u-json \
+  php71u-soap \
+  && yum clean all \
+  && rm -rf /var/cache/yum
+
+# Install composer
+RUN curl -o /usr/local/bin/composer https://getcomposer.org/composer.phar \
+  && chmod 755 /usr/local/bin/composer
+
+# PHP Config file
+COPY php.ini /etc/php.d/mg2.ini
+
+# Custom Scrips
+COPY set-mg2-credentials /usr/local/bin/set-mg2-credentials
+RUN chmod 755 /usr/local/bin/set-mg2-credentials
+
+CMD ["bash"]
diff --git a/magento2-unit-test/latest/php.ini b/magento2-unit-test/latest/php.ini
new file mode 100644
index 0000000..c8a7ade
--- /dev/null
+++ b/magento2-unit-test/latest/php.ini
@@ -0,0 +1,5 @@
+memory_limit = 2G
+
+session.auto_start = off;
+
+date.timezone="America/Chicago"
diff --git a/magento2-unit-test/latest/set-mg2-credentials b/magento2-unit-test/latest/set-mg2-credentials
new file mode 100644
index 0000000..1431c53
--- /dev/null
+++ b/magento2-unit-test/latest/set-mg2-credentials
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+if [[ "$#" -ne 2 ]]; then
+  echo "Please provide both the username and password"
+  exit 1
+fi
+
+mkdir -p /root/.composer
+cat > /root/.composer/auth.json <<EOF
+{
+    "http-basic": {
+        "repo.magento.com": {
+            "username": "$1",
+            "password": "$2"
+        }
+    }
+}
+EOF
diff --git a/php-lint/5.6/Dockerfile b/php-lint/5.6/Dockerfile
new file mode 100644
index 0000000..4bdddf4
--- /dev/null
+++ b/php-lint/5.6/Dockerfile
@@ -0,0 +1,9 @@
+FROM php:5.6-alpine
+
+RUN apk add --no-cache bash
+
+COPY php-lint docker-entrypoint /usr/local/bin/
+RUN chmod 755 /usr/local/bin/docker-entrypoint /usr/local/bin/php-lint
+
+ENTRYPOINT ["docker-entrypoint"]
+CMD ["--help"]
diff --git a/php-lint/5.6/docker-entrypoint b/php-lint/5.6/docker-entrypoint
new file mode 100644
index 0000000..131b834
--- /dev/null
+++ b/php-lint/5.6/docker-entrypoint
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+if [ "${1#-}" != "$1" ]; then
+	set -- php-lint "$@"
+fi
+
+exec "$@"
diff --git a/php-lint/5.6/php-lint b/php-lint/5.6/php-lint
new file mode 100644
index 0000000..afb52f2
--- /dev/null
+++ b/php-lint/5.6/php-lint
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Read CLI options
+LINT_DIRS=()
+LINT_EXTS=()
+QUIET=false
+while [[ $# -gt 0 ]]; do
+  case $1 in
+    -e|--ext)
+      LINT_EXTS+=("$2")
+      shift
+      shift
+      ;;
+    -d|--dir)
+      LINT_DIRS+=("$2")
+      shift
+      shift
+      ;;
+    -q|--quiet)
+      QUIET=true
+      shift
+      ;;
+    -h|--help)
+    	printf 'Usage: %s <options>\n' "$0"
+    	printf '\t%s\n' "-e,--ext: Required argument: extensions to lint"
+    	printf '\t%s\n' "-d,--dir: Required argument: directories to lint"
+    	printf '\t%s\n' "-q,--quiet: Optional argument: Quiet mode, only print errors"
+    	printf '\t%s\n' "-h,--help: Prints this help message"
+      exit 0
+      ;;
+    *)
+      echo "Unrecognized option ${1}"
+      shift
+      ;;
+  esac
+done
+
+# If no dirs were provided, use CWD
+if [[ -z "$LINT_DIRS" ]]; then
+  LINT_DIRS=($(pwd))
+fi
+
+# If no extenions were provided, use reasonable defaults
+if [[ -z "$LINT_EXTS" ]]; then
+  LINT_EXTS=(".php" ".phtml")
+fi
+
+# Run PHP Lint on all provided files and directories
+for dir in "${LINT_DIRS[@]}"; do
+  for ext in "${LINT_EXTS[@]}"; do
+    echo "Scanning directory ${dir} for extension ${ext}"
+
+    # Scan current dir and ext and lint them
+    for f in $(find "${dir}" -type f -name "*${ext}"); do
+      OUTPUT=$(php -l $f 2>&1)
+      rc=$?
+
+      if [[ $rc != 0 ]]; then # Non-zero exit code, print error and exit
+        >&2 echo "$OUTPUT"
+        exit $rc
+      elif [[ $rc == 0 ]] && [[ $QUIET == false ]]; then # all ok
+        echo "$OUTPUT"
+      fi
+    done
+  done
+done
diff --git a/php-lint/7.0/Dockerfile b/php-lint/7.0/Dockerfile
new file mode 100644
index 0000000..c14b10d
--- /dev/null
+++ b/php-lint/7.0/Dockerfile
@@ -0,0 +1,9 @@
+FROM php:7.0-alpine
+
+RUN apk add --no-cache bash
+
+COPY php-lint docker-entrypoint /usr/local/bin/
+RUN chmod 755 /usr/local/bin/docker-entrypoint /usr/local/bin/php-lint
+
+ENTRYPOINT ["docker-entrypoint"]
+CMD ["--help"]
diff --git a/php-lint/7.0/docker-entrypoint b/php-lint/7.0/docker-entrypoint
new file mode 100644
index 0000000..131b834
--- /dev/null
+++ b/php-lint/7.0/docker-entrypoint
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+if [ "${1#-}" != "$1" ]; then
+	set -- php-lint "$@"
+fi
+
+exec "$@"
diff --git a/php-lint/7.0/php-lint b/php-lint/7.0/php-lint
new file mode 100644
index 0000000..afb52f2
--- /dev/null
+++ b/php-lint/7.0/php-lint
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Read CLI options
+LINT_DIRS=()
+LINT_EXTS=()
+QUIET=false
+while [[ $# -gt 0 ]]; do
+  case $1 in
+    -e|--ext)
+      LINT_EXTS+=("$2")
+      shift
+      shift
+      ;;
+    -d|--dir)
+      LINT_DIRS+=("$2")
+      shift
+      shift
+      ;;
+    -q|--quiet)
+      QUIET=true
+      shift
+      ;;
+    -h|--help)
+    	printf 'Usage: %s <options>\n' "$0"
+    	printf '\t%s\n' "-e,--ext: Required argument: extensions to lint"
+    	printf '\t%s\n' "-d,--dir: Required argument: directories to lint"
+    	printf '\t%s\n' "-q,--quiet: Optional argument: Quiet mode, only print errors"
+    	printf '\t%s\n' "-h,--help: Prints this help message"
+      exit 0
+      ;;
+    *)
+      echo "Unrecognized option ${1}"
+      shift
+      ;;
+  esac
+done
+
+# If no dirs were provided, use CWD
+if [[ -z "$LINT_DIRS" ]]; then
+  LINT_DIRS=($(pwd))
+fi
+
+# If no extenions were provided, use reasonable defaults
+if [[ -z "$LINT_EXTS" ]]; then
+  LINT_EXTS=(".php" ".phtml")
+fi
+
+# Run PHP Lint on all provided files and directories
+for dir in "${LINT_DIRS[@]}"; do
+  for ext in "${LINT_EXTS[@]}"; do
+    echo "Scanning directory ${dir} for extension ${ext}"
+
+    # Scan current dir and ext and lint them
+    for f in $(find "${dir}" -type f -name "*${ext}"); do
+      OUTPUT=$(php -l $f 2>&1)
+      rc=$?
+
+      if [[ $rc != 0 ]]; then # Non-zero exit code, print error and exit
+        >&2 echo "$OUTPUT"
+        exit $rc
+      elif [[ $rc == 0 ]] && [[ $QUIET == false ]]; then # all ok
+        echo "$OUTPUT"
+      fi
+    done
+  done
+done
diff --git a/php-lint/7.1/Dockerfile b/php-lint/7.1/Dockerfile
new file mode 100644
index 0000000..2942326
--- /dev/null
+++ b/php-lint/7.1/Dockerfile
@@ -0,0 +1,9 @@
+FROM php:7.1-alpine
+
+RUN apk add --no-cache bash
+
+COPY php-lint docker-entrypoint /usr/local/bin/
+RUN chmod 755 /usr/local/bin/docker-entrypoint /usr/local/bin/php-lint
+
+ENTRYPOINT ["docker-entrypoint"]
+CMD ["--help"]
diff --git a/php-lint/7.1/docker-entrypoint b/php-lint/7.1/docker-entrypoint
new file mode 100644
index 0000000..131b834
--- /dev/null
+++ b/php-lint/7.1/docker-entrypoint
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+if [ "${1#-}" != "$1" ]; then
+	set -- php-lint "$@"
+fi
+
+exec "$@"
diff --git a/php-lint/7.1/php-lint b/php-lint/7.1/php-lint
new file mode 100644
index 0000000..afb52f2
--- /dev/null
+++ b/php-lint/7.1/php-lint
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Read CLI options
+LINT_DIRS=()
+LINT_EXTS=()
+QUIET=false
+while [[ $# -gt 0 ]]; do
+  case $1 in
+    -e|--ext)
+      LINT_EXTS+=("$2")
+      shift
+      shift
+      ;;
+    -d|--dir)
+      LINT_DIRS+=("$2")
+      shift
+      shift
+      ;;
+    -q|--quiet)
+      QUIET=true
+      shift
+      ;;
+    -h|--help)
+    	printf 'Usage: %s <options>\n' "$0"
+    	printf '\t%s\n' "-e,--ext: Required argument: extensions to lint"
+    	printf '\t%s\n' "-d,--dir: Required argument: directories to lint"
+    	printf '\t%s\n' "-q,--quiet: Optional argument: Quiet mode, only print errors"
+    	printf '\t%s\n' "-h,--help: Prints this help message"
+      exit 0
+      ;;
+    *)
+      echo "Unrecognized option ${1}"
+      shift
+      ;;
+  esac
+done
+
+# If no dirs were provided, use CWD
+if [[ -z "$LINT_DIRS" ]]; then
+  LINT_DIRS=($(pwd))
+fi
+
+# If no extenions were provided, use reasonable defaults
+if [[ -z "$LINT_EXTS" ]]; then
+  LINT_EXTS=(".php" ".phtml")
+fi
+
+# Run PHP Lint on all provided files and directories
+for dir in "${LINT_DIRS[@]}"; do
+  for ext in "${LINT_EXTS[@]}"; do
+    echo "Scanning directory ${dir} for extension ${ext}"
+
+    # Scan current dir and ext and lint them
+    for f in $(find "${dir}" -type f -name "*${ext}"); do
+      OUTPUT=$(php -l $f 2>&1)
+      rc=$?
+
+      if [[ $rc != 0 ]]; then # Non-zero exit code, print error and exit
+        >&2 echo "$OUTPUT"
+        exit $rc
+      elif [[ $rc == 0 ]] && [[ $QUIET == false ]]; then # all ok
+        echo "$OUTPUT"
+      fi
+    done
+  done
+done
diff --git a/php-lint/7.2/Dockerfile b/php-lint/7.2/Dockerfile
new file mode 100644
index 0000000..90e9800
--- /dev/null
+++ b/php-lint/7.2/Dockerfile
@@ -0,0 +1,9 @@
+FROM php:7.2-alpine
+
+RUN apk add --no-cache bash
+
+COPY php-lint docker-entrypoint /usr/local/bin/
+RUN chmod 755 /usr/local/bin/docker-entrypoint /usr/local/bin/php-lint
+
+ENTRYPOINT ["docker-entrypoint"]
+CMD ["--help"]
diff --git a/php-lint/7.2/docker-entrypoint b/php-lint/7.2/docker-entrypoint
new file mode 100644
index 0000000..131b834
--- /dev/null
+++ b/php-lint/7.2/docker-entrypoint
@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+if [ "${1#-}" != "$1" ]; then
+	set -- php-lint "$@"
+fi
+
+exec "$@"
diff --git a/php-lint/7.2/php-lint b/php-lint/7.2/php-lint
new file mode 100644
index 0000000..afb52f2
--- /dev/null
+++ b/php-lint/7.2/php-lint
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Read CLI options
+LINT_DIRS=()
+LINT_EXTS=()
+QUIET=false
+while [[ $# -gt 0 ]]; do
+  case $1 in
+    -e|--ext)
+      LINT_EXTS+=("$2")
+      shift
+      shift
+      ;;
+    -d|--dir)
+      LINT_DIRS+=("$2")
+      shift
+      shift
+      ;;
+    -q|--quiet)
+      QUIET=true
+      shift
+      ;;
+    -h|--help)
+    	printf 'Usage: %s <options>\n' "$0"
+    	printf '\t%s\n' "-e,--ext: Required argument: extensions to lint"
+    	printf '\t%s\n' "-d,--dir: Required argument: directories to lint"
+    	printf '\t%s\n' "-q,--quiet: Optional argument: Quiet mode, only print errors"
+    	printf '\t%s\n' "-h,--help: Prints this help message"
+      exit 0
+      ;;
+    *)
+      echo "Unrecognized option ${1}"
+      shift
+      ;;
+  esac
+done
+
+# If no dirs were provided, use CWD
+if [[ -z "$LINT_DIRS" ]]; then
+  LINT_DIRS=($(pwd))
+fi
+
+# If no extenions were provided, use reasonable defaults
+if [[ -z "$LINT_EXTS" ]]; then
+  LINT_EXTS=(".php" ".phtml")
+fi
+
+# Run PHP Lint on all provided files and directories
+for dir in "${LINT_DIRS[@]}"; do
+  for ext in "${LINT_EXTS[@]}"; do
+    echo "Scanning directory ${dir} for extension ${ext}"
+
+    # Scan current dir and ext and lint them
+    for f in $(find "${dir}" -type f -name "*${ext}"); do
+      OUTPUT=$(php -l $f 2>&1)
+      rc=$?
+
+      if [[ $rc != 0 ]]; then # Non-zero exit code, print error and exit
+        >&2 echo "$OUTPUT"
+        exit $rc
+      elif [[ $rc == 0 ]] && [[ $QUIET == false ]]; then # all ok
+        echo "$OUTPUT"
+      fi
+    done
+  done
+done
-- 
GitLab