Skip to content

Commit 76bb9ec

Browse files
authored
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
1 parent 0bdafdb commit 76bb9ec

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ In order for GitHub Actions Importer to communicate with your current CI/CD serv
4848

4949
```bash
5050
$ gh actions-importer configure
51-
? Enter value for 'GITHUB_ACCESS_TOKEN' (leave empty to skip):
51+
? Enter value for 'GITHUB_ACCESS_TOKEN' (leave empty to skip):
5252
...
5353
```
5454

5555
You can find detailed information about using environment variables in the platform-specific documentation.
5656

57+
#### Using a custom Docker registry
58+
59+
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.
60+
61+
```bash
62+
# .env.local
63+
CONTAINER_REGISTRY=my-custom-registry.com
64+
```
65+
5766
### Documentation
5867

5968
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
7079

7180
### Self-guided learning
7281

73-
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).
82+
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).
7483

7584
## Product roadmap
7685

src/ActionsImporter.UnitTests/AppTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Immutable;
23
using System.IO;
34
using System.Threading.Tasks;
45
using ActionsImporter.Interfaces;
@@ -24,7 +25,7 @@ public void BeforeEachTest()
2425
_dockerService = new Mock<IDockerService>();
2526
_processService = new Mock<IProcessService>();
2627
_configurationService = new Mock<IConfigurationService>();
27-
_app = new App(_dockerService.Object, _processService.Object, _configurationService.Object);
28+
_app = new App(_dockerService.Object, _processService.Object, _configurationService.Object, ImmutableDictionary<string, string>.Empty);
2829
_out = Console.Out;
2930
}
3031

src/ActionsImporter/App.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ namespace ActionsImporter;
77
public class App
88
{
99
private const string ActionsImporterImage = "actions-importer/cli";
10-
private const string ActionsImporterContainerRegistry = "ghcr.io";
1110

1211
private readonly IDockerService _dockerService;
1312
private readonly IProcessService _processService;
@@ -16,15 +15,19 @@ public class App
1615
public bool IsPrerelease { get; set; }
1716
public bool NoHostNetwork { get; set; }
1817

18+
private readonly ImmutableDictionary<string, string> _environmentVariables;
1919
private string ImageTag => IsPrerelease ? "pre" : "latest";
2020

2121
private string ImageName => $"{ActionsImporterImage}:{ImageTag}";
22+
private readonly string ActionsImporterContainerRegistry;
2223

23-
public App(IDockerService dockerService, IProcessService processService, IConfigurationService configurationService)
24+
public App(IDockerService dockerService, IProcessService processService, IConfigurationService configurationService, ImmutableDictionary<string, string> environmentVariables)
2425
{
2526
_dockerService = dockerService;
2627
_processService = processService;
2728
_configurationService = configurationService;
29+
_environmentVariables = environmentVariables;
30+
ActionsImporterContainerRegistry = _environmentVariables.TryGetValue("CONTAINER_REGISTRY", out var registry) ? registry : "ghcr.io";
2831
}
2932

3033
public async Task<int> UpdateActionsImporterAsync()
@@ -104,7 +107,6 @@ public async Task CheckForUpdatesAsync()
104107

105108
public async Task<int> ConfigureAsync(string[] args)
106109
{
107-
var currentVariables = await _configurationService.ReadCurrentVariablesAsync().ConfigureAwait(false);
108110
ImmutableDictionary<string, string>? newVariables;
109111

110112
if (args.Contains($"--{Commands.Configure.OptionalFeaturesOption.Name}"))
@@ -126,7 +128,7 @@ public async Task<int> ConfigureAsync(string[] args)
126128
newVariables = _configurationService.GetUserInput();
127129
}
128130

129-
var mergedVariables = _configurationService.MergeVariables(currentVariables, newVariables);
131+
var mergedVariables = _configurationService.MergeVariables(_environmentVariables, newVariables);
130132
await _configurationService.WriteVariablesAsync(mergedVariables);
131133

132134
await Console.Out.WriteLineAsync("Environment variables successfully updated.");

src/ActionsImporter/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
using Version = ActionsImporter.Commands.Version;
1010

1111
var processService = new ProcessService();
12+
var configurationService = new ConfigurationService();
1213

1314
var app = new App(
1415
new DockerService(processService, new RuntimeService()),
1516
processService,
16-
new ConfigurationService()
17+
new ConfigurationService(),
18+
await configurationService.ReadCurrentVariablesAsync()
1719
);
1820

1921
string welcomeMessage = @"GitHub Actions Importer helps you plan, test, and automate your migration to GitHub Actions.

0 commit comments

Comments
 (0)