Compare commits
28 commits
shellcheck
...
master
Author | SHA1 | Date | |
---|---|---|---|
3c014f3c4d | |||
7f970820d8 | |||
76228565aa | |||
3ccad58405 | |||
a51a2f8b7a | |||
1841998933 | |||
9694eb66b4 | |||
cb2552a7c3 | |||
96e3b7ae6d | |||
fe99c62d75 | |||
e86991fe75 | |||
9c3d4252d1 | |||
ff0bca9421 | |||
6ae863148f | |||
ad22413145 | |||
4e5cc46b28 | |||
092c5c82e8 | |||
86848b504f | |||
735b092de1 | |||
5133edbc52 | |||
1c713d46d9 | |||
990d3ac8bf | |||
fed0b11a24 | |||
0e2121294e | |||
d167fe1b52 | |||
fdc5423a8d | |||
9d05055acb | |||
a5fbeea615 |
7 changed files with 68 additions and 30 deletions
17
.drone.yml
17
.drone.yml
|
@ -16,20 +16,13 @@ steps:
|
|||
- name: w3c validator
|
||||
image: validator/validator:latest
|
||||
commands:
|
||||
- vnu static/*.html
|
||||
- /vnu-runtime-image/bin/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
|
||||
|
@ -60,6 +53,10 @@ steps:
|
|||
from_secret: dockerhub_username
|
||||
password:
|
||||
from_secret: dockerhub_password
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- pull_request
|
||||
|
||||
depends_on:
|
||||
- unit tests
|
||||
|
@ -109,6 +106,10 @@ steps:
|
|||
BRANCH: ${DRONE_COMMIT_BRANCH}
|
||||
commands:
|
||||
- bash staging_tests.sh
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- master
|
||||
|
||||
- name: deploy live
|
||||
image: sinlead/drone-kubectl
|
||||
|
|
|
@ -3,6 +3,7 @@ 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"]
|
||||
|
|
24
beer/beer.py
24
beer/beer.py
|
@ -4,24 +4,42 @@
|
|||
|
||||
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 not hours:
|
||||
hours = 17
|
||||
|
||||
if hours:
|
||||
if not minutes:
|
||||
minutes = 0
|
||||
else:
|
||||
hours = 17
|
||||
minutes = 30
|
||||
|
||||
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 """
|
||||
|
|
BIN
beer/static/beer-icon.png
Normal file
BIN
beer/static/beer-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
BIN
beer/static/clock-icon.png
Normal file
BIN
beer/static/clock-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
|
@ -32,20 +32,23 @@
|
|||
<p id="demo"></p>
|
||||
|
||||
<script>
|
||||
(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
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// Update the count down every 1 second
|
||||
var x = setInterval(function() {
|
||||
|
||||
// Get today's date and time
|
||||
|
@ -69,7 +72,8 @@ var x = setInterval(function() {
|
|||
// If the count down is finished, write some text
|
||||
if (distance < 0) {
|
||||
clearInterval(x);
|
||||
document.getElementById("demo").innerHTML = "<blink>BEER TIME !</blink>";
|
||||
document.getElementById("demo").innerHTML = '<span class="blink">BEER TIME !</span>';
|
||||
changeFavicon('/favicon/beer')
|
||||
}
|
||||
}, 1000);
|
||||
</script>
|
||||
|
|
|
@ -3,20 +3,34 @@ 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, 0);'
|
||||
[ $? -ne 0 ] && exit 1
|
||||
curl ${CURL_OPTS} ${TEST_URL} | grep -q 'setHours( 17, 30);'
|
||||
[ $? -ne 0 ] && echo "Failed with default" && exit 1
|
||||
|
||||
# set 1 parameter
|
||||
hours=18
|
||||
curl ${CURL_OPTS} ${TEST_URL}/${hours} | grep -q "setHours( ${hours}, 0);"
|
||||
[ $? -ne 0 ] && exit 1
|
||||
[ $? -ne 0 ] && echo "Failed with 1 parameter set" && exit 1
|
||||
|
||||
# set 2 parameters
|
||||
minutes=30
|
||||
curl ${CURL_OPTS} ${TEST_URL}/${hours}/${minutes} | grep -q "setHours( ${hours}, ${minutes});"
|
||||
[ $? -ne 0 ] && exit 1
|
||||
[ $? -ne 0 ] && echo "Failed with 2 parameters set" && exit 1
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
|
|
Loading…
Reference in a new issue