-
Notifications
You must be signed in to change notification settings - Fork 144
Add automatic Dockerfile generation with version detection for Golang integration #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fa7b26d
Initial plan
Copilot 9052215
Add automatic Dockerfile generation support for Golang integration
Copilot 590c9e0
Fix code formatting for line endings
Copilot 1e62e49
Use explicit Alpine version tag instead of latest
Copilot 3acd732
Merge branch 'main' into copilot/add-golang-dockerfile-support
aaronpowell 46c54ea
Add DockerfileBaseImageAnnotation support and automatic Go version de…
Copilot 4fb890c
Update README to use WithDockerfileBaseImage extension method
Copilot 880ac36
Merge branch 'main' into copilot/add-golang-dockerfile-support
tommasodotNET 65106bf
Update src/CommunityToolkit.Aspire.Hosting.Golang/GolangAppHostingExt…
tommasodotNET 2ce0835
fixes exec /app/server: no such file or directory
tommasodotNET 6897c21
Add unit tests for Go version detection and fix exception handling
Copilot 927da41
Merge branch 'main' into copilot/add-golang-dockerfile-support
tommasodotNET 8c72923
Add CA certificates and working directory to runtime stage
Copilot c9ac6c1
Merge branch 'main' into copilot/add-golang-dockerfile-support
tommasodotNET File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
tests/CommunityToolkit.Aspire.Hosting.Golang.Tests/GoVersionDetectionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| using Aspire.Hosting; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
|
|
||
| namespace CommunityToolkit.Aspire.Hosting.Golang.Tests; | ||
|
|
||
| public class GoVersionDetectionTests | ||
| { | ||
| [Fact] | ||
| public void DetectGoVersionFromGoMod() | ||
| { | ||
| // Arrange | ||
| var workingDirectory = Path.GetFullPath(Path.Combine("..", "..", "..", "..", "..", "examples", "golang", "gin-api")); | ||
| var logger = NullLogger.Instance; | ||
|
|
||
| // Act | ||
| var version = GolangAppHostingExtension.DetectGoVersion(workingDirectory, logger); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(version); | ||
| Assert.Equal("1.22", version); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetectGoVersionFromGoMod_NonExistentDirectory() | ||
| { | ||
| // Arrange | ||
| var workingDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); | ||
| var logger = NullLogger.Instance; | ||
|
|
||
| // Act | ||
| var version = GolangAppHostingExtension.DetectGoVersion(workingDirectory, logger); | ||
|
|
||
| // Assert - should fall back to checking installed toolchain or return null | ||
| // We don't assert a specific value because it depends on the system's Go installation | ||
| Assert.True(version == null || !string.IsNullOrEmpty(version)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetectGoVersionFromGoMod_WithPatchVersion() | ||
| { | ||
| // Arrange - Create a temporary directory with a go.mod file | ||
| var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); | ||
| Directory.CreateDirectory(tempDir); | ||
| try | ||
| { | ||
| var goModPath = Path.Combine(tempDir, "go.mod"); | ||
| File.WriteAllText(goModPath, @"module testmodule | ||
|
|
||
| go 1.21.5 | ||
|
|
||
| require ( | ||
| github.com/example/package v1.0.0 | ||
| ) | ||
| "); | ||
|
|
||
| var logger = NullLogger.Instance; | ||
|
|
||
| // Act | ||
| var version = GolangAppHostingExtension.DetectGoVersion(tempDir, logger); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(version); | ||
| Assert.Equal("1.21", version); | ||
| } | ||
| finally | ||
| { | ||
| // Cleanup | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetectGoVersionFromGoMod_WithMajorMinorOnly() | ||
| { | ||
| // Arrange - Create a temporary directory with a go.mod file | ||
| var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); | ||
| Directory.CreateDirectory(tempDir); | ||
| try | ||
| { | ||
| var goModPath = Path.Combine(tempDir, "go.mod"); | ||
| File.WriteAllText(goModPath, @"module testmodule | ||
|
|
||
| go 1.20 | ||
|
|
||
| require ( | ||
| github.com/example/package v1.0.0 | ||
| ) | ||
| "); | ||
|
|
||
| var logger = NullLogger.Instance; | ||
|
|
||
| // Act | ||
| var version = GolangAppHostingExtension.DetectGoVersion(tempDir, logger); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(version); | ||
| Assert.Equal("1.20", version); | ||
| } | ||
| finally | ||
| { | ||
| // Cleanup | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DetectGoVersionFromGoMod_InvalidFormat() | ||
| { | ||
| // Arrange - Create a temporary directory with an invalid go.mod file | ||
| var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); | ||
| Directory.CreateDirectory(tempDir); | ||
| try | ||
| { | ||
| var goModPath = Path.Combine(tempDir, "go.mod"); | ||
| File.WriteAllText(goModPath, @"module testmodule | ||
|
|
||
| go invalid | ||
|
|
||
| require ( | ||
| github.com/example/package v1.0.0 | ||
| ) | ||
| "); | ||
|
|
||
| var logger = NullLogger.Instance; | ||
|
|
||
| // Act | ||
| var version = GolangAppHostingExtension.DetectGoVersion(tempDir, logger); | ||
|
|
||
| // Assert - should fall back to checking installed toolchain or return null | ||
| Assert.True(version == null || !string.IsNullOrEmpty(version)); | ||
| } | ||
| finally | ||
| { | ||
| // Cleanup | ||
| if (Directory.Exists(tempDir)) | ||
| { | ||
| Directory.Delete(tempDir, true); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.