@Override
    public DockerfileEntity generateDockerfile(ServiceSpec serviceSpec, DockerfileGenContext context)
            throws HyscaleException {

        try {
            validate(serviceSpec, context);
            String serviceName = serviceSpec.get(HyscaleSpecFields.name, String.class);
            context.setServiceName(serviceName.trim());
            //validates service spec if dockerfile generation has to be skipped
            if (!skipDockerfileGen(serviceSpec, context)) {
                return null;
            }
        } catch (HyscaleException e) {
            WorkflowLogger.startActivity(DockerfileActivity.DOCKERFILE_GENERATION);
            WorkflowLogger.endActivity(Status.FAILED);
            throw e;
        }

        boolean isSuccess = false;
        DockerfileEntity dockerFileEntity = new DockerfileEntity();
        try {
            BuildSpec buildSpec = serviceSpec.get(
                    HyscaleSpecFields.getPath(HyscaleSpecFields.image, HyscaleSpecFields.buildSpec), BuildSpec.class);
            // Get updated artifacts
            List<Artifact> originalArtifacts = buildSpec.getArtifacts();

            if (!context.isSkipCopy()) {
                context.setEffectiveArtifacts(artifactHelper.getUpdatedArtifacts(originalArtifacts));
            } else {
                context.setEffectiveArtifacts(originalArtifacts);
            }

            // Use updated artifacts from context
            DockerfileContent dockerfileContent = dockerfileContentGenerator.generate(serviceSpec, context);
            String appName = context.getAppName();

            File dockerfile = new File(dockerfileGenConfig.getDockerFileDir(appName, context.getServiceName()));
            dockerFileEntity.setDockerfile(dockerfile);

            // Get Supporting Files
            List<SupportingFile> supportingFiles = new ArrayList<>();
            supportingFiles.addAll(dockerScriptHelper.getSupportingFiles(serviceSpec, context));
            supportingFiles.addAll(artifactHelper.getSupportingFiles(serviceSpec, context));

            dockerFileEntity.setSupportingFileList(supportingFiles);

            isSuccess = dockerfilePersistenceService.persistDockerfiles(dockerfileContent, supportingFiles, context);
        } catch (HyscaleException ex) {
            logger.error("Error while generating dockerfile, error {}", ex.toString());
            throw ex;
        }
        if (!isSuccess) {
            throw new HyscaleException(DockerfileErrorCodes.FAILED_TO_GENERATE_DOCKERFILE);
        }
        logger.debug("Dockerfile entity {}", dockerFileEntity);
        return dockerFileEntity;
    }
Validates service spec if dockerfile generation has to be skipped
Copies the artifacts to relative path of dockerfile
Copies the scripts to relative path of dockerfile
Generates the dockerfile content
Writes  dockerfile to a file
dockerfile-generator/dockerfile-gen-services/src/main/java/io/hyscale/dockerfile/gen/services/generator/impl/DockerfileGeneratorImpl.java