TanmayPatil105 / procfetch

🎨 Yet another command-line system information utility written in C++
https://tanmaypatil105.github.io/procfetch/
GNU General Public License v3.0
23 stars 11 forks source link

Fix missing adduser on the docker image ubuntu:latest. #145

Closed youpong closed 6 months ago

youpong commented 6 months ago

The docker image ubuntu:latest has been changed to 24.04 LTS. The new image does not install the adduser command by default, which causes errors when building the docker image procfetch. This pull request contains changes to the Dockerfile.

Related Issue(s)

This pull request fixes the issue #146.

TanmayPatil105 commented 6 months ago

I'm getting some errors while building it in docker container

make -C src -j 
make[1]: Entering directory '/procfetch/src'
g++ -std=c++2a -Wall -Wextra --pedantic-errors    -c -o fetch.o fetch.cpp
g++ -std=c++2a -Wall -Wextra --pedantic-errors    -c -o main.o main.cpp
g++ -std=c++2a -Wall -Wextra --pedantic-errors    -c -o util.o util.cpp
Assembler messages:
Fatal error: can't create main.o: Permission denied
make[1]: *** [<builtin>: main.o] Error 1
make[1]: *** Waiting for unfinished jobs....
Assembler messages:
Fatal error: can't create util.o: Permission denied
make[1]: *** [<builtin>: util.o] Error 1
Assembler messages:
Fatal error: can't create fetch.o: Permission denied
make[1]: Leaving directory '/procfetch/src'
make[1]: *** [<builtin>: fetch.o] Error 1
make: *** [Makefile:12: src] Error 2
youpong commented 6 months ago

I can't reproduce it here. My environment is as follows:

TanmayPatil105 commented 6 months ago

I was able fix that error by doing:

-USER user
-WORKDIR /home/user
+WORKDIR /home/user
+USER user

I was able to run it. After running more errors:

$ sudo docker run --rm -v $PROCFETCH:/procfetch -w /procfetch procfetch make run
make -C src -j run
make[1]: Entering directory '/procfetch/src'
./procfetch

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid
make[1]: Leaving directory '/procfetch/src'
make[1]: *** [Makefile:16: run] Aborted (core dumped)
make: *** [Makefile:12: src] Error 2

I'll try to debug this during night. I'm using Ubuntu 24.04 and Docker version 26.1.0, build 9714adc

youpong commented 6 months ago

That change in the Dockerfile works fine in my environment.

If I set a value to the USER environment variable, does it change the result?

$ USER=$(whoami) src/procfetch
TanmayPatil105 commented 6 months ago

Yupp, It does! Can you update this PR with both the changes?

youpong commented 6 months ago

I’ve updated this PR with both changes. Check it.

Well. In the Docker container environment that we provide, it is acceptable to set the USER environment variable. Let's introduce it.

However, as this case shows, it is incorrect to assume that the environment variable USERis always available. Stopping the program in such a case is not a good behavior. We need to add a process to handle the case.

TanmayPatil105 commented 6 months ago

However, as this case shows, it is incorrect to assume that the environment variable USERis always available. Stopping the program in such a case is not a good behavior. We need to add a process to handle the case.

Definitely, we've got a bunch of cases causing the program to halt. I'll create a separate issue for those, then we can start fixing them.

As for getting the username, we could just use the getlogin() from unistd.h. Let's think more about it?

TanmayPatil105 commented 6 months ago

Anyways, I'm merging this PR!