Skip to content

Commit

Permalink
release v0.11.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kikkomep committed Dec 7, 2023
2 parents 222c1e2 + 4876494 commit 3bb40b3
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 163 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
python-version: ["3.11"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
Expand All @@ -53,7 +53,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
python-version: ["3.11"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
Expand Down Expand Up @@ -96,6 +96,7 @@ jobs:
echo "Current Software Version: ${sw_version}"
echo "SOFTWARE_VERSION=${sw_version}" >> $GITHUB_ENV
echo "SOFTWARE_VERSION_AS_DOCKER_TAG=$( echo ${sw_version} | tr + _ )" >> $GITHUB_ENV
echo "USE_SOFTWARE_VERSION=$( if [[ $(git tag --points-at HEAD) ]]; then echo true; else echo false; fi )" >> $GITHUB_ENV
# Set Docker image
- name: Set Docker repository
run: |
Expand All @@ -111,10 +112,11 @@ jobs:
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG }}
type=raw,value=${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG}}.build${{ github.run_number }}
type=semver,enable=${{env.USE_SOFTWARE_VERSION}},pattern={{version}}
type=semver,enable=${{env.USE_SOFTWARE_VERSION}},event=tag,pattern={{major}}.{{minor}}
type=semver,enable=${{env.USE_SOFTWARE_VERSION}},pattern={{major}}.{{minor}}.build${{ github.run_number }}
type=raw,event=tag,value=${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG }}
type=raw,event=tag,value=${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG}}.build${{ github.run_number }}
type=sha
labels: |
org.opencontainers.image.version=${{ env.SOFTWARE_VERSION }}.build${{ github.run_number }}
Expand Down
2 changes: 1 addition & 1 deletion k8s/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version: 0.11.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.11.8
appVersion: 0.11.9

# Chart dependencies
dependencies:
Expand Down
12 changes: 11 additions & 1 deletion k8s/templates/console.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ spec:
- name: LIFEMONITOR_MAINTENANCE_MODE
value: {{ .Values.maintenanceMode.enabled | quote }}
- name: LIFEMONITOR_CONSOLE_ENABLED
value: {{ .Values.console.enabled | quote }}
value: {{ .Values.console.enabled | quote }}
volumeMounts:
{{- include "lifemonitor.common-volume-mounts" . | nindent 12 }}
- name: lifemonitor-backup
mountPath: "/var/data/backup"
{{- if .Values.backup.encryptionKeySecret }}
- name: lifemonitor-backup-encryption-key
mountPath: "/lm/backup/encryption.key"
subPath: encryptionKey
{{- end }}
ports:
- name: http
containerPort: 8000
Expand All @@ -57,6 +62,11 @@ spec:
- name: lifemonitor-backup
persistentVolumeClaim:
claimName: {{ .Values.backup.existingClaim }}
{{- if .Values.backup.encryptionKeySecret }}
- name: lifemonitor-backup-encryption-key
secret:
secretName: {{ .Values.backup.encryptionKeySecret }}
{{- end }}
{{- include "lifemonitor.common-volume" . | nindent 8 }}
{{- with .Values.lifemonitor.nodeSelector }}
nodeSelector:
Expand Down
150 changes: 82 additions & 68 deletions lifemonitor/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
"""Git implementation of _version.py."""

import errno
import logging
import os
import re
import subprocess
import sys

# define logger
logger = logging.getLogger(__name__)


def get_keywords():
"""Get the keywords needed to look up the version information."""
Expand Down Expand Up @@ -85,18 +89,19 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % dispcmd)
print(e)
logger.debug("unable to run %s", dispcmd)
if logger.isEnabledFor(logging.DEBUG):
logger.exception(e)
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
logger.error("unable to find command, tried %s", (commands,))
return None, None
stdout = p.communicate()[0].strip().decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % dispcmd)
print("stdout was %s" % stdout)
logger.error("unable to run %s (error)", dispcmd)
logger.error("stdout was %s", stdout)
return None, p.returncode
return stdout, p.returncode

Expand Down Expand Up @@ -233,70 +238,71 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
print("Directory %s not under git control" % root)
raise NotThisMethod("'git rev-parse --git-dir' returned error")

# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
"--always", "--long",
"--match", "%s*" % tag_prefix],
cwd=root)
# init pieces to store git information
pieces = {}

# try to extract the current branch
branch, rc = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root, hide_stderr=True)
if not branch:
if verbose:
print("Unable to detect git branch")
raise NotThisMethod("'git rev-parse --abbrev-ref HEAD' returned error")
logger.debug("Detected branch: %s", branch)

# declare closest_tag
closest_tag = None

# get all tags sorted by date
all_tags_sorted, rc = run_command(GITS, ["for-each-ref", "--sort=creatordate", "--format='%(refname:short)'", "refs/tags"],
cwd=root)
logger.debug("all_tags_sorted: %r", all_tags_sorted)
if len(all_tags_sorted.splitlines()) == 0:
logger.warning("No tags found")
else:
closest_tag = all_tags_sorted.splitlines()[-1].strip("'")
logger.debug("Closest tag: %r", closest_tag)
pieces["closest-tag"] = closest_tag

# detect the branch of the closest tag
closest_tag_branch = None
if closest_tag is not None:
# get the commit hash of the tag
closest_tag_branch_out, rc = run_command(GITS, ["branch", f"--contains=tags/{closest_tag}"], cwd=root)
logger.debug("Closest Tag branch output: %r", closest_tag_branch_out)
if len(closest_tag_branch_out.splitlines()) == 0:
logger.warning("No branch found for tag %r", closest_tag)
else:
closest_tag_branch = closest_tag_branch_out.splitlines()[0].strip("* ")
logger.debug("Closest tag branch: %r", closest_tag_branch)
pieces["closest-tag-branch"] = closest_tag_branch

# --long was added in git-1.5.5
if describe_out is None:
raise NotThisMethod("'git describe' failed")
describe_out = describe_out.strip()
full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
if full_out is None:
raise NotThisMethod("'git rev-parse' failed")
full_out = full_out.strip()

pieces = {}
pieces["branch"] = branch
pieces["long"] = full_out
pieces["short"] = full_out[:7] # maybe improved later
pieces["short"] = full_out[:7]
pieces["error"] = None

# parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
# TAG might have hyphens.
git_describe = describe_out
# compute distance to latest tag (if any) or to the master branch if no tags are found
distance = 0
distance_from = closest_tag if closest_tag and closest_tag_branch in ("master", branch) else "master"
distance_out, rc = run_command(GITS, ["rev-list", "%s..HEAD" % distance_from, "--count"], cwd=root)
if rc != 0:
distance_out, rc = run_command(GITS, ["rev-list", "origin/%s..HEAD" % distance_from, "--count"], cwd=root)
if distance_out is None:
logger.warning(f"Unable to detect distance from {distance_from}")
else:
distance = int(distance_out.strip())
logger.debug(f"Computed distance from '{distance_from}': %d", distance)
pieces["distance"] = distance

# look for -dirty suffix
dirty = git_describe.endswith("-dirty")
# compute dirty
dirty = True if distance > 0 else False
pieces["dirty"] = dirty
if dirty:
git_describe = git_describe[:git_describe.rindex("-dirty")]

# now we have TAG-NUM-gHEX or HEX

if "-" in git_describe:
# TAG-NUM-gHEX
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
pieces["error"] = ("unable to parse git-describe output: '%s'"
% describe_out)
return pieces

# tag
full_tag = mo.group(1)
if not full_tag.startswith(tag_prefix):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
% (full_tag, tag_prefix))
return pieces
pieces["closest-tag"] = full_tag[len(tag_prefix):]

# distance: number of commits since tag
pieces["distance"] = int(mo.group(2))

# commit: short hex revision ID
pieces["short"] = mo.group(3)

else:
# HEX: no tags
pieces["closest-tag"] = None
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
cwd=root)
pieces["distance"] = int(count_out) # total number of commits

# commit date: see ISO-8601 comment in git_versions_from_keywords()
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
Expand Down Expand Up @@ -325,19 +331,22 @@ def render_pep440(pieces):
Exceptions:
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
"""
# determine version name prefix
rendered = None
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += plus_or_dot(pieces)
rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"
else:
# exception #1
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
pieces["short"])
if pieces["branch"] in ("master", pieces["closest-tag-branch"]):
rendered = pieces["closest-tag"]
elif pieces["branch"] not in ("master", "develop"):
rendered = f"develop.{pieces['branch'].replace('/', '-')}"
else:
rendered = pieces["branch"]

if pieces["distance"] or pieces["dirty"]:
rendered += plus_or_dot(pieces)
rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"

return rendered


Expand Down Expand Up @@ -489,12 +498,15 @@ def get_versions():
verbose = cfg.verbose

try:
logger.debug("Trying keywords...")
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
verbose)
except NotThisMethod:
logger.debug("Not keywords")
pass

try:
logger.debug("Trying expanded keywords...")
root = os.path.realpath(__file__)
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
Expand All @@ -508,7 +520,9 @@ def get_versions():
"date": None}

try:
logger.debug("Trying pieces_from_vcs...")
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
logger.debug("pieces_from_vcs returned %r", pieces)
return render(pieces, cfg.style)
except NotThisMethod:
pass
Expand Down
34 changes: 31 additions & 3 deletions lifemonitor/api/models/registries/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
from __future__ import annotations

import logging
from typing import List

from flask_wtf import FlaskForm
from wtforms import HiddenField, ValidationError

from lifemonitor.auth import User
from wtforms import HiddenField

from .settings import RegistrySettings

Expand All @@ -38,10 +40,36 @@ def __get_registries__():
return WorkflowRegistry.all()


def __get_registries_names__() -> List[str]:
return [_.name for _ in __get_registries__()]


def validate_registry(registry_name: str) -> bool:
'''Validate the given registry name against the available registries'''
return registry_name in __get_registries_names__()


class RegistryNameValidator:

def __call__(self, form, field):
return self.validate(field.data)

@classmethod
def validate(cls, value: str) -> bool:
value_length = len(value) if value else 0
if value_length == 0:
return ValidationError("Registry name cannot be empty")
if not validate_registry(value):
return ValidationError("Registry not found")
logger.warning("Registry name '%s' is valid", value)
return True


class RegistrySettingsForm(FlaskForm):

action = HiddenField("action", description="")
registry = HiddenField("registry", description="")
action = HiddenField("action", description="The action to perform")
registry = HiddenField("registry",
description="Short name of the registry", validators=[RegistryNameValidator()])
registries = HiddenField("registries", description="")

available_registries = None
Expand Down
12 changes: 9 additions & 3 deletions lifemonitor/api/models/rocrate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def download_from_source(self, target_path: str = None, uri: str = None, version

# set target_path
if not target_path:
target_path = tempfile.mktemp(dir=BaseConfig.BASE_TEMP_FOLDER)
logger.warning("Target path is not defined: a temporary file will be created")
try:
# try either with authorization header and without authorization
for authorization in self._get_authorizations(extra_auth=extra_auth):
Expand All @@ -338,14 +338,20 @@ def download_from_source(self, target_path: str = None, uri: str = None, version
repo.checkout_ref(ref) # , branch_name=version)
logger.debug("Checkout DONE")
logger.debug(get_current_ref(tmp_path))
archive = repo.write_zip(target_path)
if target_path:
archive = repo.write_zip(target_path)
else:
with tempfile.NamedTemporaryFile(
dir=BaseConfig.BASE_TEMP_FOLDER,
delete=False) as tmp_file:
archive = repo.write_zip(tmp_file.name)
logger.debug("Zip file written to: %r", archive)
return archive, ref, commit
else:
auth_header = authorization.as_http_header() if authorization else None
logger.debug(auth_header)
local_zip = download_url(uri,
target_path=target_path,
target_path=target_path, # auto-generated if None
authorization=auth_header)
logger.debug("ZIP Archive: %s", local_zip)
return target_path, None, None
Expand Down
Loading

0 comments on commit 3bb40b3

Please sign in to comment.