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
Percy2y ago
Project ID: 12ad632d-3245-4503-b551-fa89e82b6a0e
Brody
Brody2y ago
full build logs please
denzelgitonga
denzelgitongaOP2y 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
Brody2y ago
in the future please send logs as .txt files
denzelgitonga
denzelgitongaOP2y ago
Oh, let me try....
Brody
Brody2y 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
denzelgitongaOP2y ago
To the root directory of the django project?
Brody
Brody2y ago
correct
denzelgitonga
denzelgitongaOP2y ago
It says that "nixpacks.toml" is not a valid name for a file or folder...
Brody
Brody2y ago
lmfao yes it is
denzelgitonga
denzelgitongaOP2y ago
There?
Brody
Brody2y ago
thats not all of what i sent
denzelgitonga
denzelgitongaOP2y ago
There?
Brody
Brody2y ago
looks good
denzelgitonga
denzelgitongaOP2y ago
Let me commit and push and redeploy, okay?
Brody
Brody2y ago
keep in mind, this is untested, i dont have anything to test with so i am just making assumptions
denzelgitonga
denzelgitongaOP2y ago
Okay, now building... let's see how it goes...
denzelgitonga
denzelgitongaOP2y ago
Would you like to check that out, please?
Brody
Brody2y ago
full build logs please
denzelgitonga
denzelgitongaOP2y ago
That's better?
Brody
Brody2y ago
try this instead
[phases.setup]
aptPkgs = ["...", "libcairo2-dev"]
[phases.setup]
aptPkgs = ["...", "libcairo2-dev"]
denzelgitonga
denzelgitongaOP2y ago
In the same "nixpacks.toml" file?
Brody
Brody2y ago
replace its contents with that
denzelgitonga
denzelgitongaOP2y ago
Okay... trying...
denzelgitonga
denzelgitongaOP2y ago
I'm I doing something wrong maybe? Or are my modules requiring an upgrade/downgrade?
Brody
Brody2y ago
do you have a repo (no you arent doing anything wrong)
denzelgitonga
denzelgitongaOP2y ago
Yes, I can share the repo...
Brody
Brody2y ago
please do also send me the table at the very top of your build logs
Brody
Brody2y ago
its private
denzelgitonga
denzelgitongaOP2y 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
Brody2y ago
its of no help to me if its private lol
denzelgitonga
denzelgitongaOP2y ago
It's public now
Brody
Brody2y ago
thank you
denzelgitonga
denzelgitongaOP2y ago
What more should I do?
Brody
Brody2y ago
work on switching to one of the databases railway provides
denzelgitonga
denzelgitongaOP2y ago
How would I do that?
Brody
Brody2y 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
denzelgitongaOP2y ago
Um, will that happen automatically?
Brody
Brody2y ago
every time you make a change to the github repo
denzelgitonga
denzelgitongaOP2y 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
Brody2y ago
do you write to the database when your app is deployed?
denzelgitonga
denzelgitongaOP2y 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
Brody2y ago
already working on it okay you have been warned do you actually use pycairo in your project
denzelgitonga
denzelgitongaOP2y 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
Brody2y ago
delete the nixpacks.toml file remove pycairo and rlPyCairo from your requirements.txt file let me know how that goes
denzelgitonga
denzelgitongaOP2y ago
do I need to uninstall it via pip?
Brody
Brody2y ago
just remove it from the file with your text editor
denzelgitonga
denzelgitongaOP2y ago
Then I pip freeze or I commit it like that?
Brody
Brody2y ago
no, never pip freeze just commit after making these changes you did 50% of what i said to lol
denzelgitonga
denzelgitongaOP2y ago
Haha, you can see from your end?
Brody
Brody2y ago
github
denzelgitonga
denzelgitongaOP2y ago
I'm I at 100% now?
Brody
Brody2y ago
haha yeah thats everything i said, hows the build going
denzelgitonga
denzelgitongaOP2y ago
Let's see now... no cairo in requirements, and no nix file... let's see
Brody
Brody2y ago
it would have started building already
denzelgitonga
denzelgitongaOP2y ago
It has... But still erroneous
Brody
Brody2y ago
yep you have a chonky project ~200mb before build
denzelgitonga
denzelgitongaOP2y ago
Haha, I'm a newbie...
Brody
Brody2y ago
you may want to move static files to a storage bucket
denzelgitonga
denzelgitongaOP2y ago
I beg your pardon?
Brody
Brody2y 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
denzelgitongaOP2y ago
I honestly don't know how to do that... maybe I am not really comprehending what you're saying, @Brody...
denzelgitonga
denzelgitongaOP2y ago
That's the new log
Brody
Brody2y ago
oh well full build logs please
denzelgitonga
denzelgitongaOP2y ago
That's the full log, @Brody
Brody
Brody2y ago
no its not
denzelgitonga
denzelgitongaOP2y ago
Sorry, how about this one?
denzelgitonga
denzelgitongaOP2y ago
Is that full now?
Brody
Brody2y ago
yes, hold on
denzelgitonga
denzelgitongaOP2y ago
Okay, thank you.
Brody
Brody2y 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
denzelgitongaOP2y ago
Okay, I have deleted the Procfile and added the Dockerfile as above:
denzelgitonga
denzelgitongaOP2y ago
Can I commit and push?
Brody
Brody2y ago
yes, let me know how it goes
denzelgitonga
denzelgitongaOP2y ago
There we go!!!!! 🥳
Brody
Brody2y ago
awsome
denzelgitonga
denzelgitongaOP2y ago
And now....
Brody
Brody2y ago
have you generated a domain?
denzelgitonga
denzelgitongaOP2y ago
I have clicked on "Add domain"
Brody
Brody2y ago
do you own a custom domain?
denzelgitonga
denzelgitongaOP2y ago
I don't own any domain.
Brody
Brody2y ago
show me the domains section of the service settings please
denzelgitonga
denzelgitongaOP2y ago
Oh wait, there's something...
Brody
Brody2y ago
cool, it works the rest is up to you!
denzelgitonga
denzelgitongaOP2y ago
But here's how it should look like
Brody
Brody2y 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
denzelgitongaOP2y 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
Brody2y ago
see my messages above
denzelgitonga
denzelgitongaOP2y ago
Okay, let me follow the docs Or is that right? I have tried to follow the whitenoise, and now redeploying..
denzelgitonga
denzelgitongaOP2y ago
It has worked, @Brody 🥳 Wow
denzelgitonga
denzelgitongaOP2y ago
Thank you so much, Sir... I am much obliged to you, Sir.
denzelgitonga
denzelgitongaOP2y ago
Now, this happens when I click register/login...
denzelgitonga
denzelgitongaOP2y ago
I have solved it... the system is now working well... Just one more thing, when I upload data, where is my DB?
Brody
Brody2y ago
remember when I said this? please share how you solved it for anyone in the future who might have the same problems?
denzelgitonga
denzelgitongaOP2y ago
Sure, I can always share, @Brody. Okay, so how would I go about the DB then?
Brody
Brody2y 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
denzelgitongaOP2y 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
denzelgitongaOP2y 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
denzelgitongaOP2y ago
denzelgitonga
denzelgitongaOP2y ago
Yet my Procfile has: web: gunicorn django_pos.wsgi --log-file -
denzelgitonga
denzelgitongaOP2y ago
Brody
Brody2y ago
I see you added gunicorn to your requirements.txt file, that was what I was gonna suggest, did it solve it?
denzelgitonga
denzelgitongaOP2y ago
No, not really... I actually decided to start the project all over again... Let me let you know how it goes, okay?
Brody
Brody2y ago
sounds good!
denzelgitonga
denzelgitongaOP2y 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
Brody2y 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
MantisInABox2y ago
Yeah, let me find it again
Brody
Brody2y ago
perfect, thanks
MantisInABox
MantisInABox2y ago
No problem
denzelgitonga
denzelgitongaOP2y 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
denzelgitongaOP2y 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
Ray2y ago
hey, please refrain from pinging helpers in here 🙂
denzelgitonga
denzelgitongaOP2y ago
Oh, alright, my apologies for that.
Brody
Brody2y 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
denzelgitongaOP2y ago
Oh my, is there nothing that can be done?
Brody
Brody2y 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
denzelgitongaOP2y 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
Brody2y ago
awsome, the less external dependencies the better
denzelgitonga
denzelgitongaOP2y 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
MantisInABox2y 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
MantisInABox2y 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
denzelgitongaOP2y ago
Alright, let me try and let you know... thank you.
MantisInABox
MantisInABox2y ago
No problem
denzelgitonga
denzelgitongaOP2y 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
denzelgitongaOP2y ago
Thank you
Want results from more Discord servers?
Add your server