Trouble Setting up Vapor API

This is my first time deploying a server and I am having some trouble getting the API working. After I have successfully deployed I get a 502 bad gateway error to the API. For some background context, I am using vapor and have the default docker file in my vapor project. I am connected to the Supabse Fly database and set the URL and POOL env variables in the fly secrets screen. Lastly I included how i am setting up my configure vapor app and included some of the logs that I am receiving. If anyone has any insight it would greatly be appreciated.

    if let url = Environment.get("DATABASE_URL") {
        app.databases.use(try DatabaseConfigurationFactory.postgres(url: url), as: .psql)
    } else {
        app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init(
            hostname: "127.0.0.1",
            port: 54322,
            username: "postgres",
            password: "postgres",
            database: "postgres",
            tls: .prefer(try .init(configuration: .clientDefault)))
        ), as: .psql)
    }
2024-10-08T01:16:32.144 app[6e8257dda7d248] sjc [info] [ 0.301965] PCI: Fatal: No config space access function found

2024-10-08T01:16:32.582 app[6e8257dda7d248] sjc [info] INFO Starting init (commit: e07a8d0e)...

2024-10-08T01:16:32.735 app[6e8257dda7d248] sjc [info] INFO Preparing to run: `./App serve --env production --hostname 0.0.0.0 --port 8080` as vapor

2024-10-08T01:16:32.742 app[6e8257dda7d248] sjc [info] INFO [fly api proxy] listening at /.fly/api

2024-10-08T01:16:32.751 app[6e8257dda7d248] sjc [info] ERROR stderr to vsock zero copy err: Broken pipe (os error 32)

2024-10-08T01:16:32.751 runner[6e8257dda7d248] sjc [info] Machine started in 1.151s

2024-10-08T01:16:32.899 app[6e8257dda7d248] sjc [info] 2024/10/08 01:16:32 INFO SSH listening listen_address=[fdaa:a:5dc9:a7b:335:8704:d9b9:2]:22 dns_server=[fdaa::3]:53

2024-10-08T01:16:33.742 app[6e8257dda7d248] sjc [info] INFO Main child exited normally with code: 127

2024-10-08T01:16:33.757 app[6e8257dda7d248] sjc [info] INFO Starting clean up.

2024-10-08T01:16:33.761 app[6e8257dda7d248] sjc [info] WARN could not unmount /rootfs: EINVAL: Invalid argument

2024-10-08T01:16:33.762 app[6e8257dda7d248] sjc [info] [ 1.919571] reboot: Restarting system

2024-10-08T01:16:34.173 runner[6e8257dda7d248] sjc [info] machine has reached its max restart count of 10

2024-10-08T01:16:39.699 app[6e8257d4b02e28] sjc [info] 2024-10-08T01:16:39.699318524 [01J9MT5EC1YSBNECNRN0R6ZPA0:main] Running Firecracker v1.7.0

2024-10-08T01:16:40.096 app[6e8257d4b02e28] sjc [info] [ 0.297445] PCI: Fatal: No config space access function found

2024-10-08T01:16:40.522 app[6e8257d4b02e28] sjc [info] INFO Starting init (commit: e07a8d0e)...

2024-10-08T01:16:40.690 app[6e8257d4b02e28] sjc [info] INFO Preparing to run: `./App serve --env production --hostname 0.0.0.0 --port 8080` as vapor

2024-10-08T01:16:40.697 app[6e8257d4b02e28] sjc [info] INFO [fly api proxy] listening at /.fly/api

2024-10-08T01:16:40.707 app[6e8257d4b02e28] sjc [info] ERROR stderr to vsock zero copy err: Broken pipe (os error 32)

2024-10-08T01:16:40.714 runner[6e8257d4b02e28] sjc [info] Machine started in 1.104s

2024-10-08T01:16:40.895 app[6e8257d4b02e28] sjc [info] 2024/10/08 01:16:40 INFO SSH listening listen_address=[fdaa:a:5dc9:a7b:336:64ee:6ac8:2]:22 dns_server=[fdaa::3]:53

2024-10-08T01:16:41.698 app[6e8257d4b02e28] sjc [info] INFO Main child exited normally with code: 127

2024-10-08T01:16:41.713 app[6e8257d4b02e28] sjc [info] INFO Starting clean up.

2024-10-08T01:16:41.717 app[6e8257d4b02e28] sjc [info] WARN could not unmount /rootfs: EINVAL: Invalid argument

2024-10-08T01:16:41.718 app[6e8257d4b02e28] sjc [info] [ 1.917041] reboot: Restarting system

2024-10-08T01:16:42.067 runner[6e8257d4b02e28] sjc [info] machine has reached its max restart count of 10

For more info here is my docker file, i did not change anything from when i launched the vapor project.

# ================================
# Build image
# ================================
FROM swift:5.10-noble AS build

# Install OS updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
    && apt-get -q update \
    && apt-get -q dist-upgrade -y \
    && apt-get install -y libjemalloc-dev

# Set up a build area
WORKDIR /build

# First just resolve dependencies.
# This creates a cached layer that can be reused
# as long as your Package.swift/Package.resolved
# files do not change.
COPY ./Package.* ./
RUN swift package resolve \
        $([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)

# Copy entire repo into container
COPY . .

# Build everything, with optimizations, with static linking, and using jemalloc
# N.B.: The static version of jemalloc is incompatible with the static Swift runtime.
RUN swift build -c release \
                --static-swift-stdlib \
                -Xlinker -ljemalloc

# Switch to the staging area
WORKDIR /staging

# Copy main executable to staging area
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/App" ./

# Copy static swift backtracer binary to staging area
RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./

# Copy resources bundled by SPM to staging area
RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;

# Copy any resources from the public directory and views directory if the directories exist
# Ensure that by default, neither the directory nor any of its contents are writable.
RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true

# ================================
# Run image
# ================================
FROM ubuntu:noble

# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
    && apt-get -q update \
    && apt-get -q dist-upgrade -y \
    && apt-get -q install -y \
      libjemalloc2 \
      ca-certificates \
      tzdata \
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
      # libcurl4 \
# If your app or its dependencies import FoundationXML, also install `libxml2`.
      # libxml2 \
    && rm -r /var/lib/apt/lists/*

# Create a vapor user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor

# Switch to the new home directory
WORKDIR /app

# Copy built executable and any staged resources from builder
COPY --from=build --chown=vapor:vapor /staging /app

# Provide configuration needed by the built-in crash reporter and some sensible default behaviors.
ENV SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=./swift-backtrace-static

# Ensure all further commands run as the vapor user
USER vapor:vapor

# Let Docker bind to port 8080
EXPOSE 8080

# Start the Vapor service when the image is run, default to listening on 8080 in production environment
ENTRYPOINT ["./App"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.