diff --git a/.gitignore b/.gitignore index 8e24f68bd..8d73fa70f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ Gemfile.lock docs/_site/ node_modules static/**/*.gz +.gitversion \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b07c67001..2d0002db2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" && \ @@ -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 diff --git a/terrariumEngine.py b/terrariumEngine.py index ce44f557d..2df3044e3 100644 --- a/terrariumEngine.py +++ b/terrariumEngine.py @@ -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']: diff --git a/terrariumWebserver.py b/terrariumWebserver.py index 082f19f60..9801bcc04 100644 --- a/terrariumWebserver.py +++ b/terrariumWebserver.py @@ -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(), diff --git a/views/includes/footer.html b/views/includes/footer.html index 03167b137..c8f5160b0 100644 --- a/views/includes/footer.html +++ b/views/includes/footer.html @@ -9,7 +9,9 @@          -    {{title}} {{version}} - {{device}} - + +    {{title}} {{version}} - {{device}} - {% if authenticated %}{{gitversion[0:8]}} -{% endif %} + Terrarium home automation diff --git a/views/layouts/base.html b/views/layouts/base.html index d965f4aee..6414c41e2 100644 --- a/views/layouts/base.html +++ b/views/layouts/base.html @@ -1,14 +1,14 @@ + {% if authenticated %}{% endif %} {% block title %}{% endblock %} - {{ title }} - {{ version }} - {% if not ajax %} - + {% if not ajax %}