Skip to content

Commit

Permalink
fix BUILD_ID empty hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
shokakucarrier committed Nov 11, 2021
1 parent affb6b3 commit cb62b39
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from setuptools import setup, find_packages
import sys

setup(
zip_safe=True,
use_2to3=False,
name='sidecarinit',
version='0.0.1',
long_description='sidecar-init container for download archive and decompress',
long_description='sidecar-init container for download archive and unzip',
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
Expand All @@ -26,4 +25,4 @@
'run-sidecar-init = sidecarinit:run'
],
}
)
)
24 changes: 17 additions & 7 deletions sidecarinit/commands.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import click
import os
import sys
import logging
from pathlib import Path
import sidecarinit.config as config
import sidecarinit.download as download

logger = logging.getLogger(__name__)


@click.command()
@click.argument('env_yml', required=False, default='/deployments/config/application.yaml') #help='Target environment, Same as sidecar application.yml'
@click.argument('env_yml', required=False,
default='/deployments/config/application.yaml')
# help='Target environment, Same as sidecar application.yml'
def run(env_yml):

suite = config.read_config(env_yml)

archive_name = '/' + os.environ.get('BUILD_ID') + '.zip'
archive_name = os.environ.get('BUILD_ID') + '.zip'

print('Downloading from :', suite.archive_api, ' to ' ,suite.local_repository)
logger.info('Downloading from : %s to %s .', suite.archive_api, suite.local_repository)
Path(suite.local_repository).mkdir(parents=True, exist_ok=True)
Path(suite.local_repository + archive_name ).touch(exist_ok=True)
Path(os.path.join(suite.local_repository, archive_name)).touch(exist_ok=True)

download.download_archive(suite.archive_api + archive_name, suite.local_repository)
if archive_name != '.zip':
download.download_archive(suite.archive_api + archive_name,
suite.local_repository)
else:
logger.info('BUILD_ID does not exist, exit now.')

sys.exit(0);
sys.exit(0)
9 changes: 5 additions & 4 deletions sidecarinit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
class Environment:
def __init__(self, env_spec):
self.archive_api = env_spec.get('sidecar').get(ENV_ARCHIVE_API)
self.local_repository = env_spec.get('sidecar').get(ENV_LOCAL_REPOSITORY).replace('${user.home}',os.environ.get('HOME')) or DEFAULT_LOCAL_REPOSITORY
self.local_repository = env_spec.get('sidecar').get(ENV_LOCAL_REPOSITORY).replace('${user.home}', os.environ.get('HOME')) or DEFAULT_LOCAL_REPOSITORY


def read_config(env_yml):
""" Read the suite configuration that this worker should run, from a config.yml file
(specified on the command line and passed in as a parameter here).
(specified on the command line and passed in as a parameter here).
Once we have a suite YAML file (from the suite_yml config), that file will be parsed
and passed back with the rest of the config values, in a Config object.
If any required configs are missing and don't have default values, error messages will
Expand All @@ -33,8 +34,8 @@ def read_config(env_yml):
yaml = YAML(typ='safe')
env_spec = yaml.load(f)
else:
errors.append( f"Missing test environment config file")
errors.append(f"Missing test environment config file")

env = Environment(env_spec)

return env
return env
5 changes: 3 additions & 2 deletions sidecarinit/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import shutil
import os

def download_archive(url,repository):

def download_archive(url, repository):
archive_name = "/" + os.environ.get('BUILD_ID') + '.zip'

with urllib.request.urlopen(url) as response, open(repository + archive_name, 'wb') as out_file:
shutil.copyfileobj(response, out_file)

shutil.unpack_archive(repository + archive_name, repository)
shutil.unpack_archive(repository + archive_name, repository)

0 comments on commit cb62b39

Please sign in to comment.