Skip to content

Commit

Permalink
chore: add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoopereira committed Nov 7, 2023
1 parent d488042 commit bccba35
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,41 @@ jobs:
- name: push
run: dotnet nuget push nupkg/dotnet-test-rerun.*.nupkg --source https://api.nuget.org/v3/index.json --api-key $NUGET_API_KEY --skip-duplicate
env:
NUGET_API_KEY: ${{secrets.NUGET_API_KEY}}
NUGET_API_KEY: ${{secrets.NUGET_API_KEY}}

docker:
runs-on: ubuntu-latest
name: 🐋 Build and Push Docker Image
steps:
- name: checkout
uses: actions/checkout@v4

- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
docker.io/${{ github.repository }}
tags: |
type=ref,event=push
type=ref,event=push tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
flavor: |
latest=true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
25 changes: 25 additions & 0 deletions src/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use the official .NET SDK image from Microsoft as the build environment
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build

# Set the working directory in the container
WORKDIR /app

# Copy everything
COPY . .

# Restore as distinct layers
RUN dotnet restore dotnet-test-rerun.csproj /p:DockerBuild=true
# Build and publish a release
RUN dotnet publish dotnet-test-rerun.csproj /p:DockerBuild=true -c Release -o out

# Build the runtime image
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS runtime

# Set the working directory in the runtime container
WORKDIR /app

# Copy the published application from the build container to the runtime container
COPY --from=build /app/out ./

# Set the entry point for the application
ENTRYPOINT ["dotnet", "test-rerun.dll"]
4 changes: 2 additions & 2 deletions src/dotnet-test-rerun.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
<PackageReference Include="TrxFileParser" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="/">
<None Include="../README.md" Pack="true" PackagePath="/" Condition="$(DockerBuild) != 'true'">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="dotnet-test-rerun.UnitTests" />
</ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0 And $(DockerBuild) != 'true'">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory=".." />
</Target>
Expand Down

0 comments on commit bccba35

Please sign in to comment.