From 6425783760783c13686b31227ab68ca388b410e0 Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Tue, 16 Oct 2018 15:37:14 -0700 Subject: [PATCH 1/2] serving/helloworld-php: Respect the PORT env var --- serving/samples/helloworld-php/Dockerfile | 5 +++-- serving/samples/helloworld-php/README.md | 15 ++++++++------- serving/samples/helloworld-php/index.php | 5 ++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/serving/samples/helloworld-php/Dockerfile b/serving/samples/helloworld-php/Dockerfile index 2ed6761b64b..7e8e2a3b31a 100644 --- a/serving/samples/helloworld-php/Dockerfile +++ b/serving/samples/helloworld-php/Dockerfile @@ -2,5 +2,6 @@ FROM php:7.2.6-apache COPY index.php /var/www/html/ -# Run on port 8080 rather than 80 -RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf +ENV PORT 8080 + +RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf diff --git a/serving/samples/helloworld-php/README.md b/serving/samples/helloworld-php/README.md index b9303062f0c..d7a355c3b70 100644 --- a/serving/samples/helloworld-php/README.md +++ b/serving/samples/helloworld-php/README.md @@ -1,8 +1,8 @@ # Hello World - PHP sample A simple web app written in PHP that you can use for testing. -It reads in an env variable `TARGET` and prints "Hello World: ${TARGET}". If -TARGET is not specified, it will use "NOT SPECIFIED" as the TARGET. +It reads in an env variable `TARGET` and prints "Hello ${TARGET}!". If +TARGET is not specified, it will use "World" as the TARGET. ## Prerequisites @@ -29,9 +29,8 @@ following instructions recreate the source files from this folder. ```php + $target = getenv('TARGET', true) ?: "World"; + echo sprintf("Hello %s!\n", $target); ``` 1. Create a file named `Dockerfile` and copy the code block below into it. @@ -42,8 +41,10 @@ following instructions recreate the source files from this folder. COPY index.php /var/www/html/ - # Run on port 8080 rather than 80 - RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf + ENV PORT 8080 + + RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf + ``` 1. Create a new file, `service.yaml` and copy the following service definition diff --git a/serving/samples/helloworld-php/index.php b/serving/samples/helloworld-php/index.php index c352fef5172..b7a1cb5a4cf 100644 --- a/serving/samples/helloworld-php/index.php +++ b/serving/samples/helloworld-php/index.php @@ -1,4 +1,3 @@ +$target = getenv('TARGET', true) ?: 'World'; +echo sprintf('Hello %s!\n', $target); From 998d7675d962fdaad4a44ebb7d212edf76f83255 Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Tue, 16 Oct 2018 15:41:48 -0700 Subject: [PATCH 2/2] serving/helloworld-php: add a comment to explain sed command --- serving/samples/helloworld-php/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/serving/samples/helloworld-php/Dockerfile b/serving/samples/helloworld-php/Dockerfile index 7e8e2a3b31a..bd08e66d7b2 100644 --- a/serving/samples/helloworld-php/Dockerfile +++ b/serving/samples/helloworld-php/Dockerfile @@ -4,4 +4,5 @@ COPY index.php /var/www/html/ ENV PORT 8080 +# Use the PORT environment variable in Apache configuration files. RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf