Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add hash.txt to the public folder #1010

Merged
merged 3 commits into from
Feb 10, 2025
Merged

chore: add hash.txt to the public folder #1010

merged 3 commits into from
Feb 10, 2025

Conversation

ofirc77
Copy link
Collaborator

@ofirc77 ofirc77 commented Jan 15, 2025

fix: add test for checking existannce of public/hash.txt file

@ofirc77 ofirc77 self-assigned this Jan 15, 2025
@ofirc77 ofirc77 requested a review from NoamGaash as a code owner January 15, 2025 16:17
@ofirc77
Copy link
Collaborator Author

ofirc77 commented Jan 15, 2025

@NoamGaash Added comment from previous commit for context:

In short, updated the commit hash in hash.txt in the build.yaml file
this commit will focus on writing test for that feature.

seems like you're testing for the existence of public/hash.txt - and I don't think we should expect this file to be found in this stage because this job is not the same job that created this file.
I do think we want to test that http://localhost:3000/hash.txt returns a text string (mime type text/plain) that is short (less then 100 chars or so).
This test can also be performed locally if you run docker build and docker run, and then navigate to this url in your browser.
also, please consider adding separated commits so it will be easier to follow what have we tried

Updated this commit according to what you asked

@ofirc77
Copy link
Collaborator Author

ofirc77 commented Jan 15, 2025

Updated the test in the validate section. It seems now that it redirects it to the main page again for my opinion ( this is why we have 3100 chars and not less than 100 )
I will try to think on solution while running it locally for that issue.
Please let me know if you have more ideas

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!
Try to run the image locally and see A) if it has the file inside the public directory and b) if it serve it

exit 1
fi
mime_type=$(file --mime-type -b /tmp/hash.txt)
if [ "$mime_type" != "text/html" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ "$mime_type" != "text/html" ]; then
if [ "$mime_type" != "text/plain" ]; then

@ofirc77
Copy link
Collaborator Author

ofirc77 commented Feb 3, 2025

Hi Noam ,tried to run the docker locally. This is the output:

ofirc/open-bus-map-search (test_hash_in_app)$ sudo docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
open_bus     latest    9e8f77ea18d0   2 minutes ago   160MB
ofirc/open-bus-map-search (test_hash_in_app)$ sudo docker run -d 9e8f77ea18d0
85559e94b7d7cf780b8325decbe9e5ce187f54c525af482a49946db99e2a1954
ofirc/open-bus-map-search (test_hash_in_app)$ sudo docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS     NAMES
85559e94b7d7   9e8f77ea18d0   "/docker-entrypoint.…"   22 seconds ago   Up 21 seconds   80/tcp    focused_ellis
ofirc/open-bus-map-search (test_hash_in_app)$ sudo docker exec -it 85559e94b7d7 /bin/bash
root@85559e94b7d7:/# ls
bin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

It seems we don't have the public directory locally. Any advise on how to debug it?

@NoamGaash
Copy link
Member

I've tried the following:

First, I created an empty hello.txt file inside the public directory.
Then, I executed:

docker build . -t noam
docker run noam

and inside the image:

root@90b4176d6842:/# cd /usr/share/nginx/html/
root@90b4176d6842:/usr/share/nginx/html# ls
50x.html    bus-groups   hello.txt      marker-bus-stop.png  operators-logos    social-image.png
_redirects  bus-logos    index.html     marker-dot.png       robots.txt         storybook
assets      favicon.ico  manifest.json  marker-icon.png      service-worker.js

seems like hello.txt is there, which is good.
Then I tries to run docker run -p 8083:80 noam and visit http://localhost:8083/hello.txt using a web browser. Seems to work.
Also tried with curl:

➜  open-bus-map-search git:(ci/revert-linux-ubuntu-version) ✗ curl http://localhost:8083/hello.txt -v

* Host localhost:8083 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8083...
* Connected to localhost (::1) port 8083
> GET /hello.txt HTTP/1.1
> Host: localhost:8083
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx/1.23.3
< Date: Tue, 04 Feb 2025 20:06:36 GMT
< Content-Type: text/plain
< Content-Length: 0
< Last-Modified: Tue, 04 Feb 2025 20:02:26 GMT
< Connection: keep-alive
< ETag: "67a27252-0"
< Accept-Ranges: bytes
< 
* Connection #0 to host localhost left intact

I see that the commit hash step is in the build.yml and not in the docker build - you can see inside the Dockerfile that when building the docker image we build databus from scratch and that's why the commit status wasn't included.
It can be added to the Dockerfile or to the validate.yaml file,
I'm pushing a commit, feel free to revert / force push if you don't like that

Thank!
Noam

@NoamGaash NoamGaash changed the title fix: add test for checking existannce of public/hash.txt file chore: add hash.txt to the public folder Feb 5, 2025
Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're good with those changes, please feel free to merge

@ofirc77 ofirc77 merged commit 654530c into main Feb 10, 2025
19 checks passed
@ofirc77 ofirc77 deleted the test_hash_in_app branch February 10, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants