Skip to content

Commit

Permalink
Add support for custom Docker registries (#275)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Chaseshak committed Oct 4, 2023
1 parent 0bdafdb commit 76bb9ec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/ActionsImporter.UnitTests/AppTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Immutable;
using System.IO;
using System.Threading.Tasks;
using ActionsImporter.Interfaces;
Expand All @@ -24,7 +25,7 @@ public void BeforeEachTest()
_dockerService = new Mock<IDockerService>();
_processService = new Mock<IProcessService>();
_configurationService = new Mock<IConfigurationService>();
_app = new App(_dockerService.Object, _processService.Object, _configurationService.Object);
_app = new App(_dockerService.Object, _processService.Object, _configurationService.Object, ImmutableDictionary<string, string>.Empty);
_out = Console.Out;
}

Expand Down
10 changes: 6 additions & 4 deletions src/ActionsImporter/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,15 +15,19 @@ public class App
public bool IsPrerelease { get; set; }
public bool NoHostNetwork { get; set; }

private readonly ImmutableDictionary<string, string> _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<string, string> environmentVariables)
{
_dockerService = dockerService;
_processService = processService;
_configurationService = configurationService;
_environmentVariables = environmentVariables;
ActionsImporterContainerRegistry = _environmentVariables.TryGetValue("CONTAINER_REGISTRY", out var registry) ? registry : "ghcr.io";
}

public async Task<int> UpdateActionsImporterAsync()
Expand Down Expand Up @@ -104,7 +107,6 @@ public async Task CheckForUpdatesAsync()

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

if (args.Contains($"--{Commands.Configure.OptionalFeaturesOption.Name}"))
Expand All @@ -126,7 +128,7 @@ public async Task<int> 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.");
Expand Down
4 changes: 3 additions & 1 deletion src/ActionsImporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 76bb9ec

Please sign in to comment.