Search code examples
dockerblazorgithub-actions

Docker build can't find Dockerfile


I have a GitHub repo with a MubBlazor project. It is just a kind of playground for me and my friend. We plan on following clean architecture, based on the following YouTube tutorial by Frank Liu. We only have the web app part by now as you can see in the current repo structure.

I want to use a self-hosted GitHub Actions runner to check out my code, build a Docker image and run that image on the same Raspberry Pi, so me and my friend can actually see the project on a server, not just by using the local Visual Studio IIS-Express hosting.

However each GitHub Actions run fails when trying to build the Docker image:

Run sudo docker build -t playground-f Dockerfile ./
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile:
#1 transferring dockerfile: 2B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s
ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount1403914947/Dockerfile: no such file or directory
Error: Process completed with exit code 1.

I feel like a copy of my repo doesn't reach the runner, if that makes sense. Because the build fails, I don't know if the rest of the process would work.

Current file/repo structure:

Playground
├── .github/workflows
│   ├── main.yml
├── Playground.WebApp
│   ├── Pages
│   ├── Properties
│   ├── Shared
│   ├── wwwroot
│   ├── App.razor
│   ├── Program.cs
│   ├── Playground.WebApp.csproj
│   ├── Playground.WebApp.sln
│   ├── _Imports.razor
├── Dockerfile
├── Spielplatz.sln
├── nginx.conf

Current workflow file:

name: Build and launch playground
on:
  push:
    branches:
      - main
jobs:
  create_image_and_run_it:    
    runs-on: self-hosted
    steps:
      - run: sudo docker build -t playground -f Dockerfile ./
      - run: sudo docker run -p 8080:80 playground

Current Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app

COPY Playground.sln ./
COPY ./Playground.WebApp/Playground.WebApp.csproj ./Playground.WebApp

RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out

FROM nginx:1.23.0-alpine
WORKDIR /app
EXPOSE 8080
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/out/wwwroot /usr/share/nginx/html

Solution

  • With github-actions, the project is not checked out automatically; we need to checkout the project explicitly. For this, the github-team provides the checkout action (github.com). Using it is as simple as adding

          - name: Git checkout
            uses: actions/checkout@v4
    

    to the steps-list of a given workflow.