GitHub action docker/build-push-action@v4 with a simple test failing online, "works on my PC"?

huangapple go评论77阅读模式
英文:

GitHub action docker/build-push-action@v4 with a simple test failing online, "works on my PC"?

问题

以下是您要翻译的内容:

  1. 在本地,使用这个 `Dockerfile`

FROM node:lts-alpine as node_builder
WORKDIR /app

如果存在,复制 assets 文件夹

COPY assets assets

  1. 在我的机器上,我可以测试资产是否已复制并正常工作(已存在):

$ touch assets/foo.js
$ docker build . -t node_builder:latest --target node_builder
$ docker run --rm node_builder:latest sh -c "stat assets/foo.js"

  1. 当我尝试在我的在线存储库和 `test.yml` 工作流中执行相同操作时,资产 `foo.js` 没有被复制。我的步骤描述如下:
  2. ```yaml
  3. node_builder:
  4. runs-on: ubuntu-latest
  5. steps:
  6. # 克隆此存储库
  7. - name: Checkout
  8. uses: actions/checkout@v3
  9. # 在克隆的存储库中创建一个简单的资产
  10. - name: Create a simple asset
  11. run: touch assets/foo.js
  12. # 资产 assets/foo.js 存在,OK!
  13. - name: Debug
  14. run: ls -la assets
  15. # 构建目标镜像
  16. - name: Build target
  17. uses: docker/build-push-action@v4
  18. with:
  19. target: node_builder
  20. tags: node_builder:latest
  21. # 在镜像内运行命令
  22. - name: Test assets copy
  23. run: docker run --rm node_builder:latest sh -c "stat assets/foo.js"

我试图通过调试/输出内容找出问题,但我找不到我做错了什么(肯定是我漏掉了某些东西)。

  1. <details>
  2. <summary>英文:</summary>
  3. Locally, with this `Dockerfile`:
  4. &lt;!-- language: lang-none --&gt;
  5. FROM node:lts-alpine as node_builder
  6. WORKDIR /app
  7. # Copy the assets folder if exists
  8. COPY assets assets
  9. On my machine, I can test if asset is copied and it works (it&#39;s there):
  10. $ touch assets/foo.js
  11. $ docker build . -t node_builder:latest --target node_builder
  12. $ docker run --rm node_builder:latest sh -c &quot;stat assets/foo.js&quot;
  13. When i try to do the same with my online repository and `test.yml` workflow, asset `foo.js` is not copied. My Steps are described as:
  14. &lt;!-- language: lang-yml --&gt;
  15. node_builder:
  16. runs-on: ubuntu-latest
  17. steps:
  18. # Clone this repository
  19. - name: Checkout
  20. uses: actions/checkout@v3
  21. # Just touch a new assets in the cloned repository
  22. - name: Create a simple asset
  23. run: touch assets/foo.js
  24. # Asset assets/foo.js is present OK!
  25. - name: Debug
  26. run: ls -la assets
  27. # Build the target image
  28. - name: Build target
  29. uses: docker/build-push-action@v4
  30. with:
  31. target: node_builder
  32. tags: node_builder:latest
  33. # Run the comand inside the image
  34. - name: Test assets copy
  35. run: docker run --rm node_builder:latest sh -c &quot;stat assets/foo.js&quot;
  36. I&#39;m trying to find out why using debug/echoing stuff but I can&#39;t find what I&#39;m doing wrong (and for sure I&#39;m missing something).
  37. </details>
  38. # 答案1
  39. **得分**: 1
  40. 请注意,任何在构建步骤之前的步骤中对文件的更改都将被忽略,包括对.dockerignore文件的处理,因为上下文是基于Git引用的。然而,您可以在使用actions/checkout操作的同时使用context输入来移除此限制。
  41. 原来,`docker/build-push-action@v4`构建GitHub存储库的URL。因此,解决方案如下:
  42. # 构建目标镜像
  43. - name: 构建目标
  44. uses: docker/build-push-action@v4
  45. with:
  46. target: node_builder
  47. context: .
  48. tags: node_builder:latest
  49. <details>
  50. <summary>英文:</summary>
  51. &gt; Be careful because any file mutation in the steps that precede the build step will be ignored, including processing of the .dockerignore file since the context is based on the Git reference. However, you can use the Path context using the context input alongside the actions/checkout action to remove this restriction.
  52. Turns out `docker/build-push-action@v4` builds the GitHub repoository URL. So the solution is:
  53. # Build the target image
  54. - name: Build target
  55. uses: docker/build-push-action@v4
  56. with:
  57. target: node_builder
  58. context: .
  59. tags: node_builder:latest
  60. </details>

huangapple
  • 本文由 发表于 2023年3月31日 03:11:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892106.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定