Skip to content

Commit 7e35462

Browse files
authored
Merge pull request #12 from renatomefi/fix/posix-compat
Fix posix compatibility
2 parents 8c61207 + 8e13418 commit 7e35462

File tree

10 files changed

+65
-23
lines changed

10 files changed

+65
-23
lines changed

.circleci/config.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ jobs:
3030
machine: true
3131
steps:
3232
- checkout
33-
- run: make test-image IMAGE="php:fpm-alpine"
33+
- run: make test-image IMAGE="php:fpm-alpine" DOCKERFILE="alpine"
34+
- run: make test-image IMAGE="php:fpm-stretch" DOCKERFILE="stretch"
3435

3536
test-7.1:
3637
machine: true
3738
steps:
3839
- checkout
39-
- run: make test-image IMAGE="php:7.1-fpm-alpine3.7"
40-
- run: make test-image IMAGE="php:7.1-fpm-alpine3.8"
40+
- run: make test-image IMAGE="php:7.1-fpm-alpine3.7" DOCKERFILE="alpine"
41+
- run: make test-image IMAGE="php:7.1-fpm-alpine3.8" DOCKERFILE="alpine"
42+
- run: make test-image IMAGE="php:7.1-fpm-stretch" DOCKERFILE="stretch"
4143

4244
test-7.2:
4345
machine: true
4446
steps:
4547
- checkout
46-
- run: make test-image IMAGE="php:7.2-fpm-alpine3.7"
47-
- run: make test-image IMAGE="php:7.2-fpm-alpine3.8"
48+
- run: make test-image IMAGE="php:7.2-fpm-alpine3.7" DOCKERFILE="alpine"
49+
- run: make test-image IMAGE="php:7.2-fpm-alpine3.8" DOCKERFILE="alpine"
50+
- run: make test-image IMAGE="php:7.2-fpm-stretch" DOCKERFILE="stretch"
4851

4952
test-7.3:
5053
machine: true
5154
steps:
5255
- checkout
53-
- run: make test-image IMAGE="php:7.3-rc-fpm-alpine3.8"
56+
- run: make test-image IMAGE="php:7.3-rc-fpm-alpine3.8" DOCKERFILE="alpine"
57+
- run: make test-image IMAGE="php:7.3-rc-fpm-stretch" DOCKERFILE="stretch"

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ current_dir := $(abspath $(patsubst %/,%,$(dir $(mkfile_path))))
66
.PHONY: *
77

88
lint: php-fpm-healthcheck
9-
docker run --rm -v ${current_dir}:/mnt:ro koalaman/shellcheck ./php-fpm-healthcheck ./test/*.sh
9+
docker run --rm -v ${current_dir}:/mnt:ro koalaman/shellcheck \
10+
./php-fpm-healthcheck ./test/*.sh
1011

1112
test:
12-
$(MAKE) test-image IMAGE="php:fpm-alpine"
13-
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.7"
14-
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.8"
15-
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.7"
16-
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.8"
17-
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-alpine3.8"
13+
$(MAKE) test-image IMAGE="php:fpm-alpine" DOCKERFILE="alpine"
14+
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.7" DOCKERFILE="alpine"
15+
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.8" DOCKERFILE="alpine"
16+
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.7" DOCKERFILE="alpine"
17+
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.8" DOCKERFILE="alpine"
18+
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-alpine3.8" DOCKERFILE="alpine"
19+
$(MAKE) test-image IMAGE="php:7.1-fpm-stretch" DOCKERFILE="stretch"
20+
$(MAKE) test-image IMAGE="php:7.2-fpm-stretch" DOCKERFILE="stretch"
21+
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-stretch" DOCKERFILE="stretch"
1822

1923
test-image:
20-
./test/docker.sh ${IMAGE}
24+
./test/docker.sh ${DOCKERFILE} ${IMAGE}

php-fpm-healthcheck

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# --slow-requests=n
3434
#
3535

36-
set -euo pipefail
36+
set -eu
3737

3838
OPTIND=1 # Reset getopt in case it has been used previously in the shell
3939

@@ -54,9 +54,9 @@ command -v grep 1> /dev/null || { >&2 echo "Make sure grep is installed (i.e. ap
5454
get_fpm_status() {
5555
if test "$VERBOSE" = 1; then printf "Trying to connect to php-fpm via: %s\\n" "$1"; fi;
5656

57-
if test ! -z "$FPM_STATUS"; then
58-
FPM_STATUS=$(cgi-fcgi -bind -connect "$1" | tail +5)
59-
fi;
57+
# Since I cannot use pipefail I'll just split these in two commands
58+
FPM_STATUS=$(cgi-fcgi -bind -connect "$1")
59+
FPM_STATUS=$(echo "$FPM_STATUS" | tail +5)
6060

6161
if test "$VERBOSE" = 1; then printf "php-fpm status output:\\n%s\\n" "$FPM_STATUS"; fi;
6262
}

test/Dockerfile renamed to test/Dockerfile-alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM php:7.2-fpm-alpine3.8
22

33
# Required software
4-
RUN apk add --no-cache fcgi
4+
RUN apk add --no-cache fcgi
55

66
# Enable php fpm status page
77
RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf

test/Dockerfile-stretch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM php:7.2-fpm-stretch
2+
3+
# Required software
4+
RUN set -x \
5+
&& apt-get update \
6+
&& apt-get install -y libfcgi-bin
7+
8+
# Enable php fpm status page
9+
RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf
10+
11+
COPY ./php-fpm-healthcheck /usr/local/bin/

test/docker.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ docker stop "$CONTAINER" 1> /dev/null
1414
}
1515
trap cleanup EXIT
1616

17-
declare -r DOCKER_IMAGE="$1"
17+
declare -r DOCKER_FILE="$1"
18+
declare -r DOCKER_IMAGE="$2"
1819

1920
declare DOCKER_TAG_TEMPORARY
2021
DOCKER_TAG_TEMPORARY="$DOCKER_IMAGE-$(date +%s)"
2122

22-
sed "s/FROM .*/FROM $DOCKER_IMAGE/g" ./test/Dockerfile | docker build -t "$DOCKER_TAG_TEMPORARY" -f - .
23+
sed "s/FROM .*/FROM $DOCKER_IMAGE/g" "./test/Dockerfile-$DOCKER_FILE" | docker build -t "$DOCKER_TAG_TEMPORARY" -f - .
2324

2425
declare CONTAINER
2526
CONTAINER=$(docker run -d --rm "$DOCKER_TAG_TEMPORARY")
@@ -30,4 +31,6 @@ TESTS_DIR="$(pwd)/test"
3031
docker run --rm -t \
3132
-v "$TESTS_DIR:/tests" \
3233
-v /var/run/docker.sock:/var/run/docker.sock:ro \
33-
renatomefi/docker-testinfra:latest --verbose --hosts="docker://$CONTAINER"
34+
renatomefi/docker-testinfra:latest \
35+
--verbose --hosts="docker://$CONTAINER" \
36+
-m "php_fpm or $DOCKER_FILE"

test/testinfra/test_command.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_healthcheck_script_is_available(host):
45
cmd = host.run("which php-fpm-healthcheck")
56
assert cmd.rc == 0
67

8+
@pytest.mark.php_fpm
79
def test_healthcheck_script_is_executable(host):
810
scriptFile = host.check_output("which php-fpm-healthcheck")
911

test/testinfra/test_execution.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_invalid_option_exits_properly(host):
45
cmd = host.run("php-fpm-healthcheck --invalid-option")
56
assert cmd.rc == 3
67

78
cmd = host.run("php-fpm-healthcheck --invalid-option=")
89
assert cmd.rc == 3
910

11+
@pytest.mark.php_fpm
1012
def test_valid_with_empty_value_exits_properly(host):
1113
cmd = host.run("php-fpm-healthcheck --listen-queue-len=")
1214
assert cmd.rc == 3
1315
assert "option value must be an integer" in cmd.stderr
1416

17+
@pytest.mark.php_fpm
1518
def test_valid_with_non_integer_value_exits_properly(host):
1619
cmd = host.run("php-fpm-healthcheck --listen-queue-len=abc")
1720
assert cmd.rc == 3
1821
assert "option value must be an integer" in cmd.stderr
1922

20-
def test_missing_fcgi(host):
23+
@pytest.mark.alpine
24+
def test_missing_fcgi_apk(host):
2125
host.run("apk del fcgi")
2226
cmd = host.run("php-fpm-healthcheck")
2327
assert cmd.rc == 4
@@ -26,3 +30,14 @@ def test_missing_fcgi(host):
2630
# Fail safe for other tests, maybe we could use a docker fixture
2731
# to start a new container everytime
2832
host.run("apk add --no-cache fcgi")
33+
34+
@pytest.mark.stretch
35+
def test_missing_fcgi_apt(host):
36+
host.run("apt-get remove -y libfcgi-bin")
37+
cmd = host.run("php-fpm-healthcheck")
38+
assert cmd.rc == 4
39+
assert "Make sure fcgi is installed" in cmd.stderr
40+
41+
# Fail safe for other tests, maybe we could use a docker fixture
42+
# to start a new container everytime
43+
host.run("apt-get install -y libfcgi-bin")

test/testinfra/test_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_metric_accepted_conn(host):
45
cmd = host.run("php-fpm-healthcheck -v")
56
assert cmd.rc == 0

test/testinfra/test_ping.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_ping(host):
45
cmd = host.run("php-fpm-healthcheck")
56
assert cmd.rc == 0
67

8+
@pytest.mark.php_fpm
79
def test_ping_verbose(host):
810
cmd = host.run("php-fpm-healthcheck -v")
911
assert cmd.rc == 0

0 commit comments

Comments
 (0)