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

Commit

Permalink
MGMT-1163 Added skipper build
Browse files Browse the repository at this point in the history
Added python requirements and dev-requirements
Added pylint and pep3 checks
Fixed pep and pylint errors
Renamed the python file to render_files.py
Removed deprecated dockerfile

f
  • Loading branch information
eranco74 committed Jun 18, 2020
1 parent 42c8223 commit 5f8e273
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 55 deletions.
407 changes: 407 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions Dockerfile

This file was deleted.

9 changes: 9 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3

COPY requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt

COPY dev-requirements.txt /tmp/dev-requirements.txt
RUN pip install -r /tmp/dev-requirements.txt

RUN rm /tmp/*requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ RUN chmod 777 $WORK_DIR

# [TODO] - change this line to use openshift-installer from the release, once we are ready
COPY --from=0 /root/installer/openshift-install $WORK_DIR
COPY ./process-ignition-manifests-and-kubeconfig.py $WORK_DIR
COPY ./render_files.py $WORK_DIR

ENV WORK_DIR=$WORK_DIR

ENV EXEC_PATH=$WORK_DIR/process-ignition-manifests-and-kubeconfig.py
ENTRYPOINT python $EXEC_PATH
ENV EXEC_PATH=$WORK_DIR/render_files.py
ENTRYPOINT python $EXEC_PATH
2 changes: 2 additions & 0 deletions Dockerfile.installer-image
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#This dockerfile require an openshift installer binary in CWD
FROM alpine:latest
RUN mkdir /root/installer
COPY ./openshift-install /root/installer

7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: pep8 pylint build

build:
skipper build ignition-manifests-and-kubeconfig-generate

.DEFAULT:
skipper -v $(MAKE) $@
14 changes: 14 additions & 0 deletions Makefile.skipper
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
all: pep8 pylint

pep8:
pep8 --max-line-length=145 render_files.py

pylint:
mkdir -p reports
PYLINTHOME=reports/ pylint render_files.py

clean:
rm -rf build dist *egg-info ./__pycache__
find -name *.pyc -delete

.PHONY: pep8 pylint clean
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pep8
pylint
81 changes: 38 additions & 43 deletions process-ignition-manifests-and-kubeconfig.py → render_files.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
#!/usr/bin/env python

import argparse
import json
import logging
import subprocess
import random
import sys
import os
import boto3
from botocore.exceptions import NoCredentialsError
from base64 import b64decode
import logging
import argparse
import sys
import json


def get_s3_client(s3_endpoint_url):
aws_access_key_id = os.environ.get("aws_access_key_id", "accessKey1")
aws_secret_access_key = os.environ.get("aws_secret_access_key", "verySecretKey1")

aws_access_key_id = os.environ.get("aws_access_key_id", "accessKey1")
aws_secret_access_key = os.environ.get("aws_secret_access_key", "verySecretKey1")

s3 = boto3.client(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
endpoint_url=s3_endpoint_url
)
return s3
s3_client = boto3.client(
's3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
endpoint_url=s3_endpoint_url
)
return s3_client


def upload_to_aws(s3, local_file, bucket, s3_file):
def upload_to_aws(s3_client, local_file, bucket, s3_file):
try:
s3.upload_file(local_file, bucket, s3_file, ExtraArgs={'ACL': 'public-read'})
s3_client.upload_file(local_file, bucket, s3_file, ExtraArgs={'ACL': 'public-read'})
print("Upload Successful")
return True
except NoCredentialsError:
Expand All @@ -38,43 +35,43 @@ def upload_to_aws(s3, local_file, bucket, s3_file):

def remove_bmo_provisioning(ignition_file):
found = False
with open(ignition_file, "r") as f:
data = json.load(f)
storageFiles = data['storage']['files']
with open(ignition_file, "r") as file_obj:
data = json.load(file_obj)
storage_files = data['storage']['files']
# Iterate through a copy of the list
for fileData in storageFiles[:]:
if 'baremetal-provisioning-config' in fileData['path']:
storageFiles.remove(fileData)
for file_data in storage_files[:]:
if 'baremetal-provisioning-config' in file_data['path']:
storage_files.remove(file_data)
found = True
break
if found:
with open(ignition_file,"w") as f:
json.dump(data, f)
with open(ignition_file, "w") as file_obj:
json.dump(data, file_obj)


def upload_to_s3(s3_endpoint_url, bucket, install_dir):
s3 = get_s3_client(s3_endpoint_url)
s3_client = get_s3_client(s3_endpoint_url)
prefix = os.environ.get("CLUSTER_ID")

for root, _, files in os.walk(install_dir):
for f in files:
logging.info("Uplading file: {}".format(f))
file_path = os.path.join(root, f)
if f == "kubeconfig":
f = "kubeconfig-noingress"
s3_file_name = "{}/{}".format(prefix, f)
for file_name in files:
logging.info("Uploading file: %s", file_name)
file_path = os.path.join(root, file_name)
if file_name == "kubeconfig":
file_name = "kubeconfig-noingress"
s3_file_name = "{}/{}".format(prefix, file_name)
print(s3_file_name)
uploaded = upload_to_aws(s3, file_path, bucket, s3_file_name)
upload_to_aws(s3_client, file_path, bucket, s3_file_name)


def debug_print_upload_to_s3(install_dir):
prefix = "dummy_cluster_id"
for root, _, files in os.walk(install_dir):
for f in files:
file_path = os.path.join(root, f)
if f == "kubeconfig":
f = "kubeconfig-noingress"
s3_file_name = "{}/{}".format(prefix, f)
for file_name in files:
file_path = os.path.join(root, file_name)
if file_name == "kubeconfig":
file_name = "kubeconfig-noingress"
s3_file_name = "{}/{}".format(prefix, file_name)
print("Uploading file %s as object %s" % (file_path, s3_file_name))


Expand All @@ -92,9 +89,8 @@ def main():
config_dir = os.path.join(work_dir, "installer_dir")
if install_config:
subprocess.check_output(["mkdir", "-p", config_dir])
with open(os.path.join(config_dir, 'install-config.yaml'), 'w+') as f:
f.write(install_config)

with open(os.path.join(config_dir, 'install-config.yaml'), 'w+') as file_obj:
file_obj.write(install_config)
if not os.path.isdir(config_dir):
raise Exception('installer directory is not mounted')

Expand All @@ -107,7 +103,6 @@ def main():
except Exception as ex:
raise Exception('Failed to generate files, exception: {}'.format(ex))


try:
remove_bmo_provisioning("%s/bootstrap.ign" % config_dir)
except Exception as ex:
Expand Down
Binary file not shown.
Binary file added reports/render_files1.stats
Binary file not shown.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3
botocore
3 changes: 3 additions & 0 deletions skipper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build-container-image: build
make:
makefile: Makefile.skipper

0 comments on commit 5f8e273

Please sign in to comment.