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

Input query/post data and return script stdout in response? #7

Open
patxipierce opened this issue Dec 16, 2020 · 3 comments
Open

Input query/post data and return script stdout in response? #7

patxipierce opened this issue Dec 16, 2020 · 3 comments

Comments

@patxipierce
Copy link

Hello, and thanks so much for this great module. <3

I have looked for caddy-exec related issues and in the caddy documentation to see if I am missing something. But now I come to you, my last hope. :-)

My setup:

I'm building a caddy image with caddy-exec and caddy-hmac like so:

$PWD\docker-compose.yml

version: "3.7"

services:
    caddy:
        build:
            context: .
            dockerfile: $PWD/config/caddy/caddy.Dockerfile
        container_name: caddy
        restart: unless-stopped
        ports:
            - "80:80"
            - "443:443"
        env_file:
            - $PWD/config/secrets/local.env
        volumes:
            - $PWD/config/caddy/Caddyfile:/etc/caddy/Caddyfile
            - $PWD/site:/site
            - $PWD/api:/api
            - caddy_data:/data
            - caddy_config:/config

volumes:
  caddy_data:
  caddy_config:

My $PWD/config/secrets/local.env file:

# Use localhost for local or an IP or Domain
SITE_ADDRESS=localhost

# API key
API_KEY=abcde123456

$PWD/config/caddy/caddy.Dockerfile

FROM caddy:2.2.1-builder-alpine AS builder

RUN xcaddy build v2.2.1 \
	--with github.com/abiosoft/caddy-exec \
	--with github.com/abiosoft/caddy-hmac

FROM caddy:2.2.1-alpine
COPY --from=builder /usr/bin/caddy /usr/bin/caddy

# Install python3
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache \
	python3 && ln -sf /bin/python3 /usr/bin/python

And my $PWD/config/caddy/Caddyfile:


{$SITE_ADDRESS} {

    root / /site/index.html
    header Content-type application/json
    file_server

    # API Routes

    route /api/example/python {
        exec {
            command     /usr/bin/python3
            args \
                /api/example/python/python-example.py \
                {$API_KEY} \
                {query}
            directory   /api/example/python
            timeout     5s
            foreground
        }
    }
}

My issue(s):

1.- So far I can pass my env vars to the scripts (not only python, but bash and other unforeseen languages), but the {query} shows up in the logs as {http.request.uri.query}, and not the intended string.

2.- Then I only see a JSON response giving a success status, or error status, but I do not see how to pass my scripts output to the response.

Any insight about something that I'm obviously missing is appreciated. And thank you again for the support, documentation and development you have provided so far.

@abiosoft
Copy link
Owner

Yeah, placeholders aren't interpreted. Since this looks like a common use-case I will add that functionality.

@git001
Copy link
Contributor

git001 commented May 4, 2022

Any Update on this issue?

git001 added a commit to git001/caddy-exec that referenced this issue May 4, 2022
@Salpadding
Copy link

xcaddy build \
    --with github.com/aksdb/caddy-cgi/v2 

maybe you want a cgi extension

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

No branches or pull requests

4 participants