Home > database >  I can't create a docker image in a monorepo with github actions
I can't create a docker image in a monorepo with github actions

Time:10-14

I'm trying to create a workflow that builds and pushes a docker image to the docker hub using https://github.com/docker/build-push-action.

I have a monorepo with a folder structure like this:

project
    api
        Dockerfile
    client

and this is the workflow:

name: deploy

on:
  push:
    branches:
      - main
    paths:
      - "api/**"

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: repo/kheilyshad-api:latest
          context: .
          file: api/Dockerfile

it always fails with this error:

/usr/bin/docker buildx build --tag ***/kheilyshad-api:latest --iidfile /tmp/docker-build-push-yGQ2mf/iidfile --metadata-file /tmp/docker-build-push-yGQ2mf/metadata-file --file api/Dockerfile --push .
error: could not find api: stat api: no such file or directory
Error: buildx failed with: error: could not find api: stat api: no such file or directory

I have to build the docker image in the root so I use file to specify the path to Dockerfile. it's basically like this

docker build -f ./api/Dockerfile .

but it couldn't find the api folder. I tried to set the file to ./api/Dockerfile, api, etc. but none of them work.

CodePudding user response:

Seems like you're not checking out the repo. Try to add actions/checkout@v2 to your steps:

steps:
  - uses: actions/checkout@v2
  • Related