2

I'm currently trying to set up GitHub actions, to automatically build and push a backend to DockerHub. However, if the workflow build-and-deploy-backend is triggered it starts creating the Docker Image but fails at the line 23 in the server/Dockerfile:

  22 |     COPY ./src ./src
  23 | >>> COPY ./tsconfig.json ./

See: https://github.com/bennodev19/dronies-watch/runs/4813916640?check_suite_focus=true

with this Error:

Dockerfile:23
--------------------
  21 |     # Move required app source into the working directory referenced with './'
  22 |     COPY ./src ./src
  23 | >>> COPY ./tsconfig.json ./
  24 |     
  25 |     # For debugging:
--------------------
error: failed to solve: failed to compute cache key: "/tsconfig.json": not found
Error: buildx failed with: error: failed to solve: failed to compute cache key: "/tsconfig.json": not found

See: https://github.com/bennodev19/dronies-watch/runs/4813916640?check_suite_focus=true

Locally it builds without any problem. Tested on MacOS and Windows 10.

build-and-deploy-backend

# *

jobs:
  build-and-deploy-backend:
    name:  Build Backend Image for Prod & Push to Dockerhub
    runs-on: ubuntu-latest
    steps:
      - name:  Checkout
        uses: actions/checkout@v2

      - name:  Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

      - name:  Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name:  Build and push Docker Image to DockerHub
         id: docker_build
         uses: docker/build-push-action@v2
         with:
          context: .
          file: server/Dockerfile # Path to the Dockerfile from which to build the Docker Image from (default {context}/Dockerfile)
          builder: ${{ steps.buildx.outputs.name }}
          push: true
          tags: latest

      - name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

See full file: https://github.com/bennodev19/dronies-watch/blob/master/.github/workflows/release.yaml

server/Dockerfile

FROM node:lts-alpine

RUN mkdir -p /app
WORKDIR /app

COPY package.json ./
COPY yarn.lock ./
RUN yarn install

COPY src ./src
COPY tsconfig.json ./

RUN yarn build

CMD [ "yarn", "start" ]

EXPOSE 5000

See full file: https://github.com/bennodev19/dronies-watch/blob/master/server/Dockerfile

Other

BennoDev
  • 1,067
  • 1
  • 6
  • 17
  • 1
    It seems you're just supplying the path to dockerfile, but you are running the docker build from your repo root, so context provided to docker build is on wrong path. Try with `context: ./server` – frennky Jan 14 '22 at 11:39

0 Answers0