Skip to content
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

Added multiplatform support for arm64 and amd64 #159

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/pullrequest-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ jobs:

- name: Verify performance
run: make verify-performance

verify-electricity-server-container-build:
name: Verify electricity container can be built.
uses: project-origin/.github/.github/workflows/reusable-build-container.yaml@main
with:
imagename: ghcr.io/project-origin/electricity-server
version: test
context: ./src
dockerfile: ./src/ProjectOrigin.Electricity.Server/Dockerfile
secrets:
pushtoken: ''

verify-registry-server-container-build:
name: Verify registry container can be built.
uses: project-origin/.github/.github/workflows/reusable-build-container.yaml@main
with:
imagename: ghcr.io/project-origin/registry-server
version: test
context: ./src
dockerfile: ./src/ProjectOrigin.Registry.Server/Dockerfile
secrets:
pushtoken: ''
Original file line number Diff line number Diff line change
Expand Up @@ -50,58 +50,28 @@ jobs:
run: dotnet nuget push build/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

publish-electricity-server-container:
name: Publish Electricity Server container
runs-on: ubuntu-22.04
needs:
- define-version
env:
name: electricity-server
project: src/ProjectOrigin.Electricity.Server

steps:
- uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./src
file: ${{ env.project }}/Dockerfile
push: true
tags: ghcr.io/project-origin/${{ env.name }}:${{ needs.define-version.outputs.version }}
uses: project-origin/.github/.github/workflows/reusable-build-container.yaml@main
with:
imagename: ghcr.io/project-origin/electricity-server
version: ${{ needs.define-version.outputs.version }}
context: ./src
dockerfile: ./src/ProjectOrigin.Electricity.Server/Dockerfile
secrets:
pushtoken: ${{ github.token }}

publish-registry-server-container:
name: Publish Registry Server container
runs-on: ubuntu-22.04
needs:
- define-version
env:
name: registry-server
project: src/ProjectOrigin.Registry.Server

steps:
- uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./src
file: ${{ env.project }}/Dockerfile
push: true
tags: ghcr.io/project-origin/${{ env.name }}:${{ needs.define-version.outputs.version }}
uses: project-origin/.github/.github/workflows/reusable-build-container.yaml@main
with:
imagename: ghcr.io/project-origin/registry-server
version: ${{ needs.define-version.outputs.version }}
context: ./src
dockerfile: ./src/ProjectOrigin.Registry.Server/Dockerfile
secrets:
pushtoken: ${{ github.token }}

publish-chart:
name: Publish helm chart
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**/Dockerfile.tmp

# ignore dotnet code coverage files
**/coverage.cobertura.xml

Expand Down
2 changes: 2 additions & 0 deletions src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/bin/
*/obj/
2 changes: 1 addition & 1 deletion src/ProjectOrigin.Electricity.Server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS dotnet-build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS dotnet-build
WORKDIR /src
COPY . .
RUN dotnet restore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using System.IO;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Images;
using Xunit;

public class ContainerImageFixture : IAsyncLifetime
{
private const string DockerfilePath = "ProjectOrigin.Registry.Server/Dockerfile";
public IImage Image => _image;
private IFutureDockerImage _image;
private string _tempDockerPath;

public ContainerImageFixture()
{
// Testcontainers doesn't support buildkit and therefore doesn't support $BUILDPLATFORM
_tempDockerPath = CreateTempDockerfileWithoutPlatform(Path.Combine(CommonDirectoryPath.GetSolutionDirectory().DirectoryPath, DockerfilePath));
var relativeDockerfile = Path.GetRelativePath(CommonDirectoryPath.GetSolutionDirectory().DirectoryPath, _tempDockerPath);

_image = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory(CommonDirectoryPath.GetSolutionDirectory(), string.Empty)
.WithDockerfile("ProjectOrigin.Registry.Server/Dockerfile")
.WithDockerfile(relativeDockerfile)
.Build();
}

Expand All @@ -23,7 +30,15 @@ public async Task InitializeAsync()

public async Task DisposeAsync()
{
File.Delete(_tempDockerPath);
await _image.DeleteAsync().ConfigureAwait(false);
await _image.DisposeAsync().ConfigureAwait(false);
}

private static string CreateTempDockerfileWithoutPlatform(string source)
{
var target = $"{source}.tmp";
File.WriteAllText(target, File.ReadAllText(source).Replace("--platform=$BUILDPLATFORM", ""));
return target;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace ProjectOrigin.Electricity.IntegrationTests;

public class PerformanceTests : IAsyncLifetime, IClassFixture<ContainerImageFixture>, IClassFixture<PostgresDatabaseFixture>
{
private const string ElectricityVerifierImage = "ghcr.io/project-origin/electricity-server:0.2.0-rc.17";
private const string ElectricityVerifierImage = "ghcr.io/project-origin/electricity-server:0.2.2";
private const int GrpcPort = 80;
private const string IssuerArea = "Narnia";
private const string RegistryName = "TheRegistry";
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectOrigin.Registry.Server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS dotnet-build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS dotnet-build
WORKDIR /src
COPY . .
RUN dotnet restore
Expand Down