From ba94c5afee5e61a1a648ea515a22b1d33f4cd3eb Mon Sep 17 00:00:00 2001
From: Chris Galusha <chrisgalusha@nebraska.edu>
Date: Mon, 2 Oct 2023 15:21:22 -0500
Subject: [PATCH] Laravel dusk

---
 .gitlab/ci/build.yml                          | 14 ++++++++++++
 .gitlab/ci/publish.yml                        | 14 ++++++++++++
 Makefile                                      | 11 +++++++++-
 php-browser-test/8.2/Dockerfile               | 22 +++++++++++++++++++
 .../8.2/browser-test-entrypoint.sh            |  6 +++++
 php-unit-test/8.2/Dockerfile                  |  2 +-
 6 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 php-browser-test/8.2/Dockerfile
 create mode 100644 php-browser-test/8.2/browser-test-entrypoint.sh

diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml
index 1700c48..743faad 100644
--- a/.gitlab/ci/build.yml
+++ b/.gitlab/ci/build.yml
@@ -26,6 +26,20 @@ Make PHP Unit Test:
   except:
     - schedules
 
+Make PHP Browser Test:
+  stage: build
+  tags:
+    - linux
+    - dockerd
+  script:
+    - make php-browser-test
+  only:
+    changes:
+      - php-browser-test/*
+      - php-browser-test/**/*
+  except:
+    - schedules
+
 Make Android Build:
   stage: build
   tags:
diff --git a/.gitlab/ci/publish.yml b/.gitlab/ci/publish.yml
index c03e3b0..e1d33fa 100644
--- a/.gitlab/ci/publish.yml
+++ b/.gitlab/ci/publish.yml
@@ -40,6 +40,20 @@ Publish PHP Unit Test:
   except:
     - schedules
 
+Publish PHP Browser Test:
+  <<: *push_to_registry
+  variables:
+    IMG_NAME: "php-browser-test"
+  needs: ["Make PHP Browser Test"]
+  only:
+    refs:
+      - master
+    changes:
+      - php-browser-test/*
+      - php-browser-test/**/*
+  except:
+    - schedules
+
 Publish Android Build:
   <<: *push_to_registry
   variables:
diff --git a/Makefile b/Makefile
index 7083d5a..427c5d9 100644
--- a/Makefile
+++ b/Makefile
@@ -20,12 +20,13 @@ BUILD_ARGS := --build-arg VCS_REF=$(GIT_COMMIT)
 
 .PHONY: all clean test $(DOCKERFILES) static-code-analysis mobile delete_dangling_images security publish utility dotnet
 
-all: php-lint php-unit-test mobile static-code-analysis utility detect-secrets dependency-check xml-lint
+all: php-lint php-unit-test php-browser-test mobile static-code-analysis utility detect-secrets dependency-check xml-lint
 
 # Image Groups
 ####################
 php-lint: php-lint_5.6 php-lint_7.0 php-lint_7.1 php-lint_7.2 php-lint_7.3 php-lint_7.4 php-lint_8.0 php-lint_8.1 php-lint_8.2 php-lint_latest
 php-unit-test: php-unit-test_5.6 php-unit-test_7.0 php-unit-test_7.1 php-unit-test_7.2 php-unit-test_7.3 php-unit-test_7.4 php-unit-test_8.0 php-unit-test_8.1 php-unit-test_8.2 php-unit-test_latest
+php-browser-test: php-browser-test_8.2 php-browser-test_latest
 mobile: android-build-server
 static-code-analysis: static-code-analysis_latest static-code-analysys_php static-code-analysys_python static-code-analysys_android
 utility: alpine-ssh-client merge-request-check
@@ -95,6 +96,14 @@ php-unit-test_8.2: php-unit-test/8.2/Dockerfile
 php-unit-test_latest: php-unit-test_8.2
 	docker tag ${REPO_ORG}/php-unit-test:8.2 ${REPO_ORG}/php-unit-test:latest
 
+# PHP Unit Test Images
+####################
+php-browser-test_8.2: php-browser-test/8.2/Dockerfile
+	docker build $(BUILD_ARGS) -t ${REPO_ORG}/php-browser-test:8.2 -f php-browser-test/8.2/Dockerfile php-browser-test/8.2
+
+php-browser-test_latest: php-browser-test_8.2
+	docker tag ${REPO_ORG}/php-browser-test:8.2 ${REPO_ORG}/php-browser-test:latest
+
 # Mobile Applications
 ####################
 android-build-server: android-build-server/Dockerfile
diff --git a/php-browser-test/8.2/Dockerfile b/php-browser-test/8.2/Dockerfile
new file mode 100644
index 0000000..14ebb95
--- /dev/null
+++ b/php-browser-test/8.2/Dockerfile
@@ -0,0 +1,22 @@
+FROM its-registry.unl.edu/unl-its/docker-ci/php-unit-test:8.2
+
+ARG BUILD_DATE
+ARG VCS_REF
+ARG VERSION
+LABEL org.label-schema.build-date=$BUILD_DATE \
+      org.label-schema.name="PHP 8.2 Browser Tester" \
+      org.label-schema.description="Perform chromedriver browser tests in PHP (Ex. Laravel Dusk)" \
+      org.label-schema.vcs-ref=$VCS_REF \
+      org.label-schema.vendor="University of Nebraska - Lincoln" \
+      org.label-schema.version=$VERSION \
+      org.label-schema.schema-version="1.0" \
+      maintainer="Alan Nelson <alan.nelson@nebraska.edu>"
+
+RUN apk add --no-cache chromium-chromedriver
+
+COPY ./browser-test-entrypoint.sh /usr/local/bin/browser-test-entrypoint
+RUN chown root:root /usr/local/bin/browser-test-entrypoint \
+  && chmod 755 /usr/local/bin/browser-test-entrypoint
+
+ENTRYPOINT ["/usr/local/bin/browser-test-entrypoint"]
+CMD ["sh"]
diff --git a/php-browser-test/8.2/browser-test-entrypoint.sh b/php-browser-test/8.2/browser-test-entrypoint.sh
new file mode 100644
index 0000000..bbefdbb
--- /dev/null
+++ b/php-browser-test/8.2/browser-test-entrypoint.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -e
+
+chromedriver --allowed-ips="127.0.0.1" > /dev/null &
+
+exec "$@"
\ No newline at end of file
diff --git a/php-unit-test/8.2/Dockerfile b/php-unit-test/8.2/Dockerfile
index a4dd31f..0f91491 100644
--- a/php-unit-test/8.2/Dockerfile
+++ b/php-unit-test/8.2/Dockerfile
@@ -5,7 +5,7 @@ ARG VCS_REF
 ARG VERSION
 LABEL org.label-schema.build-date=$BUILD_DATE \
       org.label-schema.name="PHP 8.2 Unit Tester" \
-      org.label-schema.description="" \
+      org.label-schema.description="Perform unit tests in PHP (Ex. PHPUnit)" \
       org.label-schema.vcs-ref=$VCS_REF \
       org.label-schema.vendor="University of Nebraska - Lincoln" \
       org.label-schema.version=$VERSION \
-- 
GitLab