dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.88k stars 235 forks source link

not a git repository when building single binary app #680

Closed sawirricardo closed 6 months ago

sawirricardo commented 7 months ago

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 commented 7 months ago

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
Aldoo24 commented 7 months ago

i am having the same problem.

withinboredom commented 7 months ago

Do you have .git listed in your .dockerignore?

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

Aldoo24 commented 7 months ago

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

withinboredom commented 7 months ago

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

Aldoo24 commented 7 months ago

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.

vladislavs1321 commented 7 months ago

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

Aldoo24 commented 7 months ago

It worked, thank you so much

HuyNguyen206 commented 7 months ago

@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)

Aldoo24 commented 7 months ago

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
HuyNguyen206 commented 7 months ago

Thank you @Aldoo24 , it worked

IronSinew commented 7 months ago

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 ?

Aldoo24 commented 7 months ago

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

HuyNguyen206 commented 7 months ago

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

withinboredom commented 7 months ago

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

skmirajbn commented 6 months ago

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?

dunglas commented 6 months ago

@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.

dejanceltra commented 6 months ago

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.

dunglas commented 6 months ago

@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.

skmirajbn commented 6 months ago

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 commented 6 months ago

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.

dejanceltra commented 6 months ago

@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

skmirajbn commented 6 months ago

@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?

dunglas commented 6 months ago

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.

skmirajbn commented 6 months ago

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.

dejanceltra commented 6 months ago

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

dunglas commented 6 months ago

@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 commented 6 months ago

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

dejanceltra commented 6 months ago

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.

skmirajbn commented 6 months ago

@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.

dunglas commented 6 months ago

Ok thank you very much @dejanceltra I think I get the problem!