kciter / aws-ecr-action

This Action allows you to create Docker images and push into a ECR repository.
MIT License
146 stars 116 forks source link

docker build unable to find Dockerfile #2

Closed thorion3006 closed 4 years ago

thorion3006 commented 4 years ago

Hey, I'm using your GitHub action to push my docker image to ecr, but the action fails every time complaing Dockerfile is missing.

My repo structure:

repo
|----Dockerfile
|----.github
         |----workflows
                  |----action.yml

If i don't set the path variable in the job i get the following error:

/usr/bin/docker run --name af96b426492533e83b426ba94140811963aaa8_19dc66 --label af96b4 --workdir /github/workspace --rm -e INPUT_ACCESS_KEY_ID -e INPUT_SECRET_ACCESS_KEY -e INPUT_ACCOUNT_ID -e INPUT_REPO -e INPUT_REGION -e INPUT_TAGS -e INPUT_CREATE_REPO -e INPUT_EXTRA_BUILD_ARGS -e INPUT_DOCKERFILE -e INPUT_PATH -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e GITHUB_ACTIONS=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/orchard-iot-service/orchard-iot-service":"/github/workspace" af96b4:26492533e83b426ba94140811963aaa8
== START LOGIN
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /github/home/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
== FINISHED LOGIN
== START DOCKERIZE
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /github/workspace/Dockerfile: no such file or directory
##[error]Docker run failed with exit code 1

If i set the path variable to ../../../Dockerfile I get the following error:

/usr/bin/docker run --name af96b481857813853d401a8d317be1694475bc_d6deb8 --label af96b4 --workdir /github/workspace --rm -e INPUT_ACCESS_KEY_ID -e INPUT_SECRET_ACCESS_KEY -e INPUT_ACCOUNT_ID -e INPUT_REPO -e INPUT_REGION -e INPUT_TAGS -e INPUT_CREATE_REPO -e INPUT_EXTRA_BUILD_ARGS -e INPUT_PATH -e INPUT_DOCKERFILE -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e GITHUB_ACTIONS=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/orchard-iot-service/orchard-iot-service":"/github/workspace" af96b4:81857813853d401a8d317be1694475bc
== START LOGIN
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /github/home/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
== FINISHED LOGIN
== START DOCKERIZE
unable to prepare context: path "../../../Dockerfile" not found
##[error]Docker run failed with exit code 1

What should the path variable be set to?

kodzi commented 4 years ago

FYI (and others who faced the same error) append uses: actions/checkout@v1 before uses: kciter/aws-ecr-action@v1 to checkout the content of your repo. Afterwards with your project structure you can leave the path part to default.

Example

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: kciter/aws-ecr-action@v1
      with:
        access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        account_id: ${{ secrets.AWS_ACCOUNT_ID }}
        repo: docker/repo
        region: ap-northeast-2
        tags: latest,${{ github.sha }}
        create_repo: true
frani commented 4 years ago

Ahoy my friends. we are three now !

having the same problem

dwight-biddle commented 4 years ago

I believe I found the issue with “path” not working and submitted a PR: #5

Discovered that the root cause of my issue was a docker problem, not a problem with this action. When trying to run a dockerfile in a subfolder, Docker requires that you add the path to the dockerfile in both the parameter specifying the file name (-f) and the PATH context (the '.' in 'docker build .'). When I tried reproducing in docker, I realized the docker command needed to be

docker build -f ./subfolder/my.Dockerfile ./subfolder

So the correct way to build a Dockerfile in a subfolder is to put the following two parameters in the step using this action

          dockerfile: ./subfolder/my.Dockerfile
          path: ./subfolder
vinodjayachandran commented 4 years ago

FYI (and others who faced the same error) append uses: actions/checkout@v1 before uses: kciter/aws-ecr-action@v1 to checkout the content of your repo. Afterwards with your project structure you can leave the path part to default.

Example

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: kciter/aws-ecr-action@v1
      with:
        access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        account_id: ${{ secrets.AWS_ACCOUNT_ID }}
        repo: docker/repo
        region: ap-northeast-2
        tags: latest,${{ github.sha }}
        create_repo: true

It worked for me. Thank you so much