Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the runs_in_docker flag. #10522

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')