I wrote this dotnet.yml
to build my application and push the docker image to docker hub, placed in the root of my project under the folder .github/workflows/
.
name: .NET Docker CI/CD
on:
push:
branches:
- master # Replace with your default branch if it's not 'master'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./RSOUserMicroServiceAPI/RSOUserMicroService/Dockerfile
push: true
tags: muchacho3alex/rsouserservice:latest
In the solution (root/SolutionFolder/) I have class library RSO.Core Project and an ASP .NET Core (7.0) Web API project (both in standalone folders) which reference the RSO.Core project as "..\RSO.Core\RSO.Core.csproj"
with following Dockerfile which is located in the the same folder as the Web API project and successfully builds locally.
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["RSOUserMicroService/RSOUserMicroService.csproj", "RSOUserMicroService/"]
COPY ["RSO.Core/RSO.Core.csproj", "RSO.Core/"]
RUN dotnet restore "./RSOUserMicroService/./RSOUserMicroService.csproj"
COPY . .
WORKDIR "/src/RSOUserMicroService"
RUN dotnet build "./RSOUserMicroService.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./RSOUserMicroService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV ASPNETCORE_ENVIRONMENT Release
ENTRYPOINT ["dotnet", "RSOUserMicroService.dll", "--environment=Release"]
While executing this, I get two errors that indicate that my RSO.Core project is missing.
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref u5g15bo5195rycdxlwy3dcamk::qdmrc6j8wf03upivu1wypotf0: "/RSO.Core/RSO.Core.csproj": not found
Error: buildx failed with: ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref u5g15bo5195rycdxlwy3dcamk::qdmrc6j8wf03upivu1wypotf0: "/RSO.Core/RSO.Core.csproj": not found
How to exactly refence these projects to get a successful docker build and push to the dockerhub repository? Is anything needed to remove from some cache?
The repository structure:
(Root)
.github/workflows/dotnet.yml
Solution.sln
-.dockerignore
-.sln
-RSO.Core Project
--Logic
--Repository
--Models
-Asp .Net Core Project
--Controllers
--Dockerfile