Repository navigation
fix: make labs work on a "From Sources" install - #583
Open
PRAteek-singHWY wants to merge 1 commit into
Open
PRAteek-singHWY wants to merge 1 commit into
PRAteek-singHWY wants to merge 1 commit into
Conversation
Lab containers go on the my_network Docker network, but only Docker Compose creates it, so on a source install every lab start failed with "network my_network not found". PyGoat now creates the network when it's missing. Creation runs under a file lock, because two lab starts at the same moment otherwise create two networks with the same name and Docker can then start no lab at all. The README's Traefik steps didn't work either: on Docker Desktop a Traefik binary on the host can't reach the lab containers, the Windows steps never loaded traefik.yml, and Traefik v3.3 and older can't talk to Docker 29. Traefik now starts with --configFile=traefik.yml, the Linux steps ask for v3.6 or later, and Docker Desktop users run Traefik in Docker on my_network. Fixes adeyosemanputra#582 Signed-off-by: PRAteek-singHWY <prateek23022004@gmail.com>
Author
|
Hi @RupakBiswas-2304 This PR fixes #582, where none of the labs could be started on a "From Sources" install. I tested it end to end with fresh source installs on Linux and macOS, and the Docker Compose setup still works the same. Happy to iterate based on your review. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Labs couldn't be started on a "From Sources" install. PyGoat now creates the
my_networkDocker network when it's missing, and the README's Traefik steps now work on Linux and on Docker Desktop (macOS, Windows). I tested it end to end with fresh installs on Linux and macOS, and Docker Compose still works the same.Problem / Motivation
my_networknetwork, but only Docker Compose creates it, so on a source install every lab start failed with "network my_network not found".traefik.ymland PyGoat reported "Traefik reverse proxy is not reachable".Fixes #582
Solution / Approach
_ensure_lab_network()returns the lab network (stillDOCKER_NETWORK, defaultmy_network) and creates it as a bridge network if it doesn't exist._create_lab_containercalls it before creating the container. When it already exists, which is always the case under Docker Compose, nothing changes.my_networkand every lab start fails with "network my_network is ambiguous". So the creation runs under a file lock, the same kind_user_lab_lockalready uses, and checks again once it has the lock. I moved the lock code into a small_file_lock()helper so both locks share it._user_lab_lockworks the same as before.--configFile=traefik.ymlfrom the PyGoat folder, the Linux steps ask for v3.6 or later, and Docker Desktop users get a singledocker runcommand (works in Bash and PowerShell) that runs Traefik in Docker onmy_network.Files Changed
challenge/views.py_ensure_lab_network()and use it in_create_lab_container. Move the lock code into_file_lock()challenge/tests.pyDOCKER_NETWORKsetting, and parallel lab starts creating the network only onceREADME.mdImpact
my_networkalready exists there. I ran the Compose stack with this branch: labs start, the owner gets the lab, anonymous gets 401 and another user gets 403, and there's still onemy_network.my_networkand the lab loads through Traefik. Starting three labs, stopping one or all, and restarting PyGoat all work.runserverand with gunicorn running 4 workers.