From 207b6535d80516f2d1fa5fa4d951499b8f71f7dd Mon Sep 17 00:00:00 2001 From: Dan Kolbman Date: Mon, 4 Nov 2019 13:29:10 -0500 Subject: [PATCH] :sparkles: Add status query --- Dockerfile | 5 +++++ coordinator/graphql/schema.py | 26 ++++++++++++++++++++++++-- coordinator/version_info.py | 10 ++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 coordinator/version_info.py diff --git a/Dockerfile b/Dockerfile index 88c24dc..f89ff07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,11 @@ RUN pip install awscli ADD . /app +# Bake version number +RUN COMMIT=`git rev-parse --short HEAD` && echo "COMMIT=\"${COMMIT}\"" > /app/coordinator/version_info.py \ + && VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >> /app/coordinator/version_info.py + + RUN python /app/setup.py install \ && python /app/manage.py collectstatic -v0 --noinput diff --git a/coordinator/graphql/schema.py b/coordinator/graphql/schema.py index 5b25d71..3d1fbe3 100644 --- a/coordinator/graphql/schema.py +++ b/coordinator/graphql/schema.py @@ -1,4 +1,5 @@ -from graphene import relay, ObjectType, Schema +from django.core.cache import cache +from graphene import relay, ObjectType, Field, Schema, String from graphene_django.types import DjangoObjectType from graphene_django.filter import DjangoFilterConnectionField @@ -14,6 +15,17 @@ from .users import Query as UserQuery +def get_version_info(): + from coordinator.version_info import COMMIT, VERSION + return {"commit": COMMIT, "version": VERSION} + + +class Status(ObjectType): + name = String() + version = String() + commit = String() + + class Query( ObjectType, ReleaseQuery, @@ -24,7 +36,17 @@ class Query( StudyQuery, UserQuery, ): - pass + status = Field(Status) + + def resolve_status(parent, info): + """ + Return status information about the coordinator. + """ + # Retrieve from cache in the case that we have to parse git commands + # to get version details. + info = cache.get_or_set("VERSION_INFO", get_version_info) + + return Status(name="Kids First Release Coordinator", **info) class Mutation( diff --git a/coordinator/version_info.py b/coordinator/version_info.py new file mode 100644 index 0000000..c20997d --- /dev/null +++ b/coordinator/version_info.py @@ -0,0 +1,10 @@ +# This file will be re-written during the Docker build. For development, the +# following defaults are provided. +import subprocess + +VERSION = subprocess.check_output( + ["git", "describe", "--always", "--tags"] +).strip().decode() +COMMIT = subprocess.check_output( + ["git", "rev-parse", "--short", "HEAD"] +).strip().decode()