Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Mount volume path as outer path in container
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Apr 17, 2017
1 parent ca6ac12 commit f9557d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions badwolf/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def run_in_container(self, docker_image_name):
'CI': 'true',
'CI_NAME': 'badwolf',
'BADWOLF_COMMIT': self.commit_hash,
'BADWOLF_BUILD_DIR': '/mnt/src',
'BADWOLF_BUILD_DIR': self.context.clone_path,
'BADWOLF_REPO_SLUG': self.context.repository,
'BADWOLF_SCRIPT': script,
})
Expand All @@ -187,7 +187,7 @@ def run_in_container(self, docker_image_name):

volumes = {
self.context.clone_path: {
'bind': '/mnt/src',
'bind': self.context.clone_path,
'mode': 'rw',
},
}
Expand All @@ -203,7 +203,7 @@ def run_in_container(self, docker_image_name):
entrypoint=['/bin/sh', '-c'],
command=['echo $BADWOLF_SCRIPT | base64 --decode | /bin/sh'],
environment=environment,
working_dir='/mnt/src',
working_dir=self.context.clone_path,
volumes=volumes,
privileged=self.spec.privileged,
stdin_open=False,
Expand Down
19 changes: 5 additions & 14 deletions badwolf/context.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import os
import uuid
import tempfile
import platform

from badwolf.utils import to_text

from flask import current_app

if platform.system() == 'Darwin':
# On macOS, tempfile.gettempdir function doesn't return '/tmp'
# But Docker for Mac can not mount the path returned by tempfile.gettempdir
# by default, so let's hardcode it to '/tmp'
TMP_PATH = '/tmp' # nosec
else:
TMP_PATH = tempfile.gettempdir()
from badwolf.utils import to_text


class Context(object):
Expand All @@ -39,8 +31,7 @@ def __init__(self, repository, actor, type, message, source, target=None,
self.source['repository'] = {'full_name': repository}

self.clone_path = os.path.join(
TMP_PATH,
'badwolf',
self.task_id,
current_app.config['BADWOLF_REPO_DIR'],
self.repo_name,
self.task_id,
)
14 changes: 13 additions & 1 deletion badwolf/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import sys
import base64
import tempfile
import platform

import raven

Expand Down Expand Up @@ -81,7 +83,17 @@
BITBUCKET_USERNAME = os.environ.get('BITBUCKET_USERNAME', '')
BITBUCKET_PASSWORD = os.environ.get('BITBUCKET_PASSWORD', '')

BADWOLF_LOG_DIR = os.environ.get('BADWOLF_LOG_DIR', '/var/lib/badwolf/log')
BADWOLF_DATA_DIR = os.environ.get('BADWOLF_DATA_DIR', '/var/lib/badwolf')
BADWOLF_LOG_DIR = os.environ.get('BADWOLF_LOG_DIR', os.path.join(BADWOLF_DATA_DIR, 'log'))
BADWOLF_REPO_DIR = os.environ.get('BADWOLF_REPO_DIR', os.path.join(BADWOLF_DATA_DIR, 'repos'))
if DEBUG:
if platform.system() == 'Darwin':
# On macOS, tempfile.gettempdir function doesn't return '/tmp'
# But Docker for Mac can not mount the path returned by tempfile.gettempdir
# by default, so let's hardcode it to '/tmp'
BADWOLF_REPO_DIR = '/tmp/badwolf' # nosec
else:
BADWOLF_REPO_DIR = os.path.join(tempfile.gettempdir(), 'badwolf')

# Sentry Release
try:
Expand Down

0 comments on commit f9557d0

Please sign in to comment.