container event container died when trying to deploy with dockerfile

nahascoHOBBY

a year ago

I needed to use a dockerfile to install some important dependencies but now the deployment is failing on me with "container event container died" message in the deploy logs.

FROM python:3.12.2-alpine

WORKDIR /usr/src/app

ENV PYTHONUNBUFFERED=1

RUN pip install --upgrade pip

RUN apk add --update --no-cache --virtual .tmp-build-deps \
    gcc libc-dev linux-headers postgresql-dev \
    && apk add libffi-dev \
    && apk add tk

RUN apk add weasyprint

RUN apk --update --upgrade --no-cache add fontconfig ttf-freefont font-noto terminus-font \
   && fc-cache -f \
   && fc-list | sort

COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

COPY . /usr/src/app/

this is my dockerfile.

attached are the logs.

0 Replies

nahascoHOBBY

a year ago

643c9962-5fa0-449c-82e0-67b30f66c552


nahascoHOBBY

a year ago

ok it seems like i never run the application so i changed the docker file to this

# Use an official Python runtime as a parent image
FROM python:3.12.2-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

# Ensure that the Python output is not buffered (helpful for Docker logs)
ENV PYTHONUNBUFFERED=1

# Upgrade pip
RUN pip install --upgrade pip

# Install system dependencies
RUN apk add --update --no-cache --virtual .tmp-build-deps \
    gcc libc-dev linux-headers postgresql-dev \
    && apk add libffi-dev \
    && apk add tk

# Install WeasyPrint and its dependencies
RUN apk add weasyprint

# Install fonts
RUN apk --update --upgrade --no-cache add fontconfig ttf-freefont font-noto terminus-font \
   && fc-cache -f \
   && fc-list | sort

# Install Python dependencies
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

# Copy the rest of the application code
COPY . /usr/src/app/

# Collect static files
RUN python manage.py collectstatic --noinput

# Run database migrations
RUN python manage.py migrate

# Expose the port that the app runs on
EXPOSE 8000

# Start the application
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "tibian_backend.wsgi:application"]

but i got errors in collectstatic and migrate commands


nahascoHOBBY

a year ago

i think the env vars arent present when building


nahascoHOBBY

a year ago

tried this but getting container died again

1267433769002864722


nahascoHOBBY

a year ago

can i get some help please


a year ago

build and deploy logs please -


nahascoHOBBY

a year ago

thank but i was able to finally deploy successfully when i removed a custom start command i put in previously


a year ago

glad to hear that!


nahascoHOBBY

a year ago

i have another question though,

i am trying to generate a pdf in django and then send it to frontend. everyhting works fine in development but in prod i get these errors

from origin "" has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

net::ERR_FAILED 503 (Service Unavailable)

a year ago

what do you get when you simply open the backend's domain in your browser?


nahascoHOBBY

a year ago

does this have to do with railway limitations or something with the prod setup


nahascoHOBBY

a year ago

i will try that


a year ago

I'm confident enough to say that this would be a misconfiguration, I'm sure we can get to the cause


nahascoHOBBY

a year ago

oh i remembered the request should be post with auth headers, so that wont be possible


nahascoHOBBY

a year ago

GET /api/reports/session/59/
HTTP 401 Unauthorized
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept
WWW-Authenticate: Bearer realm="api"

{
"type": "clienterror", "errors": [ { "code": "notauthenticated",
"detail": "Authentication credentials were not provided.",
"attr": null
}
]
}


nahascoHOBBY

a year ago

should i try to bypass that for testing?


a year ago

is that what you get when you open the site in your browser?


nahascoHOBBY

a year ago

yes


a year ago

okay that's a good sign, as long as it's not a railway error page that's all that matters


a year ago

looks like you will need to use some cors middleware


nahascoHOBBY

a year ago

i do already and the rest of my app works fine, only this mew route that returns a pdf isnt working


a year ago

maybe it's not really a cors error and instead it's returning something like a 500 status code that doesn't have cors headers on it, you'd want to test with something like postman that doesn't care about cors to see what's actually happening


nahascoHOBBY

a year ago

Tried that and got the railway failed to respond error, 503 service unavailable

1267454464101711953


a year ago

ah yes just as I suspected, your app did not respond


a year ago

you will have to look to your deployment logs for errors on why it didn't respond


nahascoHOBBY

a year ago

[2024-07-29 11:24:46 +0000] [79] [CRITICAL] WORKER TIMEOUT (pid:262)

[2024-07-29 11:24:46 +0000] [262] [INFO] Worker exiting (pid: 262)

[2024-07-29 11:24:47 +0000] [79] [ERROR] Worker (pid:262) exited with code 1

[2024-07-29 11:24:47 +0000] [79] [ERROR] Worker (pid:262) exited with code 1.

[2024-07-29 11:24:47 +0000] [343] [INFO] Booting worker with pid: 343

[2024-07-29 11:30:12 +0000] [79] [CRITICAL] WORKER TIMEOUT (pid:343)

[2024-07-29 11:30:13 +0000] [343] [INFO] Worker exiting (pid: 343)

[2024-07-29 11:30:13 +0000] [79] [ERROR] Worker (pid:343) exited with code 1

[2024-07-29 11:30:13 +0000] [79] [ERROR] Worker (pid:343) exited with code 1.

[2024-07-29 11:30:13 +0000] [424] [INFO] Booting worker with pid: 424

[2024-07-29 12:09:59 +0000] [79] [CRITICAL] WORKER TIMEOUT (pid:424)

[2024-07-29 12:09:59 +0000] [424] [INFO] Worker exiting (pid: 424)

[2024-07-29 12:10:00 +0000] [79] [ERROR] Worker (pid:424) exited with code 1

[2024-07-29 12:10:00 +0000] [79] [ERROR] Worker (pid:424) exited with code 1.

[2024-07-29 12:10:00 +0000] [533] [INFO] Booting worker with pid: 533

worker timed out? is that the issue?


a year ago

that means a particular request took over the default of 30 seconds and was stopped, I assume generating a pdf should never take anywhere near 30 seconds?


nahascoHOBBY

a year ago

anyway to increase default value?


a year ago

you only need to if pdf generation is supposed to take longer than 30 seconds


nahascoHOBBY

a year ago

I do alot of querysets to fetch the data for the pdf, so maybe its normal for it to take over 30 seconds, i am not sure so i want to test if increasing the value will fix the error, if it does then ill work on optimizing the process


a year ago

fair enough, what's your current start command


nahascoHOBBY

a year ago

i use a dockerfile

1267458722142224434


a year ago

what is the start command in that bash file


nahascoHOBBY

a year ago

its defined above it

gunicorn ${PROJNAME}.wsgi:application --bind \"0.0.0.0:\$RUNPORT\"


nahascoHOBBY

a year ago

i define the script in the same place, there is no external bash file


nahascoHOBBY

a year ago

what do i do with it?


a year ago

you would want to set this flag -


a year ago

to something greater than 30


nahascoHOBBY

a year ago

After testing the response is successful however it takes 33 seconds and it seems like the pdf styling wasnt loading

fixed it by increasing gunicorn workers to 8 and running collectstatic


nahascoHOBBY

a year ago

any downside to settings workers to 8? do i still need to optimise my querying?


a year ago

how long does the request to generate a pdf take now?


nahascoHOBBY

a year ago

a second or so


a year ago

okay then id say thats pretty good


nahascoHOBBY

a year ago

Great. You've been incredibly helpful! Thank you sincerely.


a year ago

no problem!