Skip to content

Commit

Permalink
Update deployment (#726)
Browse files Browse the repository at this point in the history
* Update deployment to handle gwml2 and show gwml2 version

* Also setup version of geonode and igrac
  • Loading branch information
meomancer authored Oct 7, 2024
1 parent 5e669f4 commit 0815126
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 34 deletions.
13 changes: 11 additions & 2 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ RUN apt-get install -y libreoffice

WORKDIR /

ENV GEONODE_VERSION 4.1.1.igrac
RUN rm -r /usr/src/geonode
RUN git clone --branch 4.1.1.igrac --single-branch https://github.com/kartoza/geonode.git geonode
RUN git clone --branch 4.9.1 https://github.com/kartoza/IGRAC-WellAndMonitoringDatabase.git /home/web/django_project/gwml2
RUN git clone --branch $GEONODE_VERSION --single-branch https://github.com/kartoza/geonode.git geonode

WORKDIR /geonode

Expand All @@ -33,6 +33,15 @@ RUN rm /usr/local/lib/python3.10/dist-packages/avatar/migrations/0002_auto_20200
#USER www-data
ADD django_project /home/web/django_project
WORKDIR /home/web/django_project
RUN rm -rf /home/web/django_project/gwml2

# Installing gwml2
ENV GWML2_VERSION 4.9.1
RUN git clone --branch $GWML2_VERSION https://github.com/kartoza/IGRAC-WellAndMonitoringDatabase.git /home/web/django_project/gwml2
RUN echo $GWML2_VERSION > /home/web/django_project/gwml2/version.txt

# Add geonode version
RUN echo $GEONODE_VERSION > /home/web/django_project/version/geonode_version.txt

# Open port 8080 as we will be running our uwsgi socket on that
#EXPOSE 8080
Expand Down
116 changes: 86 additions & 30 deletions django_project/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,92 @@

import os

DJANGO_ROOT = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)


def return_version_from_file(_file):
"""Retun version from file"""
if os.path.exists(_file):
version = (open(_file, 'rb').read()).decode("utf-8")
if version:
return version
return None


def project_version(request):
""" Read project version from file"""
DJANGO_ROOT = os.path.dirname(
os.path.dirname(
os.path.dirname(os.path.abspath(__file__))
))
folder = os.path.join(
DJANGO_ROOT, 'django_project', 'version')
version = os.path.join(
folder, 'version.txt')
if os.path.exists(version):
version = (open(version, 'rb').read()).decode("utf-8")
if version:
return {
'IGRAC_VERSION': {
'url': 'https://github.com/kartoza/IGRAC-GGIS/releases/tag/{}'.format(version),
'name': version
}

}
commit = os.path.join(
folder, 'commit.txt')
if os.path.exists(commit):
commit = (open(commit, 'rb').read()).decode("utf-8")
if commit:
return {
'IGRAC_VERSION': {
'url': 'https://github.com/kartoza/IGRAC-GGIS/commit/{}'.format(commit),
'name': commit
}
}
return {}
version = igrac_version()
_geonode_version = geonode_version()
if _geonode_version:
_geonode_version = _geonode_version.replace(
'-igrac', ''
).replace(
'.igrac', ''
)
else:
_geonode_version = 'unknown'

if version:
return {
'IGRAC_VERSION': {
'url': (
f'https://github.com/kartoza/IGRAC-GGIS/'
f'releases/tag/{version}'
),
'name': version
},
'GEONODE_VERSION': _geonode_version
}

commit = igrac_commit()
if commit:
return {
'IGRAC_VERSION': {
'url': (
f'https://github.com/kartoza/IGRAC-GGIS/commit/{commit}'
),
'name': commit
},
'GEONODE_VERSION': _geonode_version
}
return {
'GEONODE_VERSION': _geonode_version
}


def geonode_version():
"""Return geonode version."""
return return_version_from_file(
os.path.join(
DJANGO_ROOT, 'django_project', 'version', 'geonode_version.txt'
)
)


def igrac_version():
"""Return igrac version."""
return return_version_from_file(
os.path.join(
DJANGO_ROOT, 'django_project', 'version', 'version.txt'
)
)


def igrac_commit():
"""Return igrac commit."""
return return_version_from_file(
os.path.join(
DJANGO_ROOT, 'django_project', 'version', 'commit.txt'
)
)


def gwml2_version():
"""Read gwml2 version from file."""
return return_version_from_file(
os.path.join(
DJANGO_ROOT, 'django_project', 'gwml2', 'version.txt'
)
)
10 changes: 9 additions & 1 deletion django_project/igrac/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ class MapSlugMappingAdmin(SortableAdmin):


admin.site.register(MapSlugMapping, MapSlugMappingAdmin)
admin.site.register(SitePreference, PreferencesAdmin)


class CustomPreferencesAdmin(PreferencesAdmin):
"""Custom of preferences admin."""

readonly_fields = ('geonode_version', 'igrac_version', 'gwml2_version')


admin.site.register(SitePreference, CustomPreferencesAdmin)

admin.site.unregister(Profile)

Expand Down
16 changes: 16 additions & 0 deletions django_project/igrac/models/site_preference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from preferences.models import Preferences

from core.middleware import gwml2_version, igrac_version, geonode_version
from geonode.layers.models import Dataset


Expand Down Expand Up @@ -38,3 +39,18 @@ class SitePreference(Preferences):
upload_to='images',
null=True, blank=True,
)

@property
def geonode_version(self):
"""Return the Geonode version."""
return geonode_version()

@property
def igrac_version(self):
"""Return the IGRAC version."""
return igrac_version()

@property
def gwml2_version(self):
"""Return the GWML2 version."""
return gwml2_version()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="footer-item"
style="position: absolute; top: 8px; left: 7px;">{% trans "Version" %}
<a href="{{ IGRAC_VERSION.url }}">{{ IGRAC_VERSION.name }}</a>
<span style="font-size: 0.6rem; color: #888888"> (geonode 4.1.1)</span>
<span style="font-size: 0.6rem; color: #888888"> (geonode {{ GEONODE_VERSION }})</span>
</div>
{% endif %}
<div style="margin-left: auto; margin-right: auto; display: flex">
Expand Down

0 comments on commit 0815126

Please sign in to comment.