frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

not a git repository when building single binary app

Open sawirricardo opened this issue 1 year ago • 15 comments

What happened?

encounter not a git repository error when using docker static builder Dockerfile is based on https://frankenphp.dev/docs/embed/

Build Type

Docker (Debian Bookworm)

Worker Mode

Yes

Operating System

GNU/Linux

CPU Architecture

Apple Silicon

PHP configuration

none

Relevant log output

No response

sawirricardo avatar Mar 20 '24 17:03 sawirricardo

was using this instead, but dunno if this one is recommended

FROM --platform=linux/amd64 dunglas/frankenphp:static-builder AS builder

# Copy your app
WORKDIR /go/src/app/dist/app
COPY . .
# RUN composer install --ignore-platform-reqs --no-dev -a
RUN rm -rf tests/


# Build the static binary, be sure to select only the PHP extensions you want
WORKDIR /go/src/app/
RUN git clone https://github.com/dunglas/frankenphp
WORKDIR /go/src/app/frankenphp
RUN EMBED=../dist/app/ \
    ./build-static.sh

sawirricardo avatar Mar 20 '24 17:03 sawirricardo

i am having the same problem.

Aldoo24 avatar Mar 25 '24 11:03 Aldoo24

Do you have .git listed in your .dockerignore?

Also, can you share the build output? What isn't a git repository?

withinboredom avatar Mar 25 '24 12:03 withinboredom

i have deleted my .git folder. when running ./build-static.sh the build fails with the error:
fatal: not a git repository (or any of the parent directories): .git also, ERROR: failed to solve: process "/bin/ash -eo pipefail -c EMBED=dist/app/ ./build-static.sh" did not complete successfully: exit code: 128

Aldoo24 avatar Mar 25 '24 13:03 Aldoo24

If you deleted the git folder and receive an error about missing a git folder... what is the bug?

withinboredom avatar Mar 25 '24 22:03 withinboredom

I don't think it is referring to the git folder in my project. I tried with the git folder, including it in my .dockerignore file and got the same error again.

Aldoo24 avatar Mar 26 '24 08:03 Aldoo24

Small investigation show, that this happens here https://github.com/dunglas/frankenphp/blob/main/build-static.sh#L35-L53. Obvious, here is no git repo

86bb8340f495:/go/src/app# ls -la
total 184
drwxr-xr-x    1 root     root          4096 Mar 27 00:19 .
drwxrwxrwt    1 root     root          4096 Mar 27 00:18 ..
drwxr-xr-x    2 root     root          4096 Mar 27 00:18 C-Thread-Pool
-rw-r--r--    1 root     root             0 Mar 27 00:18 app.tar
-rw-r--r--    1 root     root             0 Mar 27 00:18 app_checksum.txt
-rwxr-xr-x    1 root     root          4842 Mar 28 12:35 build-static.sh
drwxr-xr-x    1 root     root          4096 Mar 27 00:18 caddy
-rw-r--r--    1 root     root          7045 Mar 27 00:18 cgi.go
drwxr-xr-x    1 root     root          4096 Mar 28 12:20 dist
-rw-r--r--    1 root     root          5337 Mar 27 00:18 embed.go
-rw-r--r--    1 root     root         29417 Mar 27 00:18 frankenphp.c
-rw-r--r--    1 root     root         20591 Mar 27 00:18 frankenphp.go
-rw-r--r--    1 root     root          1624 Mar 27 00:18 frankenphp.h
-rw-r--r--    1 root     root          2700 Mar 27 00:18 frankenphp_arginfo.h
-rw-r--r--    1 root     root         27981 Mar 27 00:18 frankenphp_test.go
-rw-r--r--    1 root     root           718 Mar 27 00:18 go.mod
-rw-r--r--    1 root     root          3304 Mar 27 00:18 go.sum
-rw-r--r--    1 root     root          1008 Mar 27 00:18 options.go
-rw-r--r--    1 root     root          7684 Mar 27 00:18 recorder_test.go
-rw-r--r--    1 root     root          2528 Mar 27 00:18 request_options.go
-rw-r--r--    1 root     root          1488 Mar 27 00:18 smartpointer.go
-rw-r--r--    1 root     root          4842 Mar 27 00:18 worker.go
-rw-r--r--    1 root     root          3695 Mar 27 00:18 worker_test.go

But you can run ./dist/frankenphp-linux-x86_64 version to see version , and then export FRANKENPHP_VERSION=1.1.2 (in my case), and then EMBED=dist/app/ PHP_EXTENSIONS=<your_extensions> ./build-static.sh

vladislavs1321 avatar Mar 28 '24 13:03 vladislavs1321

It worked, thank you so much

Aldoo24 avatar Mar 28 '24 13:03 Aldoo24

@Aldoo24 How do you resolve the issue? Regarding @vladislavs1321's comment, I am not sure how to follow his steps (for example, how to run ./dist/frankenphp-linux-x86_64 version ?, it seems the commands need to run inside the static-app container)

HuyNguyen206 avatar Apr 01 '24 10:04 HuyNguyen206

This is my dockerfile @HuyNguyen206

FROM --platform=linux/amd64 dunglas/frankenphp:static-builder-1.1.2

# Copy your app
WORKDIR /go/src/app/dist/app
COPY . .

# Build the static binary, be sure to select only the PHP extensions you want
WORKDIR /go/src/app/
RUN ./dist/frankenphp-linux-x86_64 version \
    export FRANKENPHP_VERSION=1.1.2 \
    EMBED=dist/app/ \
    ./build-static.sh

Aldoo24 avatar Apr 02 '24 07:04 Aldoo24

Thank you @Aldoo24 , it worked

HuyNguyen206 avatar Apr 02 '24 10:04 HuyNguyen206

EDIT: I did miss that it was running ./dist/frankenphp-linux-x86_64 version initially

I tried with Aldoo's dockerfile but I get the following issue now:

 => ERROR [stage-2 5/5] RUN EMBED=/var/www/app     export FRANKENPHP_VERSION=1.1.2     PHP_EXTENSIONS=ctype,iconv  0.3s
------
 > [stage-2 5/5] RUN EMBED=/var/www/app     export FRANKENPHP_VERSION=1.1.2     PHP_EXTENSIONS=ctype,iconv     ./build-static.sh:
0.252 /bin/ash: export: line 0: ./build-static.sh: bad variable name
------
static-builder.Dockerfile:43
--------------------
  42 |     WORKDIR /go/src/app/
  43 | >>> RUN EMBED=/var/www/app \
  44 | >>>     export FRANKENPHP_VERSION=1.1.2 \
  45 | >>>     PHP_EXTENSIONS=ctype,iconv \
  46 | >>>     ./build-static.sh
  47 |
--------------------
ERROR: failed to solve: process "/bin/ash -eo pipefail -c EMBED=/var/www/app     export FRANKENPHP_VERSION=1.1.2     PHP_EXTENSIONS=ctype,iconv     ./build-static.sh" did not complete successfully: exit code: 2

Is this a tyop in /bin/bash but shows /bin/ash ?

IronSinew avatar Apr 03 '24 19:04 IronSinew

Run ./dist/frankenphp-linux-x86_64 export FRANKENPHP_VERSION=1.1.2 before running EMBED

Aldoo24 avatar Apr 04 '24 14:04 Aldoo24

hi @Aldoo24 , after generating the binary successfully, when I try to run: sudo ./my-app php-server, then navigate to http://localhost/, response is 404. Have you facing this issue yet? If yes, how can you resolve this one? Thank you. image image

HuyNguyen206 avatar Apr 12 '24 09:04 HuyNguyen206

sudo ./my-app php-server runs a php server from your current directory. Try sudo ./my-app run

withinboredom avatar Apr 12 '24 11:04 withinboredom

sudo ./my-app php-server runs a php server from your current directory. Try sudo ./my-app run

I tried run and start also but problem remains still same. No content on localhost. Is there any fix?

skmirajbn avatar Apr 15 '24 05:04 skmirajbn

@skmirajbn this doesn't look related to the original issue. Can you please open a new issue (if none already exists for this problem) and provide us with a reproducer?

Closing as there is no issue here, this works as documented: https://frankenphp.dev/docs/embed/ The script has to be run from the directory containing the sources of FrankenPHP.

dunglas avatar Apr 15 '24 15:04 dunglas

Closing as there is no issue here, this works as documented: https://frankenphp.dev/docs/embed/ The script has to be run from the directory containing the sources of FrankenPHP.

@dunglas Example Dockerfile at https://frankenphp.dev/docs/embed/#creating-a-linux-binary suggests that you don't need frankenphp checked out during Docker image build process.

I think one option is to export ENV FRANKENPHP_VERSION=<currentVersion> during the build time of dunglas/frankenphp:static-builder, to ensure that it defaults to the version of FrankenPHP bundled in the image.

dejanceltra avatar Apr 17 '24 16:04 dejanceltra

@dejanceltra the Docker image contains a copy of FrankenPHP source in its default directory. If you change the default directory using WORKDIR and don't go back in the original one after (as done in the example), this will not work.

dunglas avatar Apr 17 '24 17:04 dunglas

Small investigation show, that this happens here https://github.com/dunglas/frankenphp/blob/main/build-static.sh#L35-L53. Obvious, here is no git repo

86bb8340f495:/go/src/app# ls -la
total 184
drwxr-xr-x    1 root     root          4096 Mar 27 00:19 .
drwxrwxrwt    1 root     root          4096 Mar 27 00:18 ..
drwxr-xr-x    2 root     root          4096 Mar 27 00:18 C-Thread-Pool
-rw-r--r--    1 root     root             0 Mar 27 00:18 app.tar
-rw-r--r--    1 root     root             0 Mar 27 00:18 app_checksum.txt
-rwxr-xr-x    1 root     root          4842 Mar 28 12:35 build-static.sh
drwxr-xr-x    1 root     root          4096 Mar 27 00:18 caddy
-rw-r--r--    1 root     root          7045 Mar 27 00:18 cgi.go
drwxr-xr-x    1 root     root          4096 Mar 28 12:20 dist
-rw-r--r--    1 root     root          5337 Mar 27 00:18 embed.go
-rw-r--r--    1 root     root         29417 Mar 27 00:18 frankenphp.c
-rw-r--r--    1 root     root         20591 Mar 27 00:18 frankenphp.go
-rw-r--r--    1 root     root          1624 Mar 27 00:18 frankenphp.h
-rw-r--r--    1 root     root          2700 Mar 27 00:18 frankenphp_arginfo.h
-rw-r--r--    1 root     root         27981 Mar 27 00:18 frankenphp_test.go
-rw-r--r--    1 root     root           718 Mar 27 00:18 go.mod
-rw-r--r--    1 root     root          3304 Mar 27 00:18 go.sum
-rw-r--r--    1 root     root          1008 Mar 27 00:18 options.go
-rw-r--r--    1 root     root          7684 Mar 27 00:18 recorder_test.go
-rw-r--r--    1 root     root          2528 Mar 27 00:18 request_options.go
-rw-r--r--    1 root     root          1488 Mar 27 00:18 smartpointer.go
-rw-r--r--    1 root     root          4842 Mar 27 00:18 worker.go
-rw-r--r--    1 root     root          3695 Mar 27 00:18 worker_test.go

But you can run ./dist/frankenphp-linux-x86_64 version to see version , and then export FRANKENPHP_VERSION=1.1.2 (in my case), and then EMBED=dist/app/ PHP_EXTENSIONS=<your_extensions> ./build-static.sh

If it is the case, So don't we need to update the documentation according to this?

skmirajbn avatar Apr 17 '24 18:04 skmirajbn

What happened?

encounter not a git repository error when using docker static builder Dockerfile is based on https://frankenphp.dev/docs/embed/

Build Type

Docker (Debian Bookworm)

Worker Mode

Yes

Operating System

GNU/Linux

CPU Architecture

Apple Silicon

PHP configuration

none

Relevant log output

No response

This problem still exists. Currently after following this instruction we got this git error..

I don't know why the issue is closed.

skmirajbn avatar Apr 17 '24 18:04 skmirajbn

@dejanceltra the Docker image contains a copy of FrankenPHP source in its default directory. If you change the default directory using WORKDIR and don't go back in the original one after (as done in the example), this will not work.

With the exception of allowed files, all others are ignored for Docker context, including .git: https://github.com/dunglas/frankenphp/blob/main/.dockerignore#L2

dejanceltra avatar Apr 18 '24 06:04 dejanceltra

@dejanceltra the Docker image contains a copy of FrankenPHP source in its default directory. If you change the default directory using WORKDIR and don't go back in the original one after (as done in the example), this will not work.

With the exception of allowed files, all others are ignored for Docker context, including .git: https://github.com/dunglas/frankenphp/blob/main/.dockerignore#L2

What would be the official instruction to solve this problem? I followed the documentation and if it is not working as expected, shouldn't the documentation need to be updated?

skmirajbn avatar Apr 18 '24 06:04 skmirajbn

I'll try to take a look today. The .git should not be necessary as long as the FRANKENPHP_VERSION env car is defined and the sources (event without .git) are available in the main builder image, which should be the case.

dunglas avatar Apr 18 '24 06:04 dunglas

I'll try to take a look today. The .git should not be necessary as long as the FRANKENPHP_VERSION env car is defined and the sources (event without .git) are available in the main builder image, which should be the case.

The problem is if anyone just follow This page to create standalone binary it not work. He will just get an error.

In the below screenshot, I modified the Dockerfile:

image

I tried this. On this file, I didn't get any error during building process but after the build when I tried to run the app using

./filename run or ./filename start or ./filename php-server

It shows in the terminal looks like the server is running but in the browser nothing is coming.

Tring to figure out the problem in the last 4 - 5 days. Still unsuccessful.

skmirajbn avatar Apr 18 '24 06:04 skmirajbn

@skmirajbn That's a separate issue, not related to the missing FRANKENPHP_VERSION.

dejanceltra avatar Apr 18 '24 07:04 dejanceltra

@skmirajbn you must use the php-server sub command, not run unless you provide a custom Caddyfile. https://frankenphp.dev/docs/embed/#using-the-binary

dunglas avatar Apr 18 '24 07:04 dunglas

@skmirajbn also I don't find the difference between the Dockerfile in your screenshot and the one in the docs.

dunglas avatar Apr 18 '24 07:04 dunglas

I'll try to take a look today. The .git should not be necessary as long as the FRANKENPHP_VERSION env car is defined and the sources (event without .git) are available in the main builder image, which should be the case.

ARG FRANKENPHP_VERSION is defined during the build of static-builder.Dockerfile, so this build succeeds, but ARGs are not included in the final image, so are not available when running dunglas/frankenphp:static-builder image.

dejanceltra avatar Apr 18 '24 07:04 dejanceltra

@skmirajbn also I don't find the difference between the Dockerfile in your screenshot and the one in the docs.

If I just remove this line ./dist/frankenphp-linux-x86_64 version \

The git error reappears. I don't know why

Here is the screenshot

image

In original documentation the added line doesn't exist.

skmirajbn avatar Apr 18 '24 07:04 skmirajbn