Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load custom Caddyfile from embedded app if it exists #494

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

pierredup
Copy link
Contributor

Use the embedded Caddyfile if the embedded app contains a Caddyfile at the root

Fixes #413

Copy link
Owner

@dunglas dunglas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement!

I left some minor comments.

caddy/php-server.go Outdated Show resolved Hide resolved
caddy/php-server.go Outdated Show resolved Hide resolved
@dunglas dunglas merged commit bccbaaf into dunglas:main Jan 22, 2024
26 checks passed
@dunglas
Copy link
Owner

dunglas commented Jan 22, 2024

Thank you!

@pierredup pierredup deleted the custom-caddyfile branch January 22, 2024 12:36
@sneycampos
Copy link
Contributor

Could you guys provide a simple explanation how it works? i'm using the latest builder to add caddy-exec module, created a Caddyfile in my application root folder (/app/Caddyfile) but doesn't see to work

This is my code:

Dockerfile:

FROM dunglas/frankenphp:latest-builder AS builder

# Copy xcaddy in the builder image
COPY --from=caddy:builder /usr/bin/xcaddy /usr/bin/xcaddy

# CGO must be enabled to build FrankenPHP
ENV CGO_ENABLED=1 XCADDY_SETCAP=1 XCADDY_GO_BUILD_FLAGS="-ldflags '-w -s'"
RUN xcaddy build \
	--output /usr/local/bin/frankenphp \
	--with github.com/dunglas/frankenphp=./ \
	--with github.com/dunglas/frankenphp/caddy=./caddy/ \
    --with github.com/dunglas/caddy-cbrotli \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/dunglas/vulcain/caddy \
    --with github.com/abiosoft/caddy-exec

FROM dunglas/frankenphp AS runner

ENV SERVER_NAME=:80

COPY . /app
WORKDIR /app

# Replace the official binary by the one contained your custom modules
COPY --from=builder /usr/local/bin/frankenphp /usr/local/bin/frankenphp

Caddyfile

{
    exec php /app/artisan optimize
    exec php /app/artisan about
}

Logs:

php-1  | {"level":"info","ts":1710106973.2761014,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
php-1  | {"level":"warn","ts":1710106973.276807,"msg":"Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/Caddyfile","line":16}
php-1  | {"level":"info","ts":1710106973.2775857,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
php-1  | {"level":"warn","ts":1710106973.277728,"logger":"http.auto_https","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
php-1  | {"level":"info","ts":1710106973.2778854,"msg":"FrankenPHP started 🐘","php_version":"8.3.3"}
php-1  | {"level":"info","ts":1710106973.2780004,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
php-1  | {"level":"info","ts":1710106973.2781467,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
php-1  | {"level":"info","ts":1710106973.2781534,"msg":"serving initial configuration"}
php-1  | {"level":"info","ts":1710106973.2782197,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x4000333580"}
php-1  | {"level":"info","ts":1710106973.278656,"logger":"tls","msg":"cleaning storage unit","storage":"FileStorage:/data/caddy"}
php-1  | {"level":"info","ts":1710106973.278754,"logger":"tls","msg":"finished cleaning storage units"}

Should my Caddyfile be same as default and may i change adding these module commands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to configure Caddyfile inside a Standalone application ?
3 participants