From 698687f12d1151e1f4af0e6aa8ebb8e6cbbcbfae Mon Sep 17 00:00:00 2001 From: Henry Whitaker Date: Sun, 12 Apr 2020 21:01:43 +0100 Subject: [PATCH] Added all files to build image from --- Dockerfile | 40 +++++++++++++++++++++++++++++++++++ README.md | 45 ++++++++++++++++++++++++++++++++++++++++ conf/entrypoint/init.sh | 25 ++++++++++++++++++++++ conf/laravel-worker.conf | 9 ++++++++ 4 files changed, 119 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 conf/entrypoint/init.sh create mode 100644 conf/laravel-worker.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7def9f57 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM webdevops/php-nginx:ubuntu-18.04 +MAINTAINER henrywhitaker3@outlook.com + +ENV WEB_DOCUMENT_ROOT /app/site/public +ARG DEBIAN_FRONTEND=noninteractive + +# Install apt stuff +RUN apt-get update +RUN apt-get install \ + python3 \ + python3-pip -y + +# Install speedtest-cli +RUN pip3 install speedtest-cli + +# Copy over static files +RUN mkdir /setup +COPY conf/ /setup/ + +# Copy over Speedtest site files +RUN cp -r /setup/site/ /app/ + +# Setup env file +RUN cd /app/site \ + && cp .env.example .env \ + && sed 's/DB_DATABASE=.*/DB_DATABASE=\/config\/speed.db/' -i.bak .env + +# Copy supervisor queue worker config +RUN cp /setup/laravel-worker.conf /opt/docker/etc/supervisor.d/ + +# Set permissions for files +RUN cp /setup/entrypoint/init.sh /entrypoint.d +RUN chmod +x /setup/entrypoint/init.sh +RUN chown -R application:application /app +RUN chmod -R 775 /app + +# Cleanup setup files +RUN rm -r /setup + +VOLUME ["/config"] diff --git a/README.md b/README.md new file mode 100644 index 00000000..b83cf264 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Speedtest Tracker + +This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [speedtest-cli](https://github.com/sivel/speedtest-cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results. + +![speedtest](https://user-images.githubusercontent.com/36062479/78822484-a82b8300-79ca-11ea-8525-fdeae496a0bd.gif) + +## Features + +- Automatically run a speedtest every hour +- Graph of previous speedtests going back x days +- Backup/restore data in JSON format + +## Usage + +```bash +docker create \ + --name=speedtest \ + -p 8765:80 \ + -v /path/to/data:/config \ + --restart unless-stopped \ + henrywhitaker3/speedtest-tracker +``` + +## Getting the Image + +To get the base image, you have 2 options: + +- Use the pre-built image on dockerhub +- Build the image yourself + +### Pre-built Image + +Run `docker pull henrywhitaker3/speedtest-tracker` + +### Dockerfile + +Clone the required files from the github repo [here](https://github.com/henrywhitaker3/Speedtest-Tracker/tree/docker) maing sure to use the `docker` branch of the repo. + +Build the image form the docker file by running (within the cloned git repo): + +```bash +docker build . -f Dockerfile --tag=henrywhitaker3/speedtest-tracker: +``` + + diff --git a/conf/entrypoint/init.sh b/conf/entrypoint/init.sh new file mode 100644 index 00000000..27aebf7e --- /dev/null +++ b/conf/entrypoint/init.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# This script sets up the + +if [ ! -f /config/speed.db ]; then + echo "Database file not found!" + echo "Creating the database..." + touch /config/speed.db +fi + +if cat /app/site/.env | grep -E "APP_KEY=base64" > /dev/null; then + echo "App key found. Skipping app key generation" +else + echo "No app key found. Generating app key" + cd /app/site && php artisan key:generate +fi + +cd /app/site && php artisan migrate + +cd /config +mkdir -p logs + +chown -R application /config +chmod 775 -R /config + +echo "* * * * * cd /app/site/ && php artisan schedule:run >> /dev/null 2>&1" | crontab - \ No newline at end of file diff --git a/conf/laravel-worker.conf b/conf/laravel-worker.conf new file mode 100644 index 00000000..b34a8f19 --- /dev/null +++ b/conf/laravel-worker.conf @@ -0,0 +1,9 @@ +[program:laravel-worker] +process_name=%(program_name)s_%(process_num)02d +command=php /app/site/artisan queue:work +autostart=true +autorestart=true +user=application +numprocs=1 +redirect_stderr=true +logfile=/config/logs/laravel-worker.log \ No newline at end of file