Skip to content

Commit

Permalink
Add commit ID that is visible in docker as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoam authored and noam1023 committed Sep 13, 2022
1 parent 15f6148 commit 4cf5392
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions Dockerfile_py_base
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY requirements.txt .
RUN pip3 install -r requirements.txt && rm requirements.txt
COPY serverpkg /app/serverpkg/
COPY utils.py time /app/
COPY version.py /app

WORKDIR /app
EXPOSE 8000
Expand Down
3 changes: 3 additions & 0 deletions scripts/again.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/usr/bin/env bash

# save the commit ID into a file, so it can be used within the docker container
echo "commit_id='$(git rev-parse --short HEAD)'" > ../version.py
docker build -t server .. && ./restart_container.sh
10 changes: 9 additions & 1 deletion scripts/declare_env
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
#
#http://jobs.eastus.cloudapp.azure.com/
#mkdir -p ./logs

if [ "${BASH_SOURCE[0]}" -ef "$0" ]
then
echo "Hey, you should source this script, not execute it!"
exit 1
fi
export CHECKER_LOG_DIR=./logs
export CLUSTER_NAME=spark96224
export LIVY_PASS=%Qq12345678

export SECRET_SIG=
# path to the key file.
export SPARK_PKEY_PATH=/data/data/96224/spark_client
export STORAGE_NAME=noamcluster1hdistorage
export CHECKER_DATA_DIR=$PWD/../checker_data
5 changes: 4 additions & 1 deletion scripts/restart_container.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
docker-compose restart

# using 'restart' will keep using the old image. This is bad when we want to get the new one
docker-compose down
docker-compose up -d

8 changes: 2 additions & 6 deletions serverpkg/logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import os
import logging


def _in_docker():
with open('/proc/1/cgroup', 'rt') as ifh:
return 'docker' in ifh.read()
import utils


class Logger:
Expand All @@ -14,7 +10,7 @@ class Logger:
"""

def __init__(self, name):
if not _in_docker():
if not utils.in_docker():
self.log_path = "./logs/"
else:
self.log_path = os.environ['CHECKER_LOG_DIR'] # "/logs"
Expand Down
2 changes: 1 addition & 1 deletion serverpkg/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def unauthorized_message(e):
@app.route('/',methods = ['GET'])
def index():
import utils
footer_text = 'commit id: {}'.format(utils.commitId())
footer_text = 'commit id: {}'.format(utils.version_string())
return render_template('index.html', running_locally=_running_on_dev_machine(), motd = Motd().get_message(), footer= footer_text)


Expand Down
24 changes: 23 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,20 @@ def wrapped(*args, **kwargs):

return wrapped


def version_string():
"""Try to get the commit ID.
If running in docker, it is not available, so try using an env var"""
if in_docker():
import version
return version.commit_id
else:
return commitId()


def commitId() -> str:
""" try to get the current git commit Id
""" try to get the current git commit Id.
This will NOT run when inside a docker container.
:return short commit ID or empty string"""
import subprocess
id = ''
Expand All @@ -57,6 +69,16 @@ def load_allowed_submitters_id(fname: str)-> set:
pass
return s


def in_docker():
""":return True if running inside a docker container
https://www.baeldung.com/linux/is-process-running-inside-container
"""
with open('/proc/1/sched', 'rt') as ifh:
line = ifh.readline()
return 'systemd' not in line


if __name__ == "__main__":

@measure
Expand Down

0 comments on commit 4cf5392

Please sign in to comment.