-
Notifications
You must be signed in to change notification settings - Fork 67
feat: add python remote debug support #138
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
base: development
Are you sure you want to change the base?
Changes from all commits
c29a1ac
cdfb2ba
f684578
803c5b8
cef5220
4a132ee
9f2c450
5cbda16
320d77b
6d33fc5
a2ea548
2cdd76d
0fa9fc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ | |
| }, | ||
| { | ||
| "name": "Environment options", | ||
| "options": ["--web-server-port", "--dags-path", "--plugins-path"], | ||
| "options": ["--web-server-port", "--dags-path", "--plugins-path", "--enable-ssh", "--ssh-port"], | ||
| }, | ||
| { | ||
| "name": "Container Memory and CPUs limit", | ||
|
|
@@ -178,6 +178,21 @@ def cli(): | |
| metavar="PORT", | ||
| ) | ||
|
|
||
| option_enable_ssh = click.option( | ||
| "--enable-ssh", | ||
| is_flag=True, | ||
| default=False, | ||
| help="Enable SSH daemon in the environment.", | ||
| metavar="ENABLE_SSH", | ||
| ) | ||
|
|
||
| option_ssh_port = click.option( | ||
| "--ssh-port", | ||
| type=click.IntRange(min=0, max=65535), | ||
| help="Port used by SSH daemon", | ||
| show_default="read from the configuration file", | ||
| metavar="SSHD_PORT", | ||
| ) | ||
|
morgan-dgk marked this conversation as resolved.
|
||
|
|
||
| def _complete_environment(ctx, param, incomplete): | ||
| env_dirs = files.get_environment_directories() | ||
|
|
@@ -246,6 +261,8 @@ def _complete_environment(ctx, param, incomplete): | |
| ) | ||
| @option_location | ||
| @option_port | ||
| @option_enable_ssh | ||
| @option_ssh_port | ||
|
Comment on lines
+264
to
+265
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it also makes sense to enable these 2 options for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've pushed up some changes that aim to address this. I assume this requires modifying
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, the changes look good to me 👍 |
||
| @click.option( | ||
| "--dags-path", | ||
| help="Path to DAGs folder. If it does not exist, it will be created.", | ||
|
|
@@ -279,6 +296,8 @@ def create( | |
| project: Optional[str], | ||
| location: str, | ||
| web_server_port: Optional[int], | ||
| enable_ssh: Optional[bool], | ||
| ssh_port: Optional[int], | ||
| environment: str, | ||
| verbose: bool, | ||
| debug: bool, | ||
|
|
@@ -339,6 +358,8 @@ def create( | |
| location=location, | ||
| env_dir_path=env_dir, | ||
| web_server_port=web_server_port, | ||
| enable_ssh=enable_ssh, | ||
| ssh_port=ssh_port, | ||
| dags_path=dags_path, | ||
| plugins_path=plugins_path, | ||
| database_engine=database_engine, | ||
|
|
@@ -352,6 +373,8 @@ def create( | |
| location=location, | ||
| env_dir_path=env_dir, | ||
| port=web_server_port, | ||
| enable_ssh=enable_ssh, | ||
| ssh_port=ssh_port, | ||
| dags_path=dags_path, | ||
| plugins_path=plugins_path, | ||
| database_engine=database_engine, | ||
|
|
@@ -364,20 +387,24 @@ def create( | |
| @cli.command() | ||
| @optional_environment | ||
| @option_port | ||
| @option_enable_ssh | ||
| @option_ssh_port | ||
| @verbose_mode | ||
| @debug_mode | ||
| @errors.catch_exceptions() | ||
| def start( | ||
| environment: Optional[str], | ||
| web_server_port: Optional[int], | ||
| enable_ssh: Optional[bool], | ||
| ssh_port: Optional[int], | ||
| verbose: bool, | ||
| debug: bool, | ||
| ): | ||
| """Start Composer environment.""" | ||
| utils.setup_logging(verbose, debug) | ||
| env_path = files.resolve_environment_path(environment) | ||
| env = composer_environment.Environment.load_from_config( | ||
| env_path, web_server_port | ||
| env_path, web_server_port,enable_ssh,ssh_port | ||
| ) | ||
| console.get_console().print(f"Starting {env.name} composer environment...") | ||
| env.start() | ||
|
|
@@ -404,12 +431,16 @@ def stop(environment: Optional[str], verbose: bool, debug: bool): | |
| @cli.command() | ||
| @optional_environment | ||
| @option_port | ||
| @option_enable_ssh | ||
| @option_ssh_port | ||
| @verbose_mode | ||
| @debug_mode | ||
| @errors.catch_exceptions() | ||
| def restart( | ||
| environment: Optional[str], | ||
| web_server_port: Optional[int], | ||
| enable_ssh: Optional[bool], | ||
| ssh_port: Optional[int], | ||
| verbose: bool, | ||
| debug: bool, | ||
| ): | ||
|
|
@@ -422,7 +453,7 @@ def restart( | |
| utils.setup_logging(verbose, debug) | ||
| env_path = files.resolve_environment_path(environment) | ||
| env = composer_environment.Environment.load_from_config( | ||
| env_path, web_server_port | ||
| env_path, web_server_port,enable_ssh,ssh_port | ||
| ) | ||
| env.restart() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,24 @@ create_user() { | |
| fi | ||
| } | ||
|
|
||
| install_and_run_sshd() { | ||
| if ! command -v /usr/sbin/sshd &> /dev/null | ||
| then | ||
| echo "Installing sshd" | ||
| sudo bash -c 'cat << EOF > /etc/apt/sources.list.d/default.list | ||
| deb http://archive.ubuntu.com/ubuntu/ noble main restricted | ||
| deb http://archive.ubuntu.com/ubuntu/ noble-updates main restricted | ||
| EOF' | ||
| sudo apt-get -qq update > /dev/null 2>&1 | ||
| sudo apt-get -qqy install openssh-server > /dev/null 2>&1 | ||
| sudo chown airflow:airflow /etc/ssh/ssh_host_*_key | ||
| sudo mkdir /run/sshd | ||
| echo "airflow:${COMPOSER_CONTAINER_AIRFLOW_USER_PASSWORD}" | sudo chpasswd | ||
| fi | ||
| echo "Starting sshd" | ||
| sudo /usr/sbin/sshd | ||
|
morgan-dgk marked this conversation as resolved.
|
||
| } | ||
|
|
||
| main() { | ||
| sudo chown airflow:airflow airflow | ||
| sudo chmod +x $run_as_user | ||
|
|
@@ -116,6 +134,10 @@ main() { | |
| sudo chown -R airflow:airflow "$FAST_API_DIR" | ||
| fi | ||
|
|
||
| if [ "${COMPOSER_CONTAINER_ENABLE_SSHD}" = "True" ]; then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, a variable hasn't been renamed. What is more interesting is that all tests are green even with this "not yet renamed" variable. Could you please add a test case that specifically catches this issue? |
||
| install_and_run_sshd | ||
| fi | ||
|
|
||
| if [ "${COMPOSER_CONTAINER_RUN_AS_HOST_USER}" = "True" ]; then | ||
| create_user "${COMPOSER_HOST_USER_NAME}" "${COMPOSER_HOST_USER_ID}" || true | ||
| echo "Running Airflow as user ${COMPOSER_HOST_USER_NAME}(${COMPOSER_HOST_USER_ID})" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| protobuf==5.29.6 | ||
| google-cloud-dlp==3.9.2 | ||
| apache-airflow-providers-google==8.6.0 | ||
| apache-airflow-providers-google==8.10.0 | ||
| proto-plus==1.20.5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import pathlib | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.e2e import ( | ||
| assert_example_dag_listed, | ||
| assert_example_dag_succeeded, | ||
| run_app, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| def test_enable_ssh_airflow(composer_image_version, valid_project_id, env_name): | ||
| dags_dir = pathlib.Path(__file__).parent / "example_dag" | ||
| run_app( | ||
| f"create --from-image-version {composer_image_version} " | ||
| f"-p {valid_project_id} --dags-path {dags_dir} " | ||
| f"--enable-ssh {env_name}" | ||
| ) | ||
| run_app(f"start {env_name}") | ||
| assert_example_dag_listed() | ||
| assert_example_dag_succeeded(env_name, airflow_major_version=2) | ||
| run_app(f"stop {env_name}") | ||
|
|
||
|
|
||
| @pytest.mark.e2e | ||
| def test_enable_ssh_airflow_3( | ||
| composer_image_version_airflow_3, valid_project_id, env_name | ||
| ): | ||
| dags_dir = pathlib.Path(__file__).parent / "example_dag" | ||
| run_app( | ||
| f"create --from-image-version {composer_image_version_airflow_3} " | ||
| f"-p {valid_project_id} --dags-path {dags_dir} " | ||
| f"--enable-ssh {env_name}" | ||
| ) | ||
| # Copy requirements.txt with already satisfied deps to our environment | ||
| run_app(f"start {env_name}") | ||
| assert_example_dag_listed() | ||
| assert_example_dag_succeeded(env_name, airflow_major_version=3) | ||
| run_app(f"stop {env_name}") |
Uh oh!
There was an error while loading. Please reload this page.