From 635c3016e37f5785667a6a15d5649a72ca8a7e6b Mon Sep 17 00:00:00 2001
From: Matt Trefilek <matthew.trefilek@wisc.edu>
Date: Mon, 5 Feb 2018 13:19:26 -0600
Subject: [PATCH] NETID-238 Dockerize PHP NetID RPC

Added in a DOCKERFILE and a docker-compose.yml which create environments to run unit and integration tests without any prerequisites (aside from docker) installed. Added a release script to release to the remote repository and an environment file to keep track of version locally.
---
 .env                 |  3 +++
 DOCKERFILE           |  6 ++++++
 README.md            | 37 +++++++------------------------------
 RELEASE.md           | 11 +++++++----
 Vagrantfile          | 22 ----------------------
 docker-compose.yml   | 15 +++++++++++++++
 manifests/default.pp | 22 ----------------------
 release.sh           | 13 +++++++++++++
 8 files changed, 51 insertions(+), 78 deletions(-)
 create mode 100644 .env
 create mode 100644 DOCKERFILE
 delete mode 100644 Vagrantfile
 create mode 100644 docker-compose.yml
 delete mode 100644 manifests/default.pp
 create mode 100755 release.sh

diff --git a/.env b/.env
new file mode 100644
index 0000000..b4c0a47
--- /dev/null
+++ b/.env
@@ -0,0 +1,3 @@
+VERSION=2.3.1
+BRANCH=master
+REMOTE=upstream
\ No newline at end of file
diff --git a/DOCKERFILE b/DOCKERFILE
new file mode 100644
index 0000000..7de4fc6
--- /dev/null
+++ b/DOCKERFILE
@@ -0,0 +1,6 @@
+FROM ubuntu:latest
+
+RUN apt-get update && apt-get install php7.0 php7.0-xml php7.0-soap wget git -y
+RUN wget http://pear.php.net/go-pear.phar && php go-pear.phar && pear install VersionControl_Git-alpha
+
+ADD . /code
\ No newline at end of file
diff --git a/README.md b/README.md
index 0ec9fd8..ab44acd 100644
--- a/README.md
+++ b/README.md
@@ -90,42 +90,25 @@ You will need to run `phpdoc` at the root of the project in order to generate th
 
 ## Development Requirements
 
-1. [phing](http://www.phing.info/)
+1. docker [Installation](https://docs.docker.com/install/)
+2. docker-compose [Installation](https://docs.docker.com/compose/install/)
 
 ## Developer Setup
 
-### Vagrant
+### Building the Docker Image
 
-A vagrant file has been created for your convenience. This will install a Vagrant development virutal box with all the necessary build tools. Simply run at the project root:
+If this is your first time running the PHP client or after any changes to the DOCKERFILE, run at the root of the project:
 
-```bash
-vagrant up
 ```
-
-### Building
-
-At the root of the project, run the following command:
-
-```bash
-php phing.phar
+docker-compose build
 ```
 
-This will retrieve dependencies and run PHPUnit.
-
-**Note:** If you are not using Vagrant, you will need to [obtain Phing](https://www.phing.info/trac/wiki/Users/Installation). (I recommend downloading the Phar file to stay consistent with this documentation.)
-
 ## Testing
 
 PHPUnit tests are located in `src/test`. To run the tests, at the root of the project, enter:
 
 ```bash
-php phpunit.phar
-```
-
-or:
-
-```bash
-php phing.phar test
+docker-compose run --rm test
 ```
 
 ## Integration Testing
@@ -133,13 +116,7 @@ php phing.phar test
 Integration with the MST NetID web service can be tested by running:
 
 ```bash
-php phpunit.phar --configuration phpunit-it.xml
-```
-
-or:
-
-```bash
-php phing.phar integration-test
+docker-compose run --rm integration-test
 ```
 
 A valid client certificate is required to authenticate with Middleware's web service. Test data must be supplied in `src/test/resources/integration-test-data.ini`. 
diff --git a/RELEASE.md b/RELEASE.md
index de173b1..71309de 100644
--- a/RELEASE.md
+++ b/RELEASE.md
@@ -1,9 +1,12 @@
 # Release Process #
 
 1. User has cloned the [primary repository](https://git.doit.wisc.edu/adi-ia/rpc-netid-php/) and has write access to it.
-2. User runs the following command: `php phing.phar release -Dversion=1.2.3 [-Dbranch=some-alternate-branch]` The branch argument is optional and defaults to `master`.
-3. The designated branch is checked out.
-4. A tag is created with the name equal to the version number with no extra characters
-5. The repository is pushed to origin with all tags. 
+2. User has run `chmod +x release.sh`
+3. User has modified the version variable in the **.env** file. If a different branch is to be released, that is also specified
+in the .env file.
+4. User runs the following command: `./release.sh`
+5. The designated branch is checked out.
+6. A tag is created with the name equal to the version number with no extra characters
+7. The repository is pushed to origin with all tags. 
 
 The end result is a new tag in the remote repository equal to the version number. Composer clients will now pick up on the new version number.
diff --git a/Vagrantfile b/Vagrantfile
deleted file mode 100644
index cb0fc89..0000000
--- a/Vagrantfile
+++ /dev/null
@@ -1,22 +0,0 @@
-# -*- mode: ruby -*-
-# vi: set ft=ruby :
-
-VAGRANTFILE_API_VERSION = "2"
-
-Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
-
-  config.vm.box = "ubuntu/trusty64"
-  config.vm.hostname = "rpc-netid-php-dev"
-  
-  config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
-  
-  config.vm.provision "shell", inline: "apt-get update" 
-
-  config.vm.provision "puppet" do |puppet|
-  end
-  
-  config.vm.provider "virtualbox" do |v|
-    v.memory=1024
-  end
-  
-end
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..3ecb66d
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,15 @@
+test:
+  build: .
+  command: bash -c "cd /code && wget -O phing.phar http://www.phing.info/get/phing-2.15.2.phar && php phing.phar test"
+  ports:
+    - "8000:8000"
+  volumes:
+    - .:/code
+
+integration-test:
+  build: .
+  command: bash -c "cd /code && wget -O phing.phar http://www.phing.info/get/phing-2.15.2.phar && php phing.phar integration-test"
+  ports:
+    - "8000:8000"
+  volumes:
+    - .:/code
\ No newline at end of file
diff --git a/manifests/default.pp b/manifests/default.pp
deleted file mode 100644
index 66e3731..0000000
--- a/manifests/default.pp
+++ /dev/null
@@ -1,22 +0,0 @@
-# Set path globally
-
-Exec {
-	path => [ "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin" ],
-}
-
-# Install phpunit
-package { 'phpunit':
-	ensure => installed,
-}
-
-# Install XDebug
-package { 'php5-xdebug':
-	ensure => installed,
-}
-
-# Download phing
-exec { 'download-phing':
-	cwd => '/vagrant',
-	command => 'wget http://www.phing.info/get/phing-latest.phar -O phing.phar',
-	creates => '/vagrant/phing.phar'
-}
diff --git a/release.sh b/release.sh
new file mode 100755
index 0000000..3b091ca
--- /dev/null
+++ b/release.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+source ./.env
+
+echo "Releasing version "$VERSION", the current state of branch "$BRANCH" on upstream"
+echo Checking out branch $BRANCH...
+git checkout $REMOTE/$BRANCH
+echo Creating tag $VERSION...
+git tag $VERSION
+echo Pushing to remote $REMOTE...
+git push $REMOTE $VERSION
+
+
+
-- 
GitLab