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

Add files needed to build and run application with Docker #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM php:alpine

WORKDIR app
COPY . /app/

# Add basics first
RUN \
apk add --no-cache apache2 php-apache2 php-json \
&& sed -i "s/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ session_module/LoadModule\ session_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ session_cookie_module/LoadModule\ session_cookie_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ session_crypto_module/LoadModule\ session_crypto_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ deflate_module/LoadModule\ deflate_module/" /etc/apache2/httpd.conf \
&& sed -i "s#^DocumentRoot \".*#DocumentRoot \"/app/web-root\"#g" /etc/apache2/httpd.conf \
&& sed -i "s#/var/www/localhost/htdocs#/app/web-root#" /etc/apache2/httpd.conf \
&& printf "\n<Directory \"/app/web-root\">\n\tAllowOverride All\n</Directory>\n" >> /etc/apache2/httpd.conf \
&& chown -R www-data:www-data /app && chmod -R 755 /app \
&& sed -i "s/index.html/index.php/g" /etc/apache2/httpd.conf \
&& chmod +x /app/start.sh

EXPOSE 80
ENTRYPOINT ["/app/start.sh"]
79 changes: 79 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh

# Set the timezone. Base image does not contain the setup-timezone script, so an alternate way is used.
if [ "$CONTAINER_TIMEZONE" ]; then
cp /usr/share/zoneinfo/${CONTAINER_TIMEZONE} /etc/localtime && \
echo "${CONTAINER_TIMEZONE}" > /etc/timezone && \
echo "Container timezone set to: $CONTAINER_TIMEZONE"
fi

# Apache server name change
if [ ! -z "$APACHE_SERVER_NAME" ]
then
sed -i "s/#ServerName www.example.com:80/ServerName $APACHE_SERVER_NAME/" /etc/apache2/httpd.conf
echo "Changed server name to '$APACHE_SERVER_NAME'..."
else
echo "NOTICE: Change 'ServerName' globally and hide server message by setting environment variable >> 'APACHE_SERVER_NAME=your.server.name' in docker command or docker-compose file"
fi

# PHP Config
if [ ! -z "$PHP_SHORT_OPEN_TAG" ]; then sed -i "s/\;\?\\s\?short_open_tag = .*/short_open_tag = $PHP_SHORT_OPEN_TAG/" /etc/php7/php.ini && echo "Set PHP short_open_tag = $PHP_SHORT_OPEN_TAG..."; fi
if [ ! -z "$PHP_OUTPUT_BUFFERING" ]; then sed -i "s/\;\?\\s\?output_buffering = .*/output_buffering = $PHP_OUTPUT_BUFFERING/" /etc/php7/php.ini && echo "Set PHP output_buffering = $PHP_SHORT_OUTPUT_BUFFERING..."; fi
if [ ! -z "$PHP_OPEN_BASEDIR" ]; then sed -i "s/\;\?\\s\?open_basedir = .*/open_basedir = $PHP_OPEN_BASEDIR/" /etc/php7/php.ini && echo "Set PHP open_basedir = $PHP_OPEN_BASEDIR..."; fi
if [ ! -z "$PHP_MAX_EXECUTION_TIME" ]; then sed -i "s/\;\?\\s\?max_execution_time = .*/max_execution_time = $PHP_MAX_EXECUTION_TIME/" /etc/php7/php.ini && echo "Set PHP max_execution_time = $PHP_MAX_EXECUTION_TIME..."; fi
if [ ! -z "$PHP_MAX_INPUT_TIME" ]; then sed -i "s/\;\?\\s\?max_input_time = .*/max_input_time = $PHP_MAX_INPUT_TIME/" /etc/php7/php.ini && echo "Set PHP max_input_time = $PHP_MAX_INPUT_TIME..."; fi
if [ ! -z "$PHP_MAX_INPUT_VARS" ]; then sed -i "s/\;\?\\s\?max_input_vars = .*/max_input_vars = $PHP_MAX_INPUT_VARS/" /etc/php7/php.ini && echo "Set PHP max_input_vars = $PHP_MAX_INPUT_VARS..."; fi
if [ ! -z "$PHP_MEMORY_LIMIT" ]; then sed -i "s/\;\?\\s\?memory_limit = .*/memory_limit = $PHP_MEMORY_LIMIT/" /etc/php7/php.ini && echo "Set PHP memory_limit = $PHP_MEMORY_LIMIT..."; fi
if [ ! -z "$PHP_ERROR_REPORTING" ]; then sed -i "s/\;\?\\s\?error_reporting = .*/error_reporting = $PHP_ERROR_REPORTING/" /etc/php7/php.ini && echo "Set PHP error_reporting = $PHP_ERROR_REPORTING..."; fi
if [ ! -z "$PHP_DISPLAY_ERRORS" ]; then sed -i "s/\;\?\\s\?display_errors = .*/display_errors = $PHP_DISPLAY_ERRORS/" /etc/php7/php.ini && echo "Set PHP display_errors = $PHP_DISPLAY_ERRORS..."; fi
if [ ! -z "$PHP_DISPLAY_STARTUP_ERRORS" ]; then sed -i "s/\;\?\\s\?display_startup_errors = .*/display_startup_errors = $PHP_DISPLAY_STARTUP_ERRORS/" /etc/php7/php.ini && echo "Set PHP display_startup_errors = $PHP_DISPLAY_STARTUP_ERRORS..."; fi
if [ ! -z "$PHP_LOG_ERRORS" ]; then sed -i "s/\;\?\\s\?log_errors = .*/log_errors = $PHP_LOG_ERRORS/" /etc/php7/php.ini && echo "Set PHP log_errors = $PHP_LOG_ERRORS..."; fi
if [ ! -z "$PHP_LOG_ERRORS_MAX_LEN" ]; then sed -i "s/\;\?\\s\?log_errors_max_len = .*/log_errors_max_len = $PHP_LOG_ERRORS_MAX_LEN/" /etc/php7/php.ini && echo "Set PHP log_errors_max_len = $PHP_LOG_ERRORS_MAX_LEN..."; fi
if [ ! -z "$PHP_IGNORE_REPEATED_ERRORS" ]; then sed -i "s/\;\?\\s\?ignore_repeated_errors = .*/ignore_repeated_errors = $PHP_IGNORE_REPEATED_ERRORS/" /etc/php7/php.ini && echo "Set PHP ignore_repeated_errors = $PHP_IGNORE_REPEATED_ERRORS..."; fi
if [ ! -z "$PHP_REPORT_MEMLEAKS" ]; then sed -i "s/\;\?\\s\?report_memleaks = .*/report_memleaks = $PHP_REPORT_MEMLEAKS/" /etc/php7/php.ini && echo "Set PHP report_memleaks = $PHP_REPORT_MEMLEAKS..."; fi
if [ ! -z "$PHP_HTML_ERRORS" ]; then sed -i "s/\;\?\\s\?html_errors = .*/html_errors = $PHP_HTML_ERRORS/" /etc/php7/php.ini && echo "Set PHP html_errors = $PHP_HTML_ERRORS..."; fi
if [ ! -z "$PHP_ERROR_LOG" ]; then sed -i "s/\;\?\\s\?error_log = .*/error_log = $PHP_ERROR_LOG/" /etc/php7/php.ini && echo "Set PHP error_log = $PHP_ERROR_LOG..."; fi
if [ ! -z "$PHP_POST_MAX_SIZE" ]; then sed -i "s/\;\?\\s\?post_max_size = .*/post_max_size = $PHP_POST_MAX_SIZE/" /etc/php7/php.ini && echo "Set PHP post_max_size = $PHP_POST_MAX_SIZE..."; fi
if [ ! -z "$PHP_DEFAULT_MIMETYPE" ]; then sed -i "s/\;\?\\s\?default_mimetype = .*/default_mimetype = $PHP_DEFAULT_MIMETYPE/" /etc/php7/php.ini && echo "Set PHP default_mimetype = $PHP_DEFAULT_MIMETYPE..."; fi
if [ ! -z "$PHP_DEFAULT_CHARSET" ]; then sed -i "s/\;\?\\s\?default_charset = .*/default_charset = $PHP_DEFAULT_CHARSET/" /etc/php7/php.ini && echo "Set PHP default_charset = $PHP_DEFAULT_CHARSET..."; fi
if [ ! -z "$PHP_FILE_UPLOADS" ]; then sed -i "s/\;\?\\s\?file_uploads = .*/file_uploads = $PHP_FILE_UPLOADS/" /etc/php7/php.ini && echo "Set PHP file_uploads = $PHP_FILE_UPLOADS..."; fi
if [ ! -z "$PHP_UPLOAD_TMP_DIR" ]; then sed -i "s/\;\?\\s\?upload_tmp_dir = .*/upload_tmp_dir = $PHP_UPLOAD_TMP_DIR/" /etc/php7/php.ini && echo "Set PHP upload_tmp_dir = $PHP_UPLOAD_TMP_DIR..."; fi
if [ ! -z "$PHP_UPLOAD_MAX_FILESIZE" ]; then sed -i "s/\;\?\\s\?upload_max_filesize = .*/upload_max_filesize = $PHP_UPLOAD_MAX_FILESIZE/" /etc/php7/php.ini && echo "Set PHP upload_max_filesize = $PHP_UPLOAD_MAX_FILESIZE..."; fi
if [ ! -z "$PHP_MAX_FILE_UPLOADS" ]; then sed -i "s/\;\?\\s\?max_file_uploads = .*/max_file_uploads = $PHP_MAX_FILE_UPLOADS/" /etc/php7/php.ini && echo "Set PHP max_file_uploads = $PHP_MAX_FILE_UPLOADS..."; fi
if [ ! -z "$PHP_ALLOW_URL_FOPEN" ]; then sed -i "s/\;\?\\s\?allow_url_fopen = .*/allow_url_fopen = $PHP_ALLOW_URL_FOPEN/" /etc/php7/php.ini && echo "Set PHP allow_url_fopen = $PHP_ALLOW_URL_FOPEN..."; fi
if [ ! -z "$PHP_ALLOW_URL_INCLUDE" ]; then sed -i "s/\;\?\\s\?allow_url_include = .*/allow_url_include = $PHP_ALLOW_URL_INCLUDE/" /etc/php7/php.ini && echo "Set PHP allow_url_include = $PHP_ALLOW_URL_INCLUDE..."; fi
if [ ! -z "$PHP_DEFAULT_SOCKET_TIMEOUT" ]; then sed -i "s/\;\?\\s\?default_socket_timeout = .*/default_socket_timeout = $PHP_DEFAULT_SOCKET_TIMEOUT/" /etc/php7/php.ini && echo "Set PHP default_socket_timeout = $PHP_DEFAULT_SOCKET_TIMEOUT..."; fi
if [ ! -z "$PHP_DATE_TIMEZONE" ]; then sed -i "s/\;\?\\s\?date.timezone = .*/date.timezone = $PHP_DATE_TIMEZONE/" /etc/php7/php.ini && echo "Set PHP date.timezone = $PHP_DATE_TIMEZONE..."; fi
if [ ! -z "$PHP_PDO_MYSQL_CACHE_SIZE" ]; then sed -i "s/\;\?\\s\?pdo_mysql.cache_size = .*/pdo_mysql.cache_size = $PHP_PDO_MYSQL_CACHE_SIZE/" /etc/php7/php.ini && echo "Set PHP pdo_mysql.cache_size = $PHP_PDO_MYSQL_CACHE_SIZE..."; fi
if [ ! -z "$PHP_PDO_MYSQL_DEFAULT_SOCKET" ]; then sed -i "s/\;\?\\s\?pdo_mysql.default_socket = .*/pdo_mysql.default_socket = $PHP_PDO_MYSQL_DEFAULT_SOCKET/" /etc/php7/php.ini && echo "Set PHP pdo_mysql.default_socket = $PHP_PDO_MYSQL_DEFAULT_SOCKET..."; fi
if [ ! -z "$PHP_SESSION_SAVE_HANDLER" ]; then sed -i "s/\;\?\\s\?session.save_handler = .*/session.save_handler = $PHP_SESSION_SAVE_HANDLER/" /etc/php7/php.ini && echo "Set PHP session.save_handler = $PHP_SESSION_SAVE_HANDLER..."; fi
if [ ! -z "$PHP_SESSION_SAVE_PATH" ]; then sed -i "s/\;\?\\s\?session.save_path = .*/session.save_path = $PHP_SESSION_SAVE_PATH/" /etc/php7/php.ini && echo "Set PHP session.save_path = $PHP_SESSION_SAVE_PATH..."; fi
if [ ! -z "$PHP_SESSION_USE_STRICT_MODE" ]; then sed -i "s/\;\?\\s\?session.use_strict_mode = .*/session.use_strict_mode = $PHP_SESSION_USE_STRICT_MODE/" /etc/php7/php.ini && echo "Set PHP session.use_strict_mode = $PHP_SESSION_USE_STRICT_MODE..."; fi
if [ ! -z "$PHP_SESSION_USE_COOKIES" ]; then sed -i "s/\;\?\\s\?session.use_cookies = .*/session.use_cookies = $PHP_SESSION_USE_COOKIES/" /etc/php7/php.ini && echo "Set PHP session.use_cookies = $PHP_SESSION_USE_COOKIES..."; fi
if [ ! -z "$PHP_SESSION_COOKIE_SECURE" ]; then sed -i "s/\;\?\\s\?session.cookie_secure = .*/session.cookie_secure = $PHP_SESSION_COOKIE_SECURE/" /etc/php7/php.ini && echo "Set PHP session.cookie_secure = $PHP_SESSION_COOKIE_SECURE..."; fi
if [ ! -z "$PHP_SESSION_NAME" ]; then sed -i "s/\;\?\\s\?session.name = .*/session.name = $PHP_SESSION_NAME/" /etc/php7/php.ini && echo "Set PHP session.name = $PHP_SESSION_NAME..."; fi
if [ ! -z "$PHP_SESSION_COOKIE_LIFETIME" ]; then sed -i "s/\;\?\\s\?session.cookie_lifetime = .*/session.cookie_lifetime = $PHP_SESSION_COOKIE_LIFETIME/" /etc/php7/php.ini && echo "Set PHP session.cookie_lifetime = $PHP_SESSION_COOKIE_LIFETIME..."; fi
if [ ! -z "$PHP_SESSION_COOKIE_PATH" ]; then sed -i "s/\;\?\\s\?session.cookie_path = .*/session.cookie_path = $PHP_SESSION_COOKIE_PATH/" /etc/php7/php.ini && echo "Set PHP session.cookie_path = $PHP_SESSION_COOKIE_PATH..."; fi
if [ ! -z "$PHP_SESSION_COOKIE_DOMAIN" ]; then sed -i "s/\;\?\\s\?session.cookie_domain = .*/session.cookie_domain = $PHP_SESSION_COOKIE_DOMAIN/" /etc/php7/php.ini && echo "Set PHP session.cookie_domain = $PHP_SESSION_COOKIE_DOMAIN..."; fi
if [ ! -z "$PHP_SESSION_COOKIE_HTTPONLY" ]; then sed -i "s/\;\?\\s\?session.cookie_httponly = .*/session.cookie_httponly = $PHP_SESSION_COOKIE_HTTPONLY/" /etc/php7/php.ini && echo "Set PHP session.cookie_httponly = $PHP_SESSION_COOKIE_HTTPONLY..."; fi

# enable xdebug coverage for testing with phpunit (already installed)
if [ ! -z "$PHP_XDEBUG_ENABLED" ]
then
echo "Enable XDebug..."
echo 'zend_extension=/usr/lib/php7/modules/xdebug.so' >> /etc/php7/php.ini;
echo 'xdebug.coverage_enable=On' >> /etc/php7/php.ini;
echo 'xdebug.remote_enable=1' >> /etc/php7/php.ini;
echo 'xdebug.remote_connect_back=1' >> /etc/php7/php.ini;
echo 'xdebug.remote_log=/tmp/xdebug.log' >> /etc/php7/php.ini;
echo 'xdebug.remote_autostart=true' >> /etc/php7/php.ini;
fi

# Start (ensure apache2 PID not left behind first) to stop auto start crashes if didn't shut down properly

echo "Clearing any old processes..."
rm -f /run/apache2/apache2.pid
rm -f /run/apache2/httpd.pid

echo "Starting apache..."
httpd -D FOREGROUND
18 changes: 14 additions & 4 deletions web-root/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div id="menu-left" class="menubar">
<div id="search-holder" class="menu-item">
<span class="icon-search"></span>
<input type="text" id="search"></input>
<input type="text" id="search"/>
</div>
<div id="menu-groups" class="menu-item">
<div class="menu-title">Groups</div>
Expand Down Expand Up @@ -71,15 +71,15 @@
<span class="box-header">Legend</span>
<ul id="legend">
<li>
<img class="dot" src="/dot-red.png"></img>
<img class="dot" src="/dot-red.png"/>
Satellite
</li>
<li>
<img class="dot" src="/dot-blue.png"></img>
<img class="dot" src="/dot-blue.png"/>
Rocket body
</li>
<li>
<img class="dot" src="/dot-grey.png"></img>
<img class="dot" src="/dot-grey.png"/>
Debris
</li>
</ul>
Expand Down Expand Up @@ -118,6 +118,16 @@
</div>
<div id="search-results"></div>
<div id="sat-hoverbox">(none)</div>
<div class="sat-description">
<div class="sat-description__header">
<div class="sat-description__header--left">About</div>
<a class="sat-description__header--right sat-description__close">X</a>
</div>
<div class="sat-description__content"></div>
<div class="sat-description__footer">
<b>Credits:</b> NASA Space Science Data Coordinated Archive
</div>
</div>
<div id="sat-infobox">
<div id="sat-info-title">This is a title</div>
<div id="all-objects-link" class="link">Find all objects from this launch...</div>
Expand Down
43 changes: 43 additions & 0 deletions web-root/nasainfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
$catalogURLTemplate = 'http://nssdc.gsfc.nasa.gov/nmc/masterCatalog.do?sc=%s';
$designator = htmlspecialchars($_GET['intldes']);
$redirect = filter_var($_GET['redirect'], FILTER_VALIDATE_BOOLEAN);

if ($designator) {
if ($redirect) {
header('Location: ' . sprintf($catalogURLTemplate, $designator), true, 302);
exit;
} else {
$catalogEntryHtml = file_get_contents(sprintf($catalogURLTemplate, $designator));

if ($catalogEntryHtml) {
$catalogEntryDocument = new DOMDocument();
if ($catalogEntryDocument->loadHTML($catalogEntryHtml)) {
$xpath = new DOMXPath($catalogEntryDocument);

$match = $xpath->query('//div[@id="contentwrapper"]//div[@class="urone"]');
if ($match->length > 0) {
$description = '';
$descriptionParts = $match[0]->childNodes;
for ($i = 1; $i < $descriptionParts->length; ++$i) {
$description .= trim($descriptionParts[$i]->nodeValue);
}

header('Content-Type: text/json', true, 200);

$data = array(
'description' => $description
);

echo json_encode($data);

exit;
}
}
}
}
}

// fall back - if any error happened during data extraction above, return 404
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
?>
21 changes: 20 additions & 1 deletion web-root/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,22 @@ $(document).ready(function() {
initialRotation = false;
camZoomSnappedOnSat = false;
});

$('.sat-description__close').click(function() {
$('.sat-description').fadeOut();
});
// debugContext = $('#debug-canvas')[0].getContext('2d');
// debugImageData = debugContext.createImageData(debugContext.canvas.width, debugContext.canvas.height);
drawLoop(); //kick off the animationFrame()s
});

function selectSat(satId) {
$('.sat-description').fadeOut();

selectedSat = satId;
if(satId === -1) {
$('#sat-infobox').fadeOut();
orbitDisplay.clearSelectOrbit();
orbitDisplay.clearSelectOrbit();
} else {
camZoomSnappedOnSat = true;
camAngleSnappedOnSat = true;
Expand All @@ -262,6 +268,19 @@ function selectSat(satId) {
// camSnapToSat(satId);
var sat = satSet.getSat(satId);
if(!sat) return;

var nasaInfoUrl = 'nasainfo.php?intldes=' + sat.intlDes;
$.getJSON(nasaInfoUrl, function (data){
var satDescription = $('.sat-description');
var satDescriptionContent = $('.sat-description__content', satDescription);
var learnMore = $('<a/>').prop('href', nasaInfoUrl + '&redirect=true').text('Learn more...');

satDescriptionContent.html(data.description);
satDescriptionContent.append($('<br/>'), learnMore);

satDescription.fadeIn();
});

orbitDisplay.setSelectOrbit(satId);
$('#sat-infobox').fadeIn();
$('#sat-info-title').html(sat.OBJECT_NAME);
Expand Down
1 change: 1 addition & 0 deletions web-root/scripts/sat.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ satSet.draw = function(pMatrix, camMatrix) {

gl.bindBuffer(gl.ARRAY_BUFFER, satPosBuf);
gl.bufferData(gl.ARRAY_BUFFER, satPos, gl.STREAM_DRAW);
gl.enableVertexAttribArray(dotShader.aPos);
gl.vertexAttribPointer(dotShader.aPos, 3, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, satColorBuf);
Expand Down
57 changes: 55 additions & 2 deletions web-root/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,59 @@ ul {
pointer-events: none;
}

.sat-description {
background: black;
border-radius: 5px;
border: 1px solid rgba(255, 255, 255, 0.2);
cursor: default;
color: white;
position: absolute;
top: 50%;
left: 50%;
padding: 1px;
margin-top: auto;
margin-bottom: auto;
display: none;
}

.sat-description__header {
padding: 1px;
border-radius: 5px;
border: 1px solid rgba(255, 255, 255, 0.2);
display: flex;
flex-direction: row;
}

.sat-description__header--left {
padding: 4px;
flex-grow: 1;
}

.sat-description__header--right {
flex: none;
display: flex;
align-items: center;
justify-content: center;
width: 25px;
height: 25px;
font-size: 10px;
border-radius: 5px;
border: 1px solid rgba(255, 255, 255, 0.2);
cursor: hand;
text-decoration: none;
}

.sat-description__content {
overflow-y: scroll;
padding: 9px;
max-width: 400px;
max-height: 250px;
}

.sat-description__footer {
font-size: 8pt;
}

#sat-infobox {
background: black;
cursor:default;
Expand Down Expand Up @@ -186,7 +239,7 @@ ul {
font-size: 12px;
height: 28px;
float: right;
margin-right: 10 px;
margin-right: 10px;
}

#search {
Expand Down Expand Up @@ -359,4 +412,4 @@ ul {

#controls-info>li {
margin-top: 10px;
}
}