-
Notifications
You must be signed in to change notification settings - Fork 642
Fix & refactor dev docker-entrypoint.sh script #3721
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
Open
jkppr
wants to merge
5
commits into
google:master
Choose a base branch
from
jkppr:fix-dev-entrypoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−97
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e4e903
* Refactor dev docker-entrypoint.sh to support a local persistent key…
jkppr 6d8b885
Merge branch 'master' into fix-dev-entrypoint
jkppr b0af806
Gemini suggestion
jkppr 44a9c29
Update dev readme and add mention of the key in the comments
jkppr 449e427
review comments
jkppr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,3 +54,6 @@ vagrant/*.log | |
|
|
||
| # Exclude debugging profiles | ||
| profiles/ | ||
|
|
||
| # Ignore local dev key | ||
| .dev_secret_key | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,121 +1,100 @@ | ||
| ## Docker for development | ||
| ## Docker for Development | ||
|
|
||
| You can run Timesketch on Docker in development mode. | ||
| Make sure to follow the docker [post-install](https://docs.docker.com/engine/install/linux-postinstall/) to run without superuser. If not then make sure to execute all `docker` commands here as *superuser*. | ||
| Make sure to follow the docker [post-install](https://docs.docker.com/engine/install/linux-postinstall/) | ||
| to run without superuser. If not, make sure to execute all `docker` commands here | ||
| as *superuser*. | ||
|
|
||
| NOTE: It is not recommended to try to run on a system with less than 8 GB of RAM. | ||
| **Note:** It is not recommended to try to run on a system with less than 8 GB of RAM. | ||
|
|
||
| ### Start a developer version of docker containers in this directory | ||
| ### 1. Start the Developer Containers | ||
|
|
||
| ```bash | ||
| cd timesketch/docker/dev/ | ||
|
|
||
| docker compose up -d | ||
| ``` | ||
|
|
||
| The provided container definition runs Timesketch in development mode as a volume from your cloned repo. Any changes you make will appear in Timesketch automatically. | ||
|
|
||
| If you see the following message you can continue | ||
| The provided container definition runs Timesketch in development mode as a | ||
| volume from your cloned repo. Any changes you make will appear in Timesketch | ||
| automatically. | ||
|
|
||
| ```text | ||
| Timesketch development server is ready! | ||
| ``` | ||
| ### Find out container ID for the timesketch container | ||
| Wait until you see the "Timesketch development server is ready!" message in the logs: | ||
|
|
||
| ```bash | ||
| CONTAINER_ID="$(docker container list -f name=timesketch-dev -q)" | ||
| docker compose logs -f timesketch | ||
| ``` | ||
|
|
||
| In the output look for CONTAINER ID for the timesketch container | ||
| ### 2. Start the Application Services | ||
|
|
||
| To write the ID to a variable, use: | ||
| Since the container starts in a "sleeping" state to allow for debugging, you | ||
| need to manually start the worker and the webserver. | ||
|
|
||
| ```bash | ||
| export CONTAINER_ID="$(docker container list -f name=timesketch-dev -q)" | ||
| ``` | ||
| **Option A: Interactive (Recommended for debugging)** | ||
| Open two new terminal tabs/windows and run: | ||
|
|
||
| and test with | ||
| *Terminal 1 (Celery Worker):* | ||
|
|
||
| ```bash | ||
| echo $CONTAINER_ID | ||
| docker compose exec timesketch celery -A timesketch.lib.tasks worker --loglevel info | ||
| ``` | ||
|
|
||
| ### Start a celery container shell | ||
| OR | ||
|
|
||
| ```bash | ||
| docker exec -it $CONTAINER_ID celery -A timesketch.lib.tasks worker --loglevel info | ||
| bash utils/tsdev.sh celery | ||
| ``` | ||
|
|
||
| ### Start development webserver (and metrics server) | ||
| *Terminal 2 (Webserver):* | ||
|
|
||
| ```bash | ||
| docker exec -it $CONTAINER_ID gunicorn --reload -b 0.0.0.0:5000 --log-file - --timeout 600 -c /usr/local/src/timesketch/data/gunicorn_config.py timesketch.wsgi:application | ||
| docker compose exec timesketch gunicorn --reload -b 0.0.0.0:5000 --log-file - --timeout 600 -c /usr/local/src/timesketch/timesketch/gunicorn_config.py timesketch.wsgi:application | ||
| ``` | ||
|
|
||
| You now can access your development version at http://127.0.0.1:5000/ | ||
|
|
||
| Log in with user: dev password: dev | ||
|
|
||
| You can also access a metrics dashboard at http://127.0.0.1:3000/ | ||
|
|
||
| ### Non-interactive | ||
|
|
||
| Running the following as a script after `docker compose up -d` will bring up the development environment in the background for you. | ||
| OR | ||
|
|
||
| ```bash | ||
| export CONTAINER_ID="$(docker container list -f name=timesketch-dev -q)" | ||
| docker exec $CONTAINER_ID celery -A timesketch.lib.tasks worker --loglevel info | ||
| docker exec $CONTAINER_ID gunicorn --reload -b 0.0.0.0:5000 --log-file - --timeout 120 timesketch.wsgi:application | ||
| bash utils/tsdev.sh web | ||
| ``` | ||
|
|
||
| ### Run tests | ||
| **Option B: Non-interactive (Background)** | ||
| Run these commands to start everything in the background: | ||
|
|
||
| ```bash | ||
| docker exec -w /usr/local/src/timesketch -it $CONTAINER_ID python3 run_tests.py --coverage | ||
| docker compose exec -d timesketch celery -A timesketch.lib.tasks worker --loglevel info | ||
| docker compose exec -d timesketch gunicorn --reload -b 0.0.0.0:5000 --log-file - --timeout 120 timesketch.wsgi:application | ||
| ``` | ||
|
|
||
| That will run all tests in your docker container. It is recommended to run all tests at least before creating a pull request. | ||
| **Option C: Tilt** | ||
|
|
||
| ### Jupyter Notebook | ||
| For instructions on how to run the dev environment using Tilt check this guide: | ||
| * https://github.com/google/timesketch/blob/master/docs/developers/tilt-development.md | ||
|
|
||
| To access a Jupyter notebook that has access to the Timesketch development | ||
| environment start a browser and visit http://localhost:8844/ . The password to | ||
| gain access is "timesketch". | ||
| ### 3. Access the Application | ||
|
|
||
| By default, the /tmp directory is mapped as the data directory to store all | ||
| notebooks. To change that, modify the line: | ||
| * **Timesketch UI:** http://127.0.0.1:5000/ | ||
| * **User:** `dev` | ||
| * **Password:** `dev` | ||
| * Note: Your login session will persist across container restarts. | ||
| * The "secret key" is randomly generated and stored in a `.dev_secret_key` file. | ||
|
|
||
| ```yaml | ||
| - /tmp/:/usr/local/src/picadata/ | ||
| ``` | ||
|
|
||
| in the docker-compose.yml file to point to a directory of your choosing. | ||
| In order for the jupyter notebook to be able to make use of that folder it has | ||
| to have read and write permission for the user with the UID 1000. | ||
| * **Metrics (Prometheus):** http://127.0.0.1:9090/ | ||
|
|
||
| By default, the latest checked in code of the timesketch API client and | ||
| timesketch import client are installed. In order to install a new version, if | ||
| you are modifying the clients you'll need to make sure that the timesketch | ||
| source code on your machine is readable by the user with the UID 1000 and | ||
| gid 1000. | ||
| If that is done, then the code is mapped into the `/usr/local/src/timesketch` | ||
| folder on the docker container. | ||
| ### Run Tests | ||
|
|
||
| New versions of timesketch api client can then be installed using: | ||
| To run all tests inside the container: | ||
|
|
||
| ```bash | ||
| !pip install -e /usr/local/src/timesketch/api_client/python/ | ||
| docker compose exec -w /usr/local/src/timesketch timesketch python3 run_tests.py --coverage | ||
| ``` | ||
|
|
||
| And the importer client: | ||
|
|
||
| ```bash | ||
| !pip install -e /usr/local/src/timesketch/importer_client/python | ||
| ``` | ||
| It is recommended to run all tests at least before creating a pull request. | ||
|
|
||
| Just remember to restart the kernel runtime in order for the changes to be | ||
| active. | ||
| ### Pull new images | ||
|
|
||
| To update the docker image run: | ||
|
|
||
| ```bash | ||
| $ sudo docker image pull us-docker.pkg.dev/osdfir-registry/timesketch/notebook:latest | ||
| docker compose pull | ||
| ``` | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.