Docker Build Error

Hello, how do you do? I am getting the following error when deploying my Django project: Dockerfile:21 ------------------- 19 | RUN printf '\nPATH=/opt/venv/bin:$PATH' >> /root/.profile 20 | COPY . /app/. 21 | >>> RUN --mount=type=cache,id=s/12ad632d-3245-4503-b551-fa89e82b6a0e-/root/cache/pip,target=/root/.cache/pip python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt 22 | 23 | ------------------- ERROR: failed to solve: process "/bin/bash -ol pipefail -c python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 1 Error: Docker build failed Please help
129 Replies
Percy
Percy15mo ago
Project ID: 12ad632d-3245-4503-b551-fa89e82b6a0e
Brody
Brody15mo ago
full build logs please
denzelgitonga
denzelgitonga15mo ago
#11 11.83 creating build/lib.linux-x86_64-cpython-311/cairo #11 11.83 copying cairo/init.py -> build/lib.linux-x86_64-cpython-311/cairo #11 11.83 copying cairo/init.pyi -> build/lib.linux-x86_64-cpython-311/cairo #11 11.83 copying cairo/py.typed -> build/lib.linux-x86_64-cpython-311/cairo #11 11.83 running build_ext #11 11.83 Package cairo was not found in the pkg-config search path. #11 11.83 Perhaps you should add the directory containing `cairo.pc' #11 11.83 to the PKG_CONFIG_PATH environment variable #11 11.83 No package 'cairo' found #11 11.83 Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' returned non-zero exit status 1. #11 11.83 [end of output] #11 11.83 #11 11.83 note: This error originates from a subprocess, and is likely not a problem with pip. #11 11.83 ERROR: Failed building wheel for pycairo #11 11.83 Failed to build pycairo #11 11.83 ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects #11 11.85 #11 11.85 [notice] A new release of pip available: 22.3.1 -> 23.1.2 #11 11.85 [notice] To update, run: pip install --upgrade pip #11 ERROR: process "/bin/bash -ol pipefail -c python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 1 -----
[stage-0 7/8] RUN --mount=type=cache,id=s/12ad632d-3245-4503-b551-fa89e82b6a0e-/root/cache/pip,target=/root/.cache/pip python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt:
#11 11.83 Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' returned non-zero exit status 1. #11 11.83 [end of output] #11 11.83 #11 11.83 note: This error originates from a subprocess, and is likely not a problem with pip. #11 11.83 ERROR: Failed building wheel for pycairo #11 11.83 Failed to build pycairo #11 11.83 ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects #11 11.85 #11 11.85 [notice] A new release of pip available: 22.3.1 -> 23.1.2 #11 11.85 [notice] To update, run: pip install --upgrade pip ----- Dockerfile:21 ------------------- 19 | RUN printf '\nPATH=/opt/venv/bin:$PATH' >> /root/.profile 20 | COPY . /app/. 21 | >>> RUN --mount=type=cache,id=s/12ad632d-3245-4503-b551-fa89e82b6a0e-/root/cache/pip,target=/root/.cache/pip python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt 22 | 23 | ------------------- ERROR: failed to solve: process "/bin/bash -ol pipefail -c python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 1 Error: Docker build failed
Brody
Brody15mo ago
in the future please send logs as .txt files
denzelgitonga
denzelgitonga15mo ago
Oh, let me try....
Brody
Brody15mo ago
add this as a nixpacks.toml file to your project
[phases.setup]
nixPkgs = ["...", "cairo"]
[phases.setup]
nixPkgs = ["...", "cairo"]
untested, but let me know how that goes
denzelgitonga
denzelgitonga15mo ago
To the root directory of the django project?
Brody
Brody15mo ago
correct
denzelgitonga
denzelgitonga15mo ago
It says that "nixpacks.toml" is not a valid name for a file or folder...
Brody
Brody15mo ago
lmfao yes it is
denzelgitonga
denzelgitonga15mo ago
There?
Brody
Brody15mo ago
thats not all of what i sent
denzelgitonga
denzelgitonga15mo ago
There?
Brody
Brody15mo ago
looks good
denzelgitonga
denzelgitonga15mo ago
Let me commit and push and redeploy, okay?
Brody
Brody15mo ago
keep in mind, this is untested, i dont have anything to test with so i am just making assumptions
denzelgitonga
denzelgitonga15mo ago
Okay, now building... let's see how it goes...
denzelgitonga
denzelgitonga15mo ago
Would you like to check that out, please?
Brody
Brody15mo ago
full build logs please
denzelgitonga
denzelgitonga15mo ago
That's better?
Brody
Brody15mo ago
try this instead
[phases.setup]
aptPkgs = ["...", "libcairo2-dev"]
[phases.setup]
aptPkgs = ["...", "libcairo2-dev"]
denzelgitonga
denzelgitonga15mo ago
In the same "nixpacks.toml" file?
Brody
Brody15mo ago
replace its contents with that
denzelgitonga
denzelgitonga15mo ago
Okay... trying...
denzelgitonga
denzelgitonga15mo ago
I'm I doing something wrong maybe? Or are my modules requiring an upgrade/downgrade?
Brody
Brody15mo ago
do you have a repo (no you arent doing anything wrong)
denzelgitonga
denzelgitonga15mo ago
Yes, I can share the repo...
Brody
Brody15mo ago
please do also send me the table at the very top of your build logs
Brody
Brody15mo ago
its private
denzelgitonga
denzelgitonga15mo ago
╔═══════════════════════════════ Nixpacks v1.5.1 ══════════════════════════════╗ ║ setup │ python311, postgresql, gcc, libcairo2-dev ║ ║──────────────────────────────────────────────────────────────────────────────║ ║ install │ python -m venv /opt/venv && . /opt/venv/bin/activate && pip ║ ║ │ install -r requirements.txt ║ ║──────────────────────────────────────────────────────────────────────────────║ ║ start │ gunicorn kafu_online_admission_system.wsgi --log-file - ║ ╚══════════════════════════════════════════════════════════════════════════════╝ That table? Yes, it's private
Brody
Brody15mo ago
its of no help to me if its private lol
denzelgitonga
denzelgitonga15mo ago
It's public now
Brody
Brody15mo ago
thank you
denzelgitonga
denzelgitonga15mo ago
What more should I do?
Brody
Brody15mo ago
work on switching to one of the databases railway provides
denzelgitonga
denzelgitonga15mo ago
How would I do that?
Brody
Brody15mo ago
you use sqlite, that wont work on railway since they dont have persistent storage, thus your whole database will get replaced on every deployment
denzelgitonga
denzelgitonga15mo ago
Um, will that happen automatically?
Brody
Brody15mo ago
every time you make a change to the github repo
denzelgitonga
denzelgitonga15mo ago
I don't think I have a problem with the database... provided it creates the tables/models just as I have described them in the Django project... or how would it work?
Brody
Brody15mo ago
do you write to the database when your app is deployed?
denzelgitonga
denzelgitonga15mo ago
I don't think so... I haven't done anything to the database... Would you like to check out the project on GitHub and maybe see where the mishap is?
Brody
Brody15mo ago
already working on it okay you have been warned do you actually use pycairo in your project
denzelgitonga
denzelgitonga15mo ago
Haha... I'm so new to this, I don't even think I have understood the warning really. I don't think I use it, no.
Brody
Brody15mo ago
delete the nixpacks.toml file remove pycairo and rlPyCairo from your requirements.txt file let me know how that goes
denzelgitonga
denzelgitonga15mo ago
do I need to uninstall it via pip?
Brody
Brody15mo ago
just remove it from the file with your text editor
denzelgitonga
denzelgitonga15mo ago
Then I pip freeze or I commit it like that?
Brody
Brody15mo ago
no, never pip freeze just commit after making these changes you did 50% of what i said to lol
denzelgitonga
denzelgitonga15mo ago
Haha, you can see from your end?
Brody
Brody15mo ago
github
denzelgitonga
denzelgitonga15mo ago
I'm I at 100% now?
Brody
Brody15mo ago
haha yeah thats everything i said, hows the build going
denzelgitonga
denzelgitonga15mo ago
Let's see now... no cairo in requirements, and no nix file... let's see
Brody
Brody15mo ago
it would have started building already
denzelgitonga
denzelgitonga15mo ago
It has... But still erroneous
Brody
Brody15mo ago
yep you have a chonky project ~200mb before build
denzelgitonga
denzelgitonga15mo ago
Haha, I'm a newbie...
Brody
Brody15mo ago
you may want to move static files to a storage bucket
denzelgitonga
denzelgitonga15mo ago
I beg your pardon?
Brody
Brody15mo ago
most of the size of your project comes from static files you may want to move them to a storage bucket (like aws s3) to cut down on your projects size
denzelgitonga
denzelgitonga15mo ago
I honestly don't know how to do that... maybe I am not really comprehending what you're saying, @Brody...
denzelgitonga
denzelgitonga15mo ago
That's the new log
Brody
Brody15mo ago
oh well full build logs please
denzelgitonga
denzelgitonga15mo ago
That's the full log, @Brody
Brody
Brody15mo ago
no its not
denzelgitonga
denzelgitonga15mo ago
Sorry, how about this one?
denzelgitonga
denzelgitonga15mo ago
Is that full now?
Brody
Brody15mo ago
yes, hold on
denzelgitonga
denzelgitonga15mo ago
Okay, thank you.
Brody
Brody15mo ago
please follow each step and make the changes in one single commit lets move away from nixpacks 1. delete the Procfile file 2. add a Dockerfile file with the contents
FROM python:3.10.0-slim

# install needed packages
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libcairo2-dev

# clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . .

CMD gunicorn kafu_online_admission_system.wsgi
FROM python:3.10.0-slim

# install needed packages
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libcairo2-dev

# clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt ./

RUN pip install -r requirements.txt

COPY . .

CMD gunicorn kafu_online_admission_system.wsgi
denzelgitonga
denzelgitonga15mo ago
Okay, I have deleted the Procfile and added the Dockerfile as above:
denzelgitonga
denzelgitonga15mo ago
Can I commit and push?
Brody
Brody15mo ago
yes, let me know how it goes
denzelgitonga
denzelgitonga15mo ago
There we go!!!!! 🥳
Brody
Brody15mo ago
awsome
denzelgitonga
denzelgitonga15mo ago
And now....
Brody
Brody15mo ago
have you generated a domain?
denzelgitonga
denzelgitonga15mo ago
I have clicked on "Add domain"
Brody
Brody15mo ago
do you own a custom domain?
denzelgitonga
denzelgitonga15mo ago
I don't own any domain.
Brody
Brody15mo ago
show me the domains section of the service settings please
denzelgitonga
denzelgitonga15mo ago
Oh wait, there's something...
Brody
Brody15mo ago
cool, it works the rest is up to you!
denzelgitonga
denzelgitonga15mo ago
But here's how it should look like
Brody
Brody15mo ago
this wouldn't be a railway issue anymore but heres some starting points you will want to look into using whitenoise. railway's django template that uses whitenoise https://github.com/railwayapp-templates/django and the docs for whitenoise https://whitenoise.readthedocs.io/en/latest/django.html happy coding!
denzelgitonga
denzelgitonga15mo ago
I usually appears like this if the environment is not on on... But when it's live, it appear like the other one... So I wonder where the issue would be now that it's live on railway
Brody
Brody15mo ago
see my messages above
denzelgitonga
denzelgitonga15mo ago
Okay, let me follow the docs Or is that right? I have tried to follow the whitenoise, and now redeploying..
denzelgitonga
denzelgitonga15mo ago
It has worked, @Brody 🥳 Wow
denzelgitonga
denzelgitonga15mo ago
Thank you so much, Sir... I am much obliged to you, Sir.
denzelgitonga
denzelgitonga15mo ago
Now, this happens when I click register/login...
denzelgitonga
denzelgitonga15mo ago
I have solved it... the system is now working well... Just one more thing, when I upload data, where is my DB?
Brody
Brody15mo ago
remember when I said this? please share how you solved it for anyone in the future who might have the same problems?
denzelgitonga
denzelgitonga15mo ago
Sure, I can always share, @Brody. Okay, so how would I go about the DB then?
Brody
Brody15mo ago
use the postgre database railway provides as a plugin 1. add the postgre database to your project 2. setup the variable references https://docs.railway.app/develop/variables#reference-variables 3. reference railway's django template because it uses a postgre database https://github.com/railwayapp-templates/django
denzelgitonga
denzelgitonga15mo ago
Okay, I would check that when I login to that system. Now, I am trying to deploy another system, but after it deploys, and I load the site, it says "App crashed", and then on the deploy logs, it says: /bin/bash: line 1: guinicorn: command not found /bin/bash: line 1: guinicorn: command not found /bin/bash: line 1: guinicorn: command not found What could be the problem, please?
denzelgitonga
denzelgitonga15mo ago
GitHub
GitHub - DenzelGitonga007/Point-of-Sale: A Point of Sale System bui...
A Point of Sale System built in Django, that'll allow shops to manage stores, have an inventory, and perform sales of their products at the cashier's desk. - GitHub - DenzelGitonga0...
denzelgitonga
denzelgitonga15mo ago
denzelgitonga
denzelgitonga15mo ago
Yet my Procfile has: web: gunicorn django_pos.wsgi --log-file -
denzelgitonga
denzelgitonga15mo ago
Brody
Brody15mo ago
I see you added gunicorn to your requirements.txt file, that was what I was gonna suggest, did it solve it?
denzelgitonga
denzelgitonga15mo ago
No, not really... I actually decided to start the project all over again... Let me let you know how it goes, okay?
Brody
Brody14mo ago
sounds good!
denzelgitonga
denzelgitonga14mo ago
Thanks Hello Sir, how do you do? I have an enquiry, when using Django for a site that'd be deployed, would you advise using Postgress DB? Then, for deployment, do I need to to switch the db from the default DBSQLite locally on my machine? Will it reflect on the server where I deploy, like Railway?
Brody
Brody14mo ago
for running on railway, yes use postgre, for local sqlite is fine @Vin mind linking that page that shows how to use different databases for different environments?
MantisInABox
MantisInABox14mo ago
Yeah, let me find it again
Brody
Brody14mo ago
perfect, thanks
MantisInABox
MantisInABox14mo ago
No problem
denzelgitonga
denzelgitonga14mo ago
Hello everyone, how's it going? Thank you so much for your continued support, you have been outstandingly helpful. For the database, perhaps I'll check it out when I reach the last phases of the project I'm working on.
denzelgitonga
denzelgitonga14mo ago
,the which is However, I have encountered a deployment error, on my clarion-stationers website, still hosted on railway. Now, the site was working fine and well, but upon installing a library for printing receipts, the site builds, and even deploys, but upon accessing it, it says that the application failed to respond, and when I check the deploy logs, I see it start falling from the weasyprint point. However, I have another site using weasyprint, and it's working just well, I don't know why this one doesn't seem to be working. I have attached the logs, perhaps you could have a look and help me fix the issue, please. Thank you.
Ray
Ray14mo ago
hey, please refrain from pinging helpers in here 🙂
denzelgitonga
denzelgitonga14mo ago
Oh, alright, my apologies for that.
Brody
Brody14mo ago
very recently someone else has made a help thread about weasyprint not working with the same error message, and I was unable to solve it for them, so sorry I don't know how to help you with that
denzelgitonga
denzelgitonga14mo ago
Oh my, is there nothing that can be done?
Brody
Brody14mo ago
I'm not a django or even python developer for that matter, I am out of ideas, but you are welcome to Google around
denzelgitonga
denzelgitonga14mo ago
Oh, thanks guys, I actually resolved to print my receipt (which was what Weasyprint was doing), in another way that is now working even on Railway. I am grateful for your assistance. Thank you once again.
Brody
Brody14mo ago
awsome, the less external dependencies the better
denzelgitonga
denzelgitonga14mo ago
Hello, how do you do? If I use this in the settings.py, if I push to railway, will it automatically take effect? Also, if I push another time, will it overwrite the existing items on the db? I think I am having a challenge switching to postgress On the railway platform. like I don't know how it It's done*
MantisInABox
MantisInABox14mo ago
If you are going to use Postgres, your settings file should look similar to this one https://GitHub.com/railwayapp-templates/django
GitHub
GitHub - railwayapp-templates/django: 1-Click Django on Railway
1-Click Django on Railway. Contribute to railwayapp-templates/django development by creating an account on GitHub.
MantisInABox
MantisInABox14mo ago
This is a good starting point to get your app up and running. Afterwards, you can add the local dev database following the article I provided the other day. Your migrations will automatically take place based on the start command in the railway.json file anytime you push changes to your code You would wrap the database connections in an if statement, and before you push to railway, you want to modify settings.py to be DEBUG=False That way it will connect to the railway hosted Postgres database
denzelgitonga
denzelgitonga14mo ago
Alright, let me try and let you know... thank you.
MantisInABox
MantisInABox14mo ago
No problem
denzelgitonga
denzelgitonga13mo ago
Hello, how do you do? Would I politely ask, I thought Railway provides free hosting and usage... I have deployed to systems on Railway following this, but now I am getting the message "The Starter plan will be discontinued on August 1, 2023. Upgrade to the Hobby plan to continue using Railway."... Would someone please explain whether I'll be charged for the projects, as my sole intention was to have the free plan. Thank you.
denzelgitonga
denzelgitonga13mo ago
Thank you