2
votes

So I've created a GitHub action that is supposed to build and push a docker image to docker hub whenever a push occurs. So here is my GitHub action: (first time creating a GitHub action)

name: Some name

on:
  push:

jobs:
  build_frontend:
    runs-on: ubuntu-latest

    steps:
      - name: Build frontend image
        run: docker image build -t image .

      - name: Push frontend image
        uses: elgohr/[email protected]
        with:
          name: image
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

But I get this error every time this runs:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/runner/work/project/project/Dockerfile: no such file or directory [error]Process completed with exit code 1.

I tried fiddling around with the path, but then I only get no such file or directory. So I this is the closest I am to something working.

Thanks for any help

2

2 Answers

10
votes

I believe you need to use the checkout action. Your repository isn't actually available to you until you do that:

So, before "Build frontend image":

  - name: Check out code
    uses: actions/checkout@v2

Since your Dockerfile is in your root, that should do it.

0
votes

I think what happens is that it runs on the top level, so if your docker file isn't there, it won't find it and you'll get an error.

For instance, I had a structure that looked like this:

-main\
---myProjectFolder\
-----DockerFile

and was getting this same error. I then made sure in my actions yml file that I changed to the correct directory before building:

run:
 cd myProjectFolder
 docker build -t .

So I would suggest trying to get into whatever folder your Dockerfile is in before running docker build.