Skip to content

Commit

Permalink
Fix race condition for Docker local tests (cartography-cncf#1384)
Browse files Browse the repository at this point in the history
## 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]>
Signed-off-by: chandanchowdhury <[email protected]>
  • Loading branch information
achantavy authored and chandanchowdhury committed Nov 27, 2024
1 parent 33c7fd4 commit 94c2a46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dev-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
while ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; do
echo "Waiting for Git to be ready..."
sleep 1
done
# Pass control to main container command
exec "$@"
3 changes: 3 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ RUN git config --global --add safe.directory /var/cartography && \
git config --local user.name "cartography"

USER ${uid}:${gid}

# Wait for git to be ready before running anything else. Fix race condition.
ENTRYPOINT ["/var/cartography/dev-entrypoint.sh"]

0 comments on commit 94c2a46

Please sign in to comment.