Skip to content

Commit c86e388

Browse files
author
Alex Chantavy
authored
Fix race condition for Docker local tests (#1384)
## Summary > Describe your changes. ### Before: 1. Pull down a fresh cartography from github ![Screenshot 2024-11-14 at 2 16 51 PM](https://github.com/user-attachments/assets/ad7a5706-c670-45a2-894d-44329eed28a4) 2. Build the container with `docker build -t cartography-cncf/cartography-dev -f dev.Dockerfile ./` (I forgot to screenshot this step) 3. Running the docker-compose linter works on the first try because the initialization step takes a while: ![Screenshot 2024-11-14 at 2 17 23 PM](https://github.com/user-attachments/assets/148c5efa-799a-425d-b52c-0fca33f28d5a) 4. [Failure] But subsequent linter runs fail with "is this a git repository?" ![Screenshot 2024-11-14 at 2 17 33 PM](https://github.com/user-attachments/assets/2447c0aa-26ac-447a-85bb-ade408db9d21) ### After: 1. Pull down fresh cartography from github and checkout this fix branch (fixdcwait) ![image](https://github.com/user-attachments/assets/1fbafca6-6b6e-4e9f-a43c-7df2efbfbc03) 2. Build container ![image](https://github.com/user-attachments/assets/60b93567-85bc-4b24-97c9-879adab49ee2) 3. Run linter on the first try ![image](https://github.com/user-attachments/assets/7d8d9a52-9f3c-4501-82a0-60abfb3f29d7) 4. [SUCCESS] Subsequent linter runs work because we've added a waiting mechanism ![Screenshot 2024-11-14 at 2 25 59 PM](https://github.com/user-attachments/assets/a8dfe235-95e4-4a40-83ec-c9c758928e8b) ### Related issues or links > Include links to relevant issues or other pages. - https://github.com/lyft/cartography/issues/... ### Checklist Provide proof that this works (this makes reviews move faster). Please perform one or more of the following: - [ ] Update/add unit or integration tests. - [x] Include a screenshot showing what the graph looked like before and after your changes. - [x] Include console log trace showing what happened before and after your changes. --------- Signed-off-by: Alex Chantavy <[email protected]>
1 parent 7ada565 commit c86e388

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

dev-entrypoint.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
while ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; do
3+
echo "Waiting for Git to be ready..."
4+
sleep 1
5+
done
6+
# Pass control to main container command
7+
exec "$@"

dev.Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ RUN git config --global --add safe.directory /var/cartography && \
3131
git config --local user.name "cartography"
3232

3333
USER ${uid}:${gid}
34+
35+
# Wait for git to be ready before running anything else. Fix race condition.
36+
ENTRYPOINT ["/var/cartography/dev-entrypoint.sh"]

0 commit comments

Comments
 (0)