Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

WIP: Implement fetching of repo files defined in DOGEN_REPOS env variable #192

Open
wants to merge 1 commit into
base: dogen-ng
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions dogen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ def parse_args(self):
'template.jinja'),
help='Path to custom template (can be url)')

parser.add_argument('--repo-files-dir',
help='Provides path to directory with *.repo files that should be used to install rpms')

parser.add_argument('descriptor_path',
help="Path to yaml descriptor to process")

Expand Down Expand Up @@ -93,7 +90,7 @@ def run(self):
self.args.target,
self.args.overrides)
generator.prepare_modules()
generator.prepare_repositories(self.args.repo_files_dir)
generator.prepare_repositories()
generator.render_dockerfile(self.args.template)
generator.fetch_artifacts()
except KeyboardInterrupt as e:
Expand Down
9 changes: 3 additions & 6 deletions dogen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def render_dockerfile(self, template_file):
f.write(template.render(self.effective_descriptor.descriptor).encode('utf-8'))
logger.debug("Done")

def prepare_repositories(self, repo_files_dir):
"""Udates descriptor with added repositories"""
self.descriptor['additional_repos'] = \
tools.prepare_external_repositories(repo_files_dir,
os.path.join(self.target,
'image'))
def prepare_repositories(self):
"""Updates descriptor with added repositories"""
self.descriptor['additional_repos'] = tools.prepare_repositories(os.path.join(self.target, 'image'))
31 changes: 22 additions & 9 deletions dogen/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def fetch(self):
return self
logger.debug("Fetching '%s' as %s" % (self.url, destination))

download_file(self.url, destination)

res = requests.get(self.url, verify=self.ssl_verify, stream=True)
if res.status_code != 200:
raise DogenError("Could not download file from %s" % self.url)
Expand All @@ -103,19 +105,30 @@ def fetch(self):
return self


def prepare_external_repositories(repo_files_dir, image_dir):
if not os.path.exists(repo_files_dir):
raise DogenError("Directory '%s' with additional repository definitions doesn't exist!"
% repo_files_dir)
def download_file(url, destination):
res = requests.get(url, verify=False, stream=True)
if res.status_code != 200:
raise DogenError("Could not download file from %s" % url)
with open(destination, 'wb') as f:
for chunk in res.iter_content(chunk_size=1024):
f.write(chunk)

def prepare_repositories(image_dir):
repos = os.getenv("DOGEN_REPOS")

if not repos:
return

destination = os.path.join(image_dir, 'repos')
os.makedirs(destination)

for repo in repos.split(','):
download_file(repo, os.path.join(destination, repo.split('/')[-1]))

added_repos = []
repo_files = glob.glob(os.path.join(repo_files_dir, "*.repo"))
target_dir = os.path.join(image_dir, 'repos')
os.makedirs(target_dir)
repo_files = glob.glob(os.path.join(destination, "*.repo"))

for f in repo_files:
logger.info("Copying %s repo file..." % os.path.basename(f))
shutil.copy2(f, target_dir)
added_repos.append(os.path.splitext(os.path.basename(f))[0])

return added_repos
Expand Down