Skip to content

Commit

Permalink
Use OSCAR PVC instead of hostPath in kaniko builds
Browse files Browse the repository at this point in the history
  • Loading branch information
srisco committed Jan 9, 2020
1 parent 9f360ad commit b14dde3
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/providers/onpremises/clients/kaniko.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@

class KanikoClient():

namespace = 'kaniko-builds'
namespace = 'oscar'

def __init__(self, function_args):
self.registry_name = utils.get_environment_variable("DOCKER_REGISTRY")
self.function_args = function_args
self.function_image_folder = utils.join_paths(
self.function_image_folder = utils.get_random_uuid4_str()
self.function_image_path = utils.join_paths(
'/pv/kaniko-builds',
utils.get_random_uuid4_str())
self.function_image_folder)
self.root_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
self.job_name = '{0}-build-job'.format(function_args['name'])
self.job_name = '{0}-build'.format(function_args['name'])
self.registry_image_id = '{0}/{1}'.format(self.registry_name,
self.function_args['name'])

def _copy_dockerfile(self):
# Get function Dockerfile paths
Expand All @@ -40,7 +43,7 @@ def _copy_dockerfile(self):
'function_template',
'Dockerfile')
func_dockerfile_dest_path = utils.join_paths(
self.function_image_folder,
self.function_image_path,
'Dockerfile')
# Modify Dockerfile
with open(func_dockerfile_path, 'r') as f_in:
Expand All @@ -55,28 +58,28 @@ def _download_binaries(self):
utils.download_github_asset('openfaas',
'faas',
'fwatchdog',
self.function_image_folder)
fwatchdog_path = os.path.join(self.function_image_folder, 'fwatchdog')
self.function_image_path)
fwatchdog_path = os.path.join(self.function_image_path, 'fwatchdog')
fwatchdog_st = os.stat(fwatchdog_path)
os.chmod(fwatchdog_path, fwatchdog_st.st_mode | stat.S_IEXEC)
# Download faas-supervisor binary and set exec permissions
release = utils.get_environment_variable('SUPERVISOR_VERSION')
utils.download_github_asset('grycap',
utils.download_github_asset('grycap',
'faas-supervisor',
'supervisor',
self.function_image_folder,
self.function_image_path,
release=release)
supervisor_path = os.path.join(self.function_image_folder, 'supervisor')
supervisor_path = os.path.join(self.function_image_path, 'supervisor')
supervisor_st = os.stat(supervisor_path)
os.chmod(supervisor_path, supervisor_st.st_mode | stat.S_IEXEC)

def _copy_user_script(self):
utils.create_file_with_content(
utils.join_paths(self.function_image_folder, 'user_script.sh'),
utils.join_paths(self.function_image_path, 'user_script.sh'),
utils.base64_to_utf8_string(self.function_args['script']))

def _copy_required_files(self):
os.makedirs(self.function_image_folder, exist_ok=True)
os.makedirs(self.function_image_path, exist_ok=True)
# Get function Dockerfile paths
self._copy_dockerfile()
# Download required binaries
Expand All @@ -86,12 +89,10 @@ def _copy_required_files(self):

def _delete_image_files(self):
# Delete all the temporal files created for the image creation
utils.delete_folder(self.function_image_folder)
utils.delete_folder(self.function_image_path)

def _create_kaniko_job_definition(self):
self.registry_image_id = '{0}/{1}'.format(self.registry_name,
self.function_args['name'])
job = {
return {
'apiVersion': 'batch/v1',
'kind': 'Job',
'metadata': {
Expand Down Expand Up @@ -122,7 +123,8 @@ def _create_kaniko_job_definition(self):
'volumeMounts': [
{
'name': 'build-context',
'mountPath': '/workspace'
'mountPath': '/workspace',
'subPath': self.function_image_folder
}
]
}
Expand All @@ -131,17 +133,15 @@ def _create_kaniko_job_definition(self):
'volumes': [
{
'name': 'build-context',
'hostPath': {
'path': self.function_image_folder,
'type': 'Directory'
'persistentVolumeClaim': {
'claimName': 'oscar-pv-claim'
}
}
]
}
}
}
}
return job

def create_and_push_docker_image(self, kubernetes_client):
# Copy/create function required files
Expand Down

0 comments on commit b14dde3

Please sign in to comment.