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

View file

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

View file

@ -4,42 +4,24 @@
from flask import Flask
from flask import render_template
from flask import send_from_directory
# pylint: disable=invalid-name
app = Flask(__name__)
app.url_map.strict_slashes = False
@app.route('/')
@app.route('/<int(min=0, max=23):hours>')
@app.route('/<int(min=0, max=23):hours>/<int(min=0, max=59):minutes>')
def index(hours=None, minutes=None):
""" main and only app """
if hours:
if not minutes:
minutes = 0
else:
if not hours:
hours = 17
minutes = 30
if not minutes:
minutes = 0
data = render_template('beer.html', hours=hours, minutes=minutes)
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():
""" 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>
<script>
const changeFavicon = link => {
let $favicon = document.querySelector('link[rel="icon"]')
// If a <link rel="icon"> element already exists,
// change its href to the given link.
if ($favicon !== null) {
$favicon.href = link
// Otherwise, create a new element and append it to <head>.
} else {
$favicon = document.createElement("link")
$favicon.rel = "icon"
$favicon.href = link
document.head.appendChild($favicon)
}
}
(function() {
var blinks = document.getElementsByTagName('blink');
var visibility = 'hidden';
window.setInterval(function() {
for (var i = blinks.length - 1; i >= 0; i--) {
blinks[i].style.visibility = visibility;
}
visibility = (visibility === 'visible') ? 'hidden' : 'visible';
}, 250);
})();
</script>
<script>
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
@ -72,8 +69,7 @@ var x = setInterval(function() {
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = '<span class="blink">BEER TIME !</span>';
changeFavicon('/favicon/beer')
document.getElementById("demo").innerHTML = "<blink>BEER TIME !</blink>";
}
}, 1000);
</script>

View file

@ -3,34 +3,20 @@ if [ ${BRANCH} == 'master' ]; then
else
TEST_URL='http://staging.beer.k3s.kleph.eu'
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'
# default
curl ${CURL_OPTS} ${TEST_URL} | grep -q 'setHours( 17, 30);'
[ $? -ne 0 ] && echo "Failed with default" && exit 1
curl ${CURL_OPTS} ${TEST_URL} | grep -q 'setHours( 17, 0);'
[ $? -ne 0 ] && exit 1
# set 1 parameter
hours=18
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
minutes=30
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