Skip to content

Commit

Permalink
[TW] Add docstrings for Dockerfile generator (#120)
Browse files Browse the repository at this point in the history
* Add docstrings.

* Update DevKit image for Ubuntu agent.
  • Loading branch information
AndreyKoltsov1997 authored Nov 9, 2023
1 parent 1bf81b7 commit 45cbffe
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
13 changes: 12 additions & 1 deletion configs/devkit/linux/agent/Ubuntu.devkit.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ FROM ${teamCityImage}

USER root

RUN rm -rf /opt/buildagent/*
# Remove agent code sequentially to work around the inability to delete volumes from the base image.
RUN rm -rf '/opt/buildagent/bin' && \
rm -rf '/opt/buildagent/tools' && \
rm -rf '/opt/buildagent/system' && \
rm -rf '/opt/buildagent/plugins' && \
rm -rf '/opt/buildagent/temp' && \
rm -rf '/opt/buildagent/work' && \
rm -rf '/opt/buildagent/lib' && \
rm -rf '/opt/buildagent/conf' && \
rm -rf '/opt/buildagent/launcher' && \
rm -rf '/data/teamcity_agent/conf'

USER buildagent

CMD ["sleep", "infinity"]
8 changes: 6 additions & 2 deletions tool/TeamCity.Docker/ConfigurationExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace TeamCity.Docker
using IoC;
using Model;

/// <summary>
/// Locates configuration files for Docker Images.
/// </summary>
internal class ConfigurationExplorer : IConfigurationExplorer
{
[NotNull] private readonly ILogger _logger;
Expand All @@ -21,7 +24,7 @@ public ConfigurationExplorer(
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
}

public Result<IEnumerable<Template>> Explore(string sourcePath, IEnumerable<string> configurationFiles)
{
if (sourcePath == null)
Expand Down Expand Up @@ -95,9 +98,10 @@ private IEnumerable<Template> GetConfigurations([NotNull] string sourcePath, [No
var ignore = new List<string>();
if (_fileSystem.IsFileExist(dockerignoreTemplatePath))
{
// Add .Dockerignore files
ignore.AddRange(_fileSystem.ReadLines(dockerignoreTemplatePath));
}

yield return new Template(_fileSystem.ReadLines(dockerfileTemplate).ToImmutableList(), variants.AsReadOnly(), ignore.AsReadOnly());
}
}
Expand Down
1 change: 1 addition & 0 deletions tool/TeamCity.Docker/DockerGraphFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Result<IGraph<IArtifact, Dependency>> Create(IEnumerable<Template> templa
var nodeDict = new Dictionary<string, INode<IArtifact>>();
foreach (var template in templates)
{
// "variants" are different Dockerfile.config files for the template
foreach (var variant in template.Variants)
{
var lines = _contentParser.Parse(template.Lines, variant.Variables).ToImmutableList();
Expand Down
9 changes: 9 additions & 0 deletions tool/TeamCity.Docker/IConfigurationExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
using IoC;
using Model;

/// <summary>
/// Describes the contract for locating template files for Docker images.
/// </summary>
internal interface IConfigurationExplorer
{
/// <summary>
/// Locates configuration files within the given path.
/// </summary>
/// <param name="sourcePath">path to directory with the templates of Dockerfiles (configs)</param>
/// <param name="configurationFiles">list of files with configuration properties within source path (.config files)</param>
/// <returns>list of templates (templates, config values)</returns>
Result<IEnumerable<Template>> Explore([NotNull] string sourcePath, [NotNull] IEnumerable<string> configurationFiles);
}
}
6 changes: 6 additions & 0 deletions tool/TeamCity.Docker/Model/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ internal readonly struct Template
[NotNull] public readonly IEnumerable<Variant> Variants;
[NotNull] public readonly IReadOnlyCollection<string> Ignore;

/// <summary>
/// Creates object describing configuration for Dockerfile.
/// </summary>
/// <param name="lines">Content of the template Dockerfile.</param>
/// <param name="variants">Different configuration options (.config files)</param>
/// <param name="ignore">Content of .Dockerignore</param>
public Template([NotNull] IReadOnlyCollection<string> lines, [NotNull] IReadOnlyCollection<Variant> variants, [NotNull] IReadOnlyCollection<string> ignore)
{
Lines = lines ?? throw new ArgumentNullException(nameof(lines));
Expand Down

0 comments on commit 45cbffe

Please sign in to comment.