package_requirements.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from airflow import DAG
  2. from datetime import datetime
  3. from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
  4. from airflow.configuration import conf
  5. # get the current Kubernetes namespace Airflow is running in
  6. namespace = conf.get("kubernetes", "NAMESPACE")
  7. # set the name that will be printed
  8. name = 'luoyulong'
  9. python_requirements = ['sphinx>=1.8','sphinx_rtd_theme','recommonmark>=0.6.0','markdown>=3.4.1']
  10. # instantiate the DAG
  11. with DAG(
  12. start_date=datetime(2022,6,1),
  13. catchup=False,
  14. schedule_interval='@daily',
  15. dag_id='lyl_package_test'
  16. ) as dag:
  17. package_python_libs = KubernetesPodOperator(
  18. # unique id of the task within the DAG
  19. task_id='package',
  20. # the Docker image to launch
  21. image='SXKJ:32775/jupyter:1.0',
  22. # launch the Pod on the same cluster as Airflow is running on
  23. in_cluster=True,
  24. # launch the Pod in the same namespace as Airflow is running in
  25. namespace=namespace,
  26. # Pod configuration
  27. # name the Pod
  28. name='my_fucking_pod',
  29. # give the Pod name a random suffix, ensure uniqueness in the namespace
  30. random_name_suffix=True,
  31. # attach labels to the Pod, can be used for grouping
  32. labels={'app':'backend', 'env':'dev'},
  33. # reattach to worker instead of creating a new Pod on worker failure
  34. reattach_on_restart=True,
  35. # delete Pod after the task is finished
  36. is_delete_operator_pod=True,
  37. # get log stdout of the container as task logs
  38. get_logs=True,
  39. # log events in case of Pod failure
  40. log_events_on_failure=True,
  41. cmds=["/bin/bash", "-c",'/home/sxkj/bigdata/install.sh'],
  42. # pass your name as an environment var
  43. env_vars={"PYTHON_REQUIREMENTS": ' '.join(python_requirements),
  44. "UPLOAD_PATH":'/tmp/x'
  45. }
  46. )