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

feat: add a devcontainer for easier development #1256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sdwilsh
Copy link

@sdwilsh sdwilsh commented Feb 26, 2025

This change adds a devcontainer that properly sets up a test environment
such that a user has a working cscli and crowdsec command for their
hub checkout. This makes it much easier to developer parsers in this
repository, greatly reducing the barrier to entry.

This change also adds a workflow to make sure the devcontainer can
build. This could be further extended to also run tests in the
devcontainer.

I verified this works by running the example test command in the
README.md:

cscli hubtest run dovecot-logs
INFO[26-02-2025 19:00:00] Running test 'dovecot-logs'                  
INFO[26-02-2025 19:00:03] Test 'dovecot-logs' passed successfully (387 assertions) 
───────────────────────
 Test           Result 
───────────────────────
 dovecot-logs   ✅     
───────────────────────

Additionally, I ran all tests with cscli hubtest run --all, which
outputted this: https://gist.github.com/sdwilsh/6ed59b6904dac9cabbea63c55567c070

@sdwilsh sdwilsh marked this pull request as draft February 26, 2025 21:06
This change adds a devcontainer that properly sets up a test environment
such that a user has a working `cscli` and `crowdsec` command for their
hub checkout.  This makes it much easier to developer parsers in this
repository, greatly reducing the barrier to entry.

This change also adds a workflow to make sure the devcontainer can
build.  This could be further extended to also run tests in the
devcontainer.

I verified this works by running the example test command in the
`README.md`:
```sh
cscli hubtest run dovecot-logs
INFO[26-02-2025 19:00:00] Running test 'dovecot-logs'                  
INFO[26-02-2025 19:00:03] Test 'dovecot-logs' passed successfully (387 assertions) 
───────────────────────
 Test           Result 
───────────────────────
 dovecot-logs   ✅     
───────────────────────
```

Additionally, I ran all tests with `cscli hubtest run --all`, which
outputted this: https://gist.github.com/sdwilsh/6ed59b6904dac9cabbea63c55567c070
Comment on lines +14 to +27
# As documented in https://github.com/crowdsecurity/crowdsec/issues/3183,
# running ./test_env.sh sets a bunch of relative paths with simply do not work
# as we need them to in a devcontainer. The following lines set absolute paths
# that do work.
yq -iy '.api.client.credentials_path = "/workspaces/crowdsec/tests/config/local_api_credentials.yaml"' dev.yaml
yq -iy '.api.server.console_path = "/workspaces/crowdsec/tests/config/console.yaml"' dev.yaml
yq -iy '.api.server.online_client.credentials_path = "/workspaces/crowdsec/tests/config/online_api_credentials.yaml"' dev.yaml
yq -iy '.api.server.profiles_path = "/workspaces/crowdsec/tests/config/profiles.yaml"' dev.yaml
yq -iy '.config_paths.config_dir = "/workspaces/crowdsec/tests/config/"' dev.yaml
yq -iy '.config_paths.data_dir = "/workspaces/crowdsec/tests/data/"' dev.yaml
yq -iy '.config_paths.notification_dir = "/workspaces/crowdsec/tests/notifications/"' dev.yaml
yq -iy '.config_paths.plugin_dir = "/workspaces/crowdsec/tests/plugins/"' dev.yaml
yq -iy '.crowdsec_service.acquisition_path = "/workspaces/crowdsec/tests/config/acquis.yaml"' dev.yaml
yq -iy '.db_config.db_path = "/workspaces/crowdsec/tests/data/crowdsec.db"' dev.yaml
Copy link
Author

Choose a reason for hiding this comment

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

This whole section can go away once crowdsecurity/crowdsec#3183 is resolved (or at least the last item in that issue as of this writing).

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.

1 participant