// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
using System.IO;
using System.Reflection;
using AWS.Deploy.Common;
using AWS.Deploy.Common.Extensions;
namespace AWS.Deploy.DockerEngine
{
public class ProjectUtilities
{
private const string DockerFileConfig = "AWS.Deploy.DockerEngine.Properties.DockerFileConfig.json";
private const string DockerfileTemplate = "AWS.Deploy.DockerEngine.Templates.Dockerfile.template";
///
/// Retrieves the Docker File Config
///
internal static string ReadDockerFileConfig()
{
var template = Assembly.GetExecutingAssembly().ReadEmbeddedFile(DockerFileConfig);
if (string.IsNullOrWhiteSpace(template))
{
throw new DockerEngineException(DeployToolErrorCode.UnableToMapProjectToDockerImage, $"The DockerEngine could not find the embedded config file responsible for mapping projects to Docker images.");
}
return template;
}
///
/// Reads dockerfile template file
///
internal static string ReadTemplate()
{
var template = Assembly.GetExecutingAssembly().ReadEmbeddedFile(DockerfileTemplate);
if (string.IsNullOrWhiteSpace(template))
{
throw new DockerFileTemplateException(DeployToolErrorCode.DockerFileTemplateNotFound, "The Dockerfile template for the project was not found.");
}
return template;
}
}
}