无法准备上下文:路径” ”未找到 Github Actions Runner

发布于 2025-01-09 23:46:08 字数 4157 浏览 0 评论 0原文

我正在尝试在 Github Actions 运行程序中构建并标记一个 docker 映像,并且从运行程序中收到此错误。

unable to prepare context: path " " not found
Error: Process completed with exit code 1.

我已经在 StackOverflow 上解决了所有其他类似问题并实现了它们,但仍然没有前进的道路。

有趣的是,我还有其他微服务使用类似的工作流程,并且 Dockerfile 工作得很好。

我的工作流程

name: some-tests

on:
  pull_request:
    branches: [ main ]

jobs:
  tests:
    runs-on: ubuntu-latest
    env: 
      AWS_REGION: us-east-1
      IMAGE_NAME: service
      IMAGE_TAG: 1.1.0

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Create cluster
        uses: helm/[email protected]

      - name: Read secrets from AWS Secrets Manager into environment variables
        uses: abhilash1in/[email protected]
        id: read-secrets
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ env.AWS_REGION }}
          secrets: |
            users-service/secrets
          parse-json: true

      - name: Build and Tag Image 
        id: build-image
        run: |
          # Build a docker container and Tag
          docker build --file Dockerfile \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

      - name: Push Image to Kind cluster 
        id: kind-cluster-image-push
        env: 
          KIND_IMAGE: ${{ steps.build-image.outputs.image }}
          CLUSTER_NAME: chart-testing
          CLUSTER_CONTROLLER: chart-testing-control-plane
        run: |
          kind load docker-image $KIND_IMAGE --name $CLUSTER_NAME
          docker exec $CLUSTER_CONTROLLER crictl images

Dockerfile*

FROM node:14 AS base
WORKDIR /app

FROM base AS development

COPY .npmrc .npmrc
COPY package.json ./
RUN npm install --production
RUN cp -R node_modules /tmp/node_modules
RUN npm install 
RUN rm -f .npmrc 
COPY . .

FROM development AS builder
COPY .npmrc .npmrc
RUN yarn run build
RUN rm -f .npmrc 
RUN ls -la

FROM node:14-alpine AS production

# Install curl
RUN apk update && apk add curl

COPY --from=builder /tmp/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./


ARG APP_API
                        
# set environmental variables

ENV APP_API=$APP_API

EXPOSE ${PORT}

CMD [ "yarn", "start" ]

我猜问题出在构建命令之类的地方,这些是我尝试过的不同东西

我明确使用了 --file 和句点(.)*

docker build --file Dockerfile \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

我只使用了句点 (.)

docker build \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

我使用了 Dockerfile 的相对路径 (./Dockerfile)

docker build --file ./Dockerfile \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

我使用了句点的相对路径(./)

docker build \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG ./
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

我已经用尽了我从 SO 中读到的所有内容

I am trying to build and tag a docker image in Github Actions runner and am getting this error from the runner

unable to prepare context: path " " not found
Error: Process completed with exit code 1.

I have gone through all other similar issues on StackOverflow and implemented them but still, no way forward.

The interesting thing is, I have other microservices using similar workflow and Dockerfile working perfectly fine.

My workflow

name: some-tests

on:
  pull_request:
    branches: [ main ]

jobs:
  tests:
    runs-on: ubuntu-latest
    env: 
      AWS_REGION: us-east-1
      IMAGE_NAME: service
      IMAGE_TAG: 1.1.0

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Create cluster
        uses: helm/[email protected]

      - name: Read secrets from AWS Secrets Manager into environment variables
        uses: abhilash1in/[email protected]
        id: read-secrets
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ env.AWS_REGION }}
          secrets: |
            users-service/secrets
          parse-json: true

      - name: Build and Tag Image 
        id: build-image
        run: |
          # Build a docker container and Tag
          docker build --file Dockerfile \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

      - name: Push Image to Kind cluster 
        id: kind-cluster-image-push
        env: 
          KIND_IMAGE: ${{ steps.build-image.outputs.image }}
          CLUSTER_NAME: chart-testing
          CLUSTER_CONTROLLER: chart-testing-control-plane
        run: |
          kind load docker-image $KIND_IMAGE --name $CLUSTER_NAME
          docker exec $CLUSTER_CONTROLLER crictl images

Dockerfile*

FROM node:14 AS base
WORKDIR /app

FROM base AS development

COPY .npmrc .npmrc
COPY package.json ./
RUN npm install --production
RUN cp -R node_modules /tmp/node_modules
RUN npm install 
RUN rm -f .npmrc 
COPY . .

FROM development AS builder
COPY .npmrc .npmrc
RUN yarn run build
RUN rm -f .npmrc 
RUN ls -la

FROM node:14-alpine AS production

# Install curl
RUN apk update && apk add curl

COPY --from=builder /tmp/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./


ARG APP_API
                        
# set environmental variables

ENV APP_API=$APP_API

EXPOSE ${PORT}

CMD [ "yarn", "start" ]

I guess the problem is coming from the building command or something, these are the different things I have tried

I used --file explicitly with period(.)*

docker build --file Dockerfile \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

I used only period (.)

docker build \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

I used relative path for Dockerfile (./Dockerfile)

docker build --file ./Dockerfile \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG .
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

I used relative path for the period (./)

docker build \
          --build-arg APP_API=$USERS_SERVICE_SECRETS_APP_API \
          -t $IMAGE_NAME:$IMAGE_TAG ./
          echo "::set-output name=image::$IMAGE_NAME:$IMAGE_TAG"

I have literally exhausted everything I've read from SO

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2025-01-16 23:46:08

这个问题基本上是一个空白问题。没有什么可以证明这一点。感谢 这个 Github 答案

The problem was basically a white-spacing issue. Nothing could show this. Thanks to This Github answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文