vulnerability-lookup icon indicating copy to clipboard operation
vulnerability-lookup copied to clipboard

Docker: error building image from .zip | missing .git directory

Open LukeVader-IV opened this issue 4 months ago • 4 comments

Steps to Reproduce:

  1. wget [LATEST ZIP FROM RELEASES]
  2. docker compose up -d

when the image is being built, the following error appears:

 => CACHED [20/43] RUN poetry install                                                                                     0.0s
 => CACHED [21/43] RUN echo VULNERABILITYLOOKUP_HOME="/main/app" >> .env                                                  0.0s
 => ERROR [22/43] COPY .git ./.git/                                                                                       0.0s
------
 > [22/43] COPY .git ./.git/:
------
Dockerfile:42

--------------------

  40 |     RUN echo VULNERABILITYLOOKUP_HOME="${APP_DIR}" >> .env

  41 |

  42 | >>> COPY .git ./.git/

  43 |     COPY .gitignore .gitmodules ./

  44 |     COPY .github ./github/

--------------------

failed to solve: failed to compute cache key: failed to calculate checksum of ref 9cc62f56-1db5-4a9b-aaae-3696af9c8d85::mjn73m9k8t6qsmiit0tqkwey1: "/.git": not found

LukeVader-IV avatar Jul 07 '25 08:07 LukeVader-IV

I initially tried to try building from the git repo, but that caused a different error. That's why i decided to fetch the .zip file. When using git clone [REPO] instead, or adding an empty .git directory to the zip extracted dir:

 => [ 3/43] RUN pipx install poetry && env                                                                               78.7s
 => [ 4/43] WORKDIR /main/app                                                                                             4.4s
 => [ 5/43] ADD https://github.com/gocsaf/csaf/releases/download/v3.2.0/csaf-3.2.0-gnulinux-amd64.tar.gz /opt/csaf_archi  5.7s
 => ERROR [ 6/43] RUN mkdir /opt/csaf && tar xzvf /opt/csaf_archive.tar.gz -C "/build/csaf_distribution/bin-linux-amd64"  4.5s
------
 > [ 6/43] RUN mkdir /opt/csaf && tar xzvf /opt/csaf_archive.tar.gz -C "/build/csaf_distribution/bin-linux-amd64":
4.052 tar: /build/csaf_distribution/bin-linux-amd64: Cannot open: No such file or directory
4.052 tar: Error is not recoverable: exiting now
------
Dockerfile:22

--------------------

  20 |     WORKDIR ${APP_DIR}

  21 |     ADD "https://github.com/gocsaf/csaf/releases/download/v${CSAF_VERSION}/csaf-${CSAF_VERSION}-gnulinux-amd64.tar.gz" /opt/csaf_archive.tar.gz

  22 | >>> RUN mkdir /opt/csaf && tar xzvf /opt/csaf_archive.tar.gz -C "${CSAF_PATH}"

  23 |     RUN mv "${CSAF_PATH}/csaf-${CSAF_VERSION}-gnulinux-amd64/bin-linux-amd64" "${CSAF_PATH}"

  24 |     RUN rm -rf /opt/csaf_archive.tar.gz

--------------------

failed to solve: process "/bin/sh -c mkdir /opt/csaf && tar xzvf /opt/csaf_archive.tar.gz -C \"${CSAF_PATH}\"" did not complete successfully: exit code: 2

LukeVader-IV avatar Jul 07 '25 08:07 LukeVader-IV

Hmmm... currently on vacation; unable to troubleshoot for the next couple of weeks I'm afraid... should be an easy fix though...

P-T-I avatar Jul 08 '25 14:07 P-T-I

@LukeVader-IV Is this still an issue for you? I cannot reproduce it from the current master; please note that the dockerfile (as you've noticed already) is expected to run from a cloned repo...

P-T-I avatar Aug 12 '25 13:08 P-T-I

It seems that you have to add a mkdir in your Dockerfile before uncompressing the archive.

WORKDIR ${APP_DIR}
ADD "https://github.com/gocsaf/csaf/releases/download/v${CSAF_VERSION}/csaf-${CSAF_VERSION}-gnulinux-amd64.tar.gz" /opt/csaf_archive.tar.gz
RUN mkdir -p ${CSAF_PATH} /opt/csaf && tar xzvf /opt/csaf_archive.tar.gz -C "${CSAF_PATH}"
RUN mv "${CSAF_PATH}/csaf-${CSAF_VERSION}-gnulinux-amd64/bin-linux-amd64" "${CSAF_PATH}"
RUN rm -rf /opt/csaf_archive.tar.gz

@P-T-I maybe your env file is not the one by default, that's why you can't reproduce the bug ?

y0no avatar Oct 13 '25 13:10 y0no