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

readme, docker and detect unauthorized access #13

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/moodledata
/mysqldata
.git
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM ubuntu

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:ondrej/php
RUN apt-get update -y

RUN apt-get install -y apache2
RUN apt-get install -y php7.2 libapache2-mod-php7.2 php7.2-cli php7.2-common php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-mysql php7.2-mcrypt php7.2-zip

RUN mkdir -p /var/www/html
COPY . /var/www/html

WORKDIR /var/www/html

## configure apache

# remove ubuntu apache default page
RUN rm /var/www/html/index.html

ENV CUSTOM_DOCUMENT_ROOT=\/var\/www\/html

# fix warning
# AH00558: apache2: Could not reliably determine the server's fully qualified domain name,
# using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

RUN echo "<Directory $CUSTOM_DOCUMENT_ROOT>" >> /etc/apache2/apache2.conf
RUN echo " Options Indexes FollowSymLinks" >> /etc/apache2/apache2.conf
RUN echo " AllowOverride All" >> /etc/apache2/apache2.conf
RUN echo " Require all granted" >> /etc/apache2/apache2.conf
RUN echo "</Directory>" >> /etc/apache2/apache2.conf
RUN a2enmod rewrite

RUN mkdir -p /var/log/apache2/
RUN chmod -R 750 /var/log/apache2/
RUN chown -R www-data:www-data /var/log/apache2/
RUN chown -R www-data:www-data /var/www/html/
RUN chmod -R 755 /var/www/html/

# final docker configuration

COPY DockerfileEntryPoint.sh /usr/local/bin/DockerfileEntryPoint.sh
RUN chmod 744 /usr/local/bin/DockerfileEntryPoint.sh

ENTRYPOINT ["DockerfileEntryPoint.sh"]
60 changes: 60 additions & 0 deletions DockerfileEntryPoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
set -e

mkdir -p /var/log/apache2/
chmod -R 750 /var/log/apache2/

ENV_FILE=env
ENV_HOME=/var

function echo_log {
DATE='date +%Y/%m/%d:%H:%M:%S'
echo `$DATE`" $1"
}

function download_env_variables {

if [[ "x${CONFIGURATOR_GET_VARIABLES_FULL_URL}" = "x" || "x${CONFIGURATOR_AUTH_HEADER}" = "x" ]]; then
echo_log ""
echo_log "Configurator variables are not provided. Variables will not be downloaded"
return 0
fi

echo_log ""
echo_log "starting to download environment variables"
http_response=$(curl -s -o curl_response_file -w "%{http_code}" -H "$CONFIGURATOR_AUTH_HEADER" ${CONFIGURATOR_GET_VARIABLES_FULL_URL})

echo_log "download status: $http_response"
if [ $http_response == "200" ]; then
mv curl_response_file $ENV_HOME/$ENV_FILE
echo_log "exporting Environment Variables"
source $ENV_HOME/$ENV_FILE
else

echo_log "download response: $(cat curl_response_file)"
echo_log "new environment variables could not be obtained from remote service"

if [ -e $ENV_HOME/$ENV_FILE ]; then
echo_log "exporting old env variables"
source $ENV_HOME/$ENV_FILE
else
echo_log "environment file not found: $ENV_HOME/$ENV_FILE"
echo_log "if variables will not download, don't pass CONFIGURATOR_ variables and try again."
exit 1
fi
fi

}

function start {
php -v
source /etc/apache2/envvars
exec apache2 -DFOREGROUND
}


########################
# Scripts starts here
########################
download_env_variables
start
223 changes: 128 additions & 95 deletions README.md

Large diffs are not rendered by default.

Loading