英文:
GitHub action docker/build-push-action@v4 with a simple test failing online, "works on my PC"?
问题
以下是您要翻译的内容:
在本地,使用这个 `Dockerfile`:
FROM node:lts-alpine as node_builder
WORKDIR /app
如果存在,复制 assets 文件夹
COPY assets assets
在我的机器上,我可以测试资产是否已复制并正常工作(已存在):
$ 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"
当我尝试在我的在线存储库和 `test.yml` 工作流中执行相同操作时,资产 `foo.js` 没有被复制。我的步骤描述如下:
```yaml
node_builder:
runs-on: ubuntu-latest
steps:
# 克隆此存储库
- name: Checkout
uses: actions/checkout@v3
# 在克隆的存储库中创建一个简单的资产
- name: Create a simple asset
run: touch assets/foo.js
# 资产 assets/foo.js 存在,OK!
- name: Debug
run: ls -la assets
# 构建目标镜像
- name: Build target
uses: docker/build-push-action@v4
with:
target: node_builder
tags: node_builder:latest
# 在镜像内运行命令
- name: Test assets copy
run: docker run --rm node_builder:latest sh -c "stat assets/foo.js"
我试图通过调试/输出内容找出问题,但我找不到我做错了什么(肯定是我漏掉了某些东西)。
<details>
<summary>英文:</summary>
Locally, with this `Dockerfile`:
<!-- language: lang-none -->
FROM node:lts-alpine as node_builder
WORKDIR /app
# Copy the assets folder if exists
COPY assets assets
On my machine, I can test if asset is copied and it works (it's there):
$ 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"
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:
<!-- language: lang-yml -->
node_builder:
runs-on: ubuntu-latest
steps:
# Clone this repository
- name: Checkout
uses: actions/checkout@v3
# Just touch a new assets in the cloned repository
- name: Create a simple asset
run: touch assets/foo.js
# Asset assets/foo.js is present OK!
- name: Debug
run: ls -la assets
# Build the target image
- name: Build target
uses: docker/build-push-action@v4
with:
target: node_builder
tags: node_builder:latest
# Run the comand inside the image
- name: Test assets copy
run: docker run --rm node_builder:latest sh -c "stat assets/foo.js"
I'm trying to find out why using debug/echoing stuff but I can't find what I'm doing wrong (and for sure I'm missing something).
</details>
# 答案1
**得分**: 1
请注意,任何在构建步骤之前的步骤中对文件的更改都将被忽略,包括对.dockerignore文件的处理,因为上下文是基于Git引用的。然而,您可以在使用actions/checkout操作的同时使用context输入来移除此限制。
原来,`docker/build-push-action@v4`构建GitHub存储库的URL。因此,解决方案如下:
# 构建目标镜像
- name: 构建目标
uses: docker/build-push-action@v4
with:
target: node_builder
context: .
tags: node_builder:latest
<details>
<summary>英文:</summary>
> 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.
Turns out `docker/build-push-action@v4` builds the GitHub repoository URL. So the solution is:
# Build the target image
- name: Build target
uses: docker/build-push-action@v4
with:
target: node_builder
context: .
tags: node_builder:latest
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论