Compare commits

..

1 commit

Author SHA1 Message Date
7ee7793c47 [CI] Add shellcheck
Some checks reported errors
continuous-integration/drone/push Build encountered an error
2020-03-03 00:53:07 +01:00
7 changed files with 30 additions and 68 deletions

View file

@ -16,13 +16,20 @@ steps:
- name: w3c validator - name: w3c validator
image: validator/validator:latest image: validator/validator:latest
commands: commands:
- /vnu-runtime-image/bin/vnu static/*.html - vnu static/*.html
- name: markdown lint - name: markdown lint
image: pipelinecomponents/markdownlint:latest image: pipelinecomponents/markdownlint:latest
commands: commands:
- mdl --style all --warnings . - mdl --style all --warnings .
- name: shellcheck
image: koalaman/shellcheck
environment:
WORKDIR: /drone/src
commands:
- shellcheck *.sh
--- ---
kind: pipeline kind: pipeline
name: unit tests name: unit tests
@ -53,10 +60,6 @@ steps:
from_secret: dockerhub_username from_secret: dockerhub_username
password: password:
from_secret: dockerhub_password from_secret: dockerhub_password
when:
event:
exclude:
- pull_request
depends_on: depends_on:
- unit tests - unit tests
@ -106,10 +109,6 @@ steps:
BRANCH: ${DRONE_COMMIT_BRANCH} BRANCH: ${DRONE_COMMIT_BRANCH}
commands: commands:
- bash staging_tests.sh - bash staging_tests.sh
when:
branch:
exclude:
- master
- name: deploy live - name: deploy live
image: sinlead/drone-kubectl image: sinlead/drone-kubectl

View file

@ -3,7 +3,6 @@ FROM python:slim
RUN pip install flask RUN pip install flask
COPY /beer/beer.py /beer.py COPY /beer/beer.py /beer.py
COPY /beer/templates /templates COPY /beer/templates /templates
COPY /beer/static /static
EXPOSE 5000 EXPOSE 5000
CMD ["python", "/beer.py"] CMD ["python", "/beer.py"]

View file

@ -4,42 +4,24 @@
from flask import Flask from flask import Flask
from flask import render_template from flask import render_template
from flask import send_from_directory
# pylint: disable=invalid-name # pylint: disable=invalid-name
app = Flask(__name__) app = Flask(__name__)
app.url_map.strict_slashes = False
@app.route('/') @app.route('/')
@app.route('/<int(min=0, max=23):hours>') @app.route('/<int(min=0, max=23):hours>')
@app.route('/<int(min=0, max=23):hours>/<int(min=0, max=59):minutes>') @app.route('/<int(min=0, max=23):hours>/<int(min=0, max=59):minutes>')
def index(hours=None, minutes=None): def index(hours=None, minutes=None):
""" main and only app """ """ main and only app """
if not hours:
if hours:
if not minutes:
minutes = 0
else:
hours = 17 hours = 17
minutes = 30 if not minutes:
minutes = 0
data = render_template('beer.html', hours=hours, minutes=minutes) data = render_template('beer.html', hours=hours, minutes=minutes)
return data return data
@app.route('/favicon.ico')
def default_favicon():
""" serve default favicon """
return send_from_directory('static', 'clock-icon.png')
@app.route('/favicon/<mode>')
def favicon(mode):
""" serve the favicon according to the timer """
if mode == 'beer':
filename = 'beer-icon.png'
else:
filename = 'clock-icon.png'
return send_from_directory('static', filename)
def main(): def main():
""" main func """ """ main func """

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

View file

@ -32,23 +32,20 @@
<p id="demo"></p> <p id="demo"></p>
<script> <script>
(function() {
const changeFavicon = link => { var blinks = document.getElementsByTagName('blink');
let $favicon = document.querySelector('link[rel="icon"]') var visibility = 'hidden';
// If a <link rel="icon"> element already exists, window.setInterval(function() {
// change its href to the given link. for (var i = blinks.length - 1; i >= 0; i--) {
if ($favicon !== null) { blinks[i].style.visibility = visibility;
$favicon.href = link }
// Otherwise, create a new element and append it to <head>. visibility = (visibility === 'visible') ? 'hidden' : 'visible';
} else { }, 250);
$favicon = document.createElement("link") })();
$favicon.rel = "icon" </script>
$favicon.href = link <script>
document.head.appendChild($favicon)
}
}
// Update the count down every 1 second // Update the count down every 1 second
var x = setInterval(function() { var x = setInterval(function() {
// Get today's date and time // Get today's date and time
@ -72,8 +69,7 @@ var x = setInterval(function() {
// If the count down is finished, write some text // If the count down is finished, write some text
if (distance < 0) { if (distance < 0) {
clearInterval(x); clearInterval(x);
document.getElementById("demo").innerHTML = '<span class="blink">BEER TIME !</span>'; document.getElementById("demo").innerHTML = "<blink>BEER TIME !</blink>";
changeFavicon('/favicon/beer')
} }
}, 1000); }, 1000);
</script> </script>

View file

@ -3,34 +3,20 @@ if [ ${BRANCH} == 'master' ]; then
else else
TEST_URL='http://staging.beer.k3s.kleph.eu' TEST_URL='http://staging.beer.k3s.kleph.eu'
fi fi
echo "testing URL: ${TEST_URL}"
while :
do
status_code=$(curl -o /dev/null -s -w '%{http_code}' ${TEST_URL})
echo "status code: ${status_code}"
[[ ${status_code} -eq 200 ]] && break
[[ ${i} -gt 5 ]] && exit 1
echo "service not ready or in error"
sleep 5
i=$(( i+1 ))
done
CURL_OPTS='-s' CURL_OPTS='-s'
# default # default
curl ${CURL_OPTS} ${TEST_URL} | grep -q 'setHours( 17, 30);' curl ${CURL_OPTS} ${TEST_URL} | grep -q 'setHours( 17, 0);'
[ $? -ne 0 ] && echo "Failed with default" && exit 1 [ $? -ne 0 ] && exit 1
# set 1 parameter # set 1 parameter
hours=18 hours=18
curl ${CURL_OPTS} ${TEST_URL}/${hours} | grep -q "setHours( ${hours}, 0);" curl ${CURL_OPTS} ${TEST_URL}/${hours} | grep -q "setHours( ${hours}, 0);"
[ $? -ne 0 ] && echo "Failed with 1 parameter set" && exit 1 [ $? -ne 0 ] && exit 1
# set 2 parameters # set 2 parameters
minutes=30 minutes=30
curl ${CURL_OPTS} ${TEST_URL}/${hours}/${minutes} | grep -q "setHours( ${hours}, ${minutes});" curl ${CURL_OPTS} ${TEST_URL}/${hours}/${minutes} | grep -q "setHours( ${hours}, ${minutes});"
[ $? -ne 0 ] && echo "Failed with 2 parameters set" && exit 1 [ $? -ne 0 ] && exit 1
echo "OK"
exit 0 exit 0