redhat-actions / buildah-build

GitHub Action to use 'buildah' to build a container image.
https://github.com/marketplace/actions/buildah-build
MIT License
144 stars 34 forks source link

[BUG] workingdir not being used for copy #70

Closed larryclaman closed 3 years ago

larryclaman commented 3 years ago

Version v2

Describe the bug

Attempting to use buildah-build action but having a problem with getting the copy command to honor the workdir. My action looks like:

    # Build container image without Dockerfile!
    - name: Build container image using Buildah 
      uses: redhat-actions/buildah-build@v2
      with:
        image:  ${{env.acrsite}}/${{env.repo}}
        tags: ${{github.run_number}} ${{ github.sha }}
        workdir: /app/
        build-args: |
          build_version=${{github.run_number}}
        base-image: mcr.microsoft.com/dotnet/aspnet:2.1
        entrypoint: |
          dotnet
          poi.dll
        envs: |
          WEB_PORT="8080"
          WEB_SERVER_BASE_URI="http://0.0.0.0"
          ASPNETCORE_ENVIRONMENT="Production"
        content: |
          myapp

What's happening is that the content from my local myapp directory is being copied into the root of the image, rather than into the /app workdir. I have tried setting workdir to /app and /app/, but in both cases, the content is copied into the root, not into the workdir. I do see that the '/app' directory was created; it's just not being used.

When looking at the run, it appears that the copy command is happening before the build config command with the workdir argument, so I think this is the cause of the problem:

Overriding storage mount_program with "fuse-overlayfs" in environment
Performing build from scratch
/usr/bin/buildah from mcr.microsoft.com/dotnet/aspnet:2.1
Trying to pull mcr.microsoft.com/dotnet/aspnet:2.1...
Getting image source signatures
Copying blob sha256:33f99cea3b7da8c6e0143c9fd7590c6d56f7d310ddd59b11be4ad485ae4cab2a
Copying blob sha256:f66af433fc3eabe3694f2bd46f6936aadb99adf45275e78b5e46894149829642
Copying blob sha256:2b463c1ef5a97bea188f214519fec9d82d0e411e6d47685262df4098a5fad185
Copying blob sha256:06e05c6a34c19717d50d6de009d20a269e522e8cfef2949c1e26b74dc0bf841b
Copying config sha256:1a48139335f865314e13afee3978a53d3bc6adf3b1b3f4543eb6742a4a07db1a
Writing manifest to image destination
Storing signatures
aspnet-working-container
/usr/bin/buildah copy aspnet-working-container myapp
243190cfec4ce2dc69cf717980cc2fa87b3a111eee0f6e70b998d505515fee88
/usr/bin/buildah config --entrypoint ["dotnet","poi.dll"] --env WEB_PORT="8080" --env WEB_SERVER_BASE_URI="http://0.0.0.0" --env ASPNETCORE_ENVIRONMENT="Production" --workingdir /app/ aspnet-working-container
time="2021-09-01T17:37:34Z" level=warning msg="cmd \"bash\" exists and will be passed to entrypoint as a parameter"
/usr/bin/buildah commit --format docker --squash aspnet-working-container [....]/api-poi:39

Steps to reproduce, workflow links, screenshots

see above

divyansh42 commented 3 years ago

@larryclaman Thanks for reporting this issue. I also think that this problem is because workingDir is being set after the copy command. Ideally, the copy command should be done after the config command if we are setting the workingDir.

We will update you once we add a fix for this.

divyansh42 commented 3 years ago

@larryclaman we have fixed this. Could you please try again and let us know if you still face any problems.