Beispiel #1
0
 def test_given_a_dockerfile_without_healthcheck_when_fix_then_instruction_with_healthcheck_is_generated(
         self):
     instructions = DockerfileService.parse_dockerfile(
         self, 'test/resources/Dockerfile_basic_with_comments')
     check_result = DockerfileService.evaluate_dockerfile(
         self, instructions)
     result = DockerfileService.get_dockerfile_fixes(self, check_result)
     healthcheck_instruction = list(
         filter(lambda x: x['instruction'] == 'HEALTHCHECK', result))
     self.assertEqual(len(healthcheck_instruction), 1)
Beispiel #2
0
 def test_given_a_dockerfile_with_two_apt_get_when_fix_then_one_instruction_with_apt_get_is_generated(
         self):
     instructions = DockerfileService.parse_dockerfile(
         self, 'test/resources/Dockerfile_with_two_apt-get')
     check_result = DockerfileService.evaluate_dockerfile(
         self, instructions)
     result = DockerfileService.get_dockerfile_fixes(
         self, check_result, instructions)
     apt_get_instructions = list(
         filter(lambda x: x['instruction'] == 'COPY', result))
     self.assertEqual(len(apt_get_instructions), 1)
Beispiel #3
0
 def test_given_a_dockerfile_with_wrong_add_usage_when_fix_then_instruction_with_copy_is_generated(
         self):
     instructions = DockerfileService.parse_dockerfile(
         self, 'test/resources/Dockerfile_wrong_ADD_usage')
     check_result = DockerfileService.evaluate_dockerfile(
         self, instructions)
     result = DockerfileService.get_dockerfile_fixes(
         self, check_result, instructions)
     copy_instruction = list(
         filter(lambda x: x['instruction'] == 'COPY', result))
     self.assertEqual(len(copy_instruction), 2)
Beispiel #4
0
 def test_given_a_dockerfile_without_user_when_fix_then_instruction_with_user_is_generated(
         self):
     instructions = DockerfileService.parse_dockerfile(
         self, 'test/resources/Dockerfile_basic_with_comments')
     check_result = DockerfileService.evaluate_dockerfile(
         self, instructions)
     result = DockerfileService.get_dockerfile_fixes(self, check_result)
     user_instruction = list(
         filter(lambda x: x['instruction'] == 'USER', result))
     user_add_instruction = list(
         filter(
             lambda x: x['instruction'] == 'RUN' and x['value'].startswith(
                 'useradd'), result))
     self.assertEqual(len(user_instruction), 1)
     self.assertEqual(len(user_add_instruction), 1)
Beispiel #5
0
def post_fix_dockerfile():
    dockerfile_service = DockerfileService()
    dockerfile = request.get_json().get(DOCKER_FILE)
    dockerfile_path = write_dockerfile(dockerfile)
    evaluation = dockerfile_service.check_and_fix_dockerfile(dockerfile_path)
    os.remove(dockerfile_path)
    return jsonify(evaluation)
Beispiel #6
0
 def check_and_fix_container(self, container_id):
     container = self.get_container(container_id)
     if not container:
         return 'Error: no container found'
     check_result = self.evaluate_container(container)
     fixes = DockerfileService.get_dockerfile_fixes(self, check_result)
     Make_dockerfile.write_docker_file_from_dynamic(container, fixes)
     return check_result
Beispiel #7
0
def verify_dockerfile():
    dockerfile_service = DockerfileService()
    dockerfile = request.form['dockerfile']
    dockerfile_path = write_dockerfile(dockerfile)
    evaluation = dockerfile_service.check_and_fix_dockerfile(dockerfile_path)
    os.remove(dockerfile_path)
    template = env.get_template('index.html')
    return template.render(result=evaluation)
Beispiel #8
0
def post_check_dockerfile():
    dockerfile_service = DockerfileService()
    dockerfile = request.get_json().get(DOCKER_FILE)
    dockerfile_path = write_dockerfile(dockerfile)
    errors = validate_dockerfile(dockerfile_path)
    if errors is not None:
        print(errors)
        raise InvalidUsage(errors)
    evaluation = dockerfile_service.check_dockerfile(dockerfile_path)
    os.remove(dockerfile_path)
    return jsonify(evaluation)
Beispiel #9
0
 def test_given_a_dockerfile_with_user_when_check_and_fix_then_OK(self):
     result = DockerfileService.check_and_fix_dockerfile(
         self, 'test/resources/Dockerfile_with_user')
     self.assertEqual(
         result[0]['dockerfile_evaluation']['4_1']['evaluation'], 'OK')
Beispiel #10
0
 def test_given_a_dockerfile_with_user_when_check_and_fix_then_OK(self):
     result = DockerfileService.check_and_fix_dockerfile(
         self, 'test/resources/Dockerfile_with_user')
     user_check_result = list(
         filter(lambda x: x['4_1']['evaluation'] == 'OK', result))
     self.assertEqual(len(user_check_result), 1)
Beispiel #11
0
 def test_given_a_dockerfile_without_user_when_check_and_fix_then_KO(self):
     result = DockerfileService.check_and_fix_dockerfile(
         self, 'test/resources/Dockerfile_basic_with_comments')
     self.assertEqual(
         result[0]['dockerfile_evaluation']['4_1']['evaluation'], 'KO')