Skip to content

Commit

Permalink
Fix the runs_in_docker flag. (#10522)
Browse files Browse the repository at this point in the history
* Pass in the branch and commit through env variables. Medusa didn't pick up the branch name.
* Fix setting the RUNS_IN_DOCKER flag. So we prevent from updating from within container.
  • Loading branch information
p0psicles authored Apr 22, 2022
1 parent aff50a3 commit 35d4104
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
8 changes: 8 additions & 0 deletions medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,17 @@ def initialize(self, console_logging=True):
# set current commit branch from environment variable, if needed
# use this to inject the branch information on immutable installations (e.g. Docker containers)
commit_branch_env = os.environ.get('MEDUSA_COMMIT_BRANCH')

if commit_branch_env and app.CUR_COMMIT_BRANCH != commit_branch_env:
app.CUR_COMMIT_BRANCH = commit_branch_env

if not app.BRANCH and app.CUR_COMMIT_BRANCH:
# Overwrite the current branch for non-git installations like docker.
app.BRANCH = app.CUR_COMMIT_BRANCH

# Asume we only have these environ variables when building a docker container.
app.RUNS_IN_DOCKER = os.environ.get('MEDUSA_COMMIT_HASH') and os.environ.get('MEDUSA_COMMIT_BRANCH')

app.ACTUAL_CACHE_DIR = check_setting_str(app.CFG, 'General', 'cache_dir', 'cache')

# fix bad configs due to buggy code
Expand Down
17 changes: 1 addition & 16 deletions medusa/updater/version_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,4 @@ def runs_in_docker():
if app.RUNS_IN_DOCKER is not None:
return app.RUNS_IN_DOCKER

path = '/proc/{pid}/cgroup'.format(pid=os.getpid())
try:
if not os.path.isfile(path):
return False

with open(path) as f:
for line in f:
if re.match(r'\d+:[\w=]+:/docker(-[ce]e)?/\w+', line):
log.debug(u'Running in a docker container')
app.RUNS_IN_DOCKER = True
return True
return False
except (EnvironmentError, OSError) as error:
log.info(u'Tried to check the path {path} if we are running in a docker container, '
u'but an error occurred: {error}', {'path': path, 'error': error})
return False
return os.environ.get('MEDUSA_COMMIT_HASH') and os.environ.get('MEDUSA_COMMIT_BRANCH')

0 comments on commit 35d4104

Please sign in to comment.