sam hassan
sam hassan

Reputation: 217

unable to prepare context: path " " not found for Github Actions Runner

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

Upvotes: 1

Views: 3800

Answers (1)

sam hassan
sam hassan

Reputation: 217

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

Upvotes: 3

Related Questions