Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8 + Container image goal #16

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:7.4-apache

# hide Apache version and details
RUN echo '\n\
ServerTokens Prod\n\
ServerSignature Off\n'\
>> /etc/apache2/apache2.conf

# Copy host configuration
COPY docker/vhost.conf /etc/apache2/sites-available/000-default.conf

# Copy source code
COPY src/php/ /var/www/html
4 changes: 4 additions & 0 deletions docker/docker_image_build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker image rm firestorm-db-image &>/dev/null
docker build -t firestorm-db-image .
55 changes: 55 additions & 0 deletions docker/docker_image_test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# constants
BASE_PORT=8000
INCREMENT=1
IMAGE_NAME="firestorm-db-image"
IMAGE_TAG="latest"

npm_runner=""
if command -v pnpm &> /dev/null; then
npm_runner="pnpm"
elif command -v npm &> /dev/null; then
npm_runner="npm"
fi

temp_dir=/tmp/php-$(echo $RANDOM)
echo "Creating $temp_dir temp file folder..."
mkdir -p $temp_dir
rm -rf $temp_dir/*

echo "Copying db test files to temp file folder..."
cp tests/*.json $temp_dir
# match group write to the files with writing authorized to the test group
chgrp www-data $temp_dir/*.json
chmod g+w $temp_dir/*.json

echo -n "Finding free port for docker HTTP port..."
port=$BASE_PORT
is_free=$(netstat -taln | grep $port)
while [[ -n "$is_free" ]]; do
port=$[port+INCREMENT]
is_free=$(netstat -taln | grep $port)
done
echo " [:$port]"

echo "Starting docker container..."
docker_container_id=$(docker run -d \
-v ./tests/config.php:/var/www/html/config.php \
-v ./tests/tokens.php:/var/www/html/tokens.php \
-v $temp_dir/:/var/www/html/files \
-p $port:80 $IMAGE_NAME:$IMAGE_TAG \
)

echo "Running tests..."
$npm_runner run test -- --port $port

e=$?

echo "Cleaning after me..."
docker stop $docker_container_id &>/dev/null
docker rm $docker_container_id &>/dev/null
rm -rf $temp_dir

echo "done"
exit $e
7 changes: 7 additions & 0 deletions docker/vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"nodemon_jsdoc": "nodemon -x npm run jsdoc --watch src/index.js --watch jsdoc.json",
"types": "npx tsc",
"prettier": "prettier \"{,!(node_modules)/**/}*.js\" --config .prettierrc --write",
"test_docker": "bash docker/docker_image_build.bash && bash docker/docker_image_test.bash",
"cov": "npm run php_stop ; npm run php_start && nyc --reporter=text mocha tests/**/*.spec.js; npm run php_stop"
},
"repository": {
Expand Down
9 changes: 2 additions & 7 deletions tests/js-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const path = require("path");
const fs = require("fs");
const { readFile } = require("fs").promises;

const ADDRESS = "http://127.0.0.1:8000/";
const PORT = process.argv.indexOf('--port') > -1 ? process.argv[process.argv.indexOf('--port')+1] : '8000'
const ADDRESS = `http://127.0.0.1:${PORT}/`;
const TOKEN = "NeverGonnaGiveYouUp";

const HOUSE_DATABASE_NAME = "house";
Expand Down Expand Up @@ -231,7 +232,6 @@ describe("GET operations", () => {
done();
})
.catch((err) => {
console.trace(err.response);
done(err);
});
});
Expand Down Expand Up @@ -393,7 +393,6 @@ describe("GET operations", () => {
done();
})
.catch((err) => {
console.error(err.raw);
done(err);
});
});
Expand Down Expand Up @@ -489,7 +488,6 @@ describe("GET operations", () => {
)
.then((_) => done())
.catch((err) => {
console.error(err);
done("Should not reject with error " + JSON.stringify(err));
});
});
Expand Down Expand Up @@ -743,7 +741,6 @@ describe("PUT operations", () => {
done();
})
.catch((err) => {
console.trace(err);
done(err);
})
.finally(async () => {
Expand Down Expand Up @@ -919,7 +916,6 @@ describe("PUT operations", () => {
done();
})
.catch((err) => {
console.log(err);
done(err);
});
});
Expand Down Expand Up @@ -953,7 +949,6 @@ describe("PUT operations", () => {
done();
})
.catch((err) => {
console.error(err);
done(err);
});
});
Expand Down
Loading