Skip to content

Commit

Permalink
Add commit information to source code and footer when adming is logge…
Browse files Browse the repository at this point in the history
…d in. #637
  • Loading branch information
theyosh committed Apr 8, 2022
1 parent 9bda1b0 commit 3eb6bc7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Gemfile.lock
docs/_site/
node_modules
static/**/*.gz
.gitversion
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ RUN sed -i 's/opencv-python-headless/# opencv-python-headless/g' requirements.tx
pip install -r requirements.txt && \
find /opt/venv -type d -name "__pycache__" -exec rm -r {} +
WORKDIR /TerrariumPI
# we previously copied .git and then did git submodule init and submodule update, however as .git dir changes all the time it invalidates docker cache
# Set git version in a temp file
RUN git rev-parse HEAD > .gitversion
# Just clone the libraries, ignore docker cache...
RUN git clone https://github.com/SequentMicrosystems/4relay-rpi.git --depth 1 "3rdparty/4relay-rpi" && \
git clone https://github.com/PiSupply/Bright-Pi.git --depth 1 "3rdparty/Bright-Pi" && \
git clone https://github.com/ageir/chirp-rpi.git --depth 1 "3rdparty/chirp-rpi" && \
Expand All @@ -56,13 +58,14 @@ RUN git clone https://github.com/SequentMicrosystems/4relay-rpi.git --depth 1 "3
rm -Rf 3rdparty/Bright-Pi/Documents && \
find . -type d -name ".git" -exec rm -r {} +

# remove git and 3rdparty dir from code copy to help keep image smaller
# 3rdparty is coming from the builder image

FROM python:3.8-buster as sourcecode
WORKDIR /TerrariumPI
COPY . .
# remove git and 3rdparty dir from code copy to help keep image smaller
# 3rdparty is coming from the builder image
RUN rm -Rf .git 3rdparty
# Compress HTML, JS and CSS files so browsers can download compressed versions of the files
RUN find static/assets/ -type f -regex ".*\.\(css\|js\)" -exec gzip -f9k '{}' \;

# actual image
Expand Down
12 changes: 12 additions & 0 deletions terrariumEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ def load_settings(self):
# Loading active language
gettext.translation('terrariumpi', 'locales/', languages=[self.settings['language']]).install()

# TODO: Loading git data
gitversion = Path('.gitversion')
if gitversion.exists():
gitversion = gitversion.read_text().strip()
elif Path('.git').exists():
gitversion = str(terrariumUtils.get_script_data('git rev-parse HEAD')).strip()
else:
gitversion = None

print(f'Setting git version to: {gitversion}')
self.settings['gitversion'] = gitversion

# Loading weather
if 'weather_source' in self.settings:
if '' != self.settings['weather_source']:
Expand Down
1 change: 1 addition & 0 deletions terrariumWebserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def unit_variables():
'username' : self.engine.settings['username'],
'profile_image' : self.engine.settings['profile_image'],
'favicon' : self.engine.settings['favicon'],
'gitversion' : self.engine.settings['gitversion'],

'languages' : self.engine.settings['languages'],
'units' : unit_variables(),
Expand Down
4 changes: 3 additions & 1 deletion views/includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<small class="badge badge-success opacity-1" title="{{ _('Current activity') }}">&nbsp;&nbsp;</small>
<small class="badge badge-warning opacity-1" title="{{ _('Warning messages') }}">&nbsp;&nbsp;</small>
<small class="badge badge-danger opacity-1" title="{{ _('Error messages') }}">&nbsp;&nbsp;</small>
<span class="d-none d-sm-inline">&nbsp;&nbsp; {{title}} {{version}} - <small>{{device}} -</span>

<span class="d-none d-sm-inline">&nbsp;&nbsp; {{title}} {{version}} - <small>{{device}} - {% if authenticated %}<a href="https://github.com/theyosh/TerrariumPI/commit/{{gitversion}}" target="_blank" title="Git commit">{{gitversion[0:8]}}</a> -{% endif %}</span>

<a href="https://github.com/theyosh/TerrariumPI" target="_blank" rel="noopener" title="Download TerrariumPI on Github">Terrarium home automation</a>
</small>
</div>
Expand Down
4 changes: 2 additions & 2 deletions views/layouts/base.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html lang="{{ lang[:2] }}">
<head>
{% if authenticated %}<!-- Commit version: {{gitversion[0:8]}} | https://github.com/theyosh/TerrariumPI/commit/{{gitversion}} -->{% endif %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="{{favicon}}" type="image/x-icon">
<title>
{% block title %}{% endblock %} - {{ title }} - {{ version }}
</title>
{% if not ajax %}
<!-- jQuery -->
{% if not ajax %}<!-- jQuery -->
<script src="/static/assets/plugins/jquery/jquery.min.js"></script>
<!-- Google Font: Source Sans Pro -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
Expand Down

0 comments on commit 3eb6bc7

Please sign in to comment.