From 76bb9ec0eca6fea8d866f2bf3b3443f0a5f70b4f Mon Sep 17 00:00:00 2001 From: Chase S Date: Wed, 4 Oct 2023 13:02:08 -0500 Subject: [PATCH] Add support for custom Docker registries (#275) * Add support for custom Docker registries This allows a user to set the `CONTAINER_REGISTRY` environment variable which can be used in place of the default of ghcr.io if a customer would like to mirror our image so they can self host behind any proxies or other custom network stack. * Add details to README about a custom docker registry --- README.md | 13 +++++++++++-- src/ActionsImporter.UnitTests/AppTests.cs | 3 ++- src/ActionsImporter/App.cs | 10 ++++++---- src/ActionsImporter/Program.cs | 4 +++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8566aa02..b96c9818 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,21 @@ In order for GitHub Actions Importer to communicate with your current CI/CD serv ```bash $ gh actions-importer configure -? Enter value for 'GITHUB_ACCESS_TOKEN' (leave empty to skip): +? Enter value for 'GITHUB_ACCESS_TOKEN' (leave empty to skip): ... ``` You can find detailed information about using environment variables in the platform-specific documentation. +#### Using a custom Docker registry + +We highly recommend using the [official GitHub Container Registry to pull the GitHub Actions Importer Docker image](https://github.com/actions-importer/preview/pkgs/container/cli/). However, if you need to use a custom Docker registry, you can configure GitHub Actions Importer to use a custom Docker registry by setting the `CONTAINER_REGISTRY` environment variable in your `.env.local` file. + +```bash +# .env.local +CONTAINER_REGISTRY=my-custom-registry.com +``` + ### Documentation Detailed information about how to use GitHub Actions Importer can be found in the [documentation](https://docs.github.com/en/actions/migrating-to-github-actions/automating-migration-with-github-actions-importer). @@ -70,7 +79,7 @@ You can access recorded demos of GitHub Actions Importer performing migrations t ### Self-guided learning -The GitHub Actions Importer labs repository contains platform-specific learning paths that teach you how to use GitHub Actions Importer and how to approach migrations to GitHub Actions. To learn more, see the [GitHub Actions Importer labs repository](https://github.com/actions/importer-labs/tree/main#readme). +The GitHub Actions Importer labs repository contains platform-specific learning paths that teach you how to use GitHub Actions Importer and how to approach migrations to GitHub Actions. To learn more, see the [GitHub Actions Importer labs repository](https://github.com/actions/importer-labs/tree/main#readme). ## Product roadmap diff --git a/src/ActionsImporter.UnitTests/AppTests.cs b/src/ActionsImporter.UnitTests/AppTests.cs index 5191b86e..ca33bc3d 100644 --- a/src/ActionsImporter.UnitTests/AppTests.cs +++ b/src/ActionsImporter.UnitTests/AppTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Immutable; using System.IO; using System.Threading.Tasks; using ActionsImporter.Interfaces; @@ -24,7 +25,7 @@ public void BeforeEachTest() _dockerService = new Mock(); _processService = new Mock(); _configurationService = new Mock(); - _app = new App(_dockerService.Object, _processService.Object, _configurationService.Object); + _app = new App(_dockerService.Object, _processService.Object, _configurationService.Object, ImmutableDictionary.Empty); _out = Console.Out; } diff --git a/src/ActionsImporter/App.cs b/src/ActionsImporter/App.cs index 560ea21e..84a01f93 100644 --- a/src/ActionsImporter/App.cs +++ b/src/ActionsImporter/App.cs @@ -7,7 +7,6 @@ namespace ActionsImporter; public class App { private const string ActionsImporterImage = "actions-importer/cli"; - private const string ActionsImporterContainerRegistry = "ghcr.io"; private readonly IDockerService _dockerService; private readonly IProcessService _processService; @@ -16,15 +15,19 @@ public class App public bool IsPrerelease { get; set; } public bool NoHostNetwork { get; set; } + private readonly ImmutableDictionary _environmentVariables; private string ImageTag => IsPrerelease ? "pre" : "latest"; private string ImageName => $"{ActionsImporterImage}:{ImageTag}"; + private readonly string ActionsImporterContainerRegistry; - public App(IDockerService dockerService, IProcessService processService, IConfigurationService configurationService) + public App(IDockerService dockerService, IProcessService processService, IConfigurationService configurationService, ImmutableDictionary environmentVariables) { _dockerService = dockerService; _processService = processService; _configurationService = configurationService; + _environmentVariables = environmentVariables; + ActionsImporterContainerRegistry = _environmentVariables.TryGetValue("CONTAINER_REGISTRY", out var registry) ? registry : "ghcr.io"; } public async Task UpdateActionsImporterAsync() @@ -104,7 +107,6 @@ public async Task CheckForUpdatesAsync() public async Task ConfigureAsync(string[] args) { - var currentVariables = await _configurationService.ReadCurrentVariablesAsync().ConfigureAwait(false); ImmutableDictionary? newVariables; if (args.Contains($"--{Commands.Configure.OptionalFeaturesOption.Name}")) @@ -126,7 +128,7 @@ public async Task ConfigureAsync(string[] args) newVariables = _configurationService.GetUserInput(); } - var mergedVariables = _configurationService.MergeVariables(currentVariables, newVariables); + var mergedVariables = _configurationService.MergeVariables(_environmentVariables, newVariables); await _configurationService.WriteVariablesAsync(mergedVariables); await Console.Out.WriteLineAsync("Environment variables successfully updated."); diff --git a/src/ActionsImporter/Program.cs b/src/ActionsImporter/Program.cs index abe39bbf..9d320ab4 100644 --- a/src/ActionsImporter/Program.cs +++ b/src/ActionsImporter/Program.cs @@ -9,11 +9,13 @@ using Version = ActionsImporter.Commands.Version; var processService = new ProcessService(); +var configurationService = new ConfigurationService(); var app = new App( new DockerService(processService, new RuntimeService()), processService, - new ConfigurationService() + new ConfigurationService(), + await configurationService.ReadCurrentVariablesAsync() ); string welcomeMessage = @"GitHub Actions Importer helps you plan, test, and automate your migration to GitHub Actions.