<commit_before>---
- name: Create media root
  become: true
  ansible.builtin.file:
    mode: 0755
    path: "{{ chmvh_media_root }}"
    state: directory

- name: Create static root
  become: true
  ansible.builtin.file:
    mode: 0755
    path: "{{ chmvh_static_root }}"
    state: directory

- name: Create OS user for database
  become: true
  ansible.builtin.user:
    create_home: false
    name: "{{ chmvh_db_os_user }}"
  register: db_user

- name: Create database data directory
  become: true
  ansible.builtin.file:
    mode: 0755
    owner: "{{ chmvh_db_os_user }}"
    path: "{{ chmvh_db_data_dir }}"
    state: directory

- name: Run Postgres server
  community.general.docker_container:
    env:
      POSTGRES_PASSWORD: "{{ chmvh_db_super_password }}"
      POSTGRES_USER: "{{ chmvh_db_super_user }}"
    image: postgres:12
    name: postgres
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    ports:
      - 5432:5432
    restart_policy: unless-stopped
    user: "{{ db_user.uid }}"
    volumes:
      - "{{ chmvh_db_data_dir }}:/var/lib/postgresql/data"

- name: Create application database user
  no_log: true
  postgresql_user:
    login_db: postgres
    login_host: localhost
    login_password: "{{ <PASSWORD> }}"
    login_user: "{{ chmvh_db_super_user }}"
    name: "{{ chmvh_db_user }}"
    password: "<PASSWORD>{{ (ch<PASSWORD>('<PASSWORD>') }}"

- name: Create application database
  postgresql_db:
    login_host: localhost
    login_password: "{{ <PASSWORD> }}"
    login_user: "{{ chmvh_db_super_user }}"
    name: "{{ chmvh_db_name }}"
    owner: "{{ chmvh_db_user }}"

- name: Run management tasks
  docker_container:
    command: "{{ item }}"
    detach: false
    entrypoint: "./manage.py"
    env:
      CHMVH_DB_HOST: "postgres"
      CHMVH_DB_NAME: "{{ chmvh_db_name }}"
      CHMVH_DB_PASSWORD: "{{ <PASSWORD>db_password }}"
      CHMVH_DB_PORT: "5432"
      CHMVH_DB_USER: "{{ chmvh_db_user }}"
      CHMVH_SECRET_KEY: "{{ chmvh_secret_key }}"
      CHMVH_STATIC_ROOT: "/var/www/static"
    image: "{{ chmvh_web_image }}"
    name: "chmvh-{{ item }}"
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    volumes:
      - "{{ chmvh_static_root }}:/var/www/static"
  with_items:
    - "collectstatic"
    - "migrate"

- name: Serve static content
  community.general.docker_container:
    image: nginx:1.19
    labels:
      traefik.enable: "true"
      traefik.http.routers.chmvh-static.entrypoints: websecure
      traefik.http.routers.chmvh-static.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`) && PathPrefix(`/media/`, `/static/`)"
      traefik.http.routers.chmvh-static.tls: "true"
      traefik.http.routers.chmvh-static.tls.certresolver: "letsencrypt"
      traefik.http.services.chmvh-static.loadbalancer.server.port: "80"
      # Redirect HTTP to HTTPS
      traefik.http.routers.chmvh-static-http.middlewares: "https-redirect@file"
      traefik.http.routers.chmvh-static-http.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`) && PathPrefix(`/media/', '/static/`)"
    name: chmvh-static
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    restart_policy: unless-stopped
    volumes:
      - "{{ chmvh_media_root }}:/usr/share/nginx/html/media:ro"
      - "{{ chmvh_static_root }}:/usr/share/nginx/html/static:ro"

- name: Run web server
  docker_container:
    env:
      CHMVH_ADMIN_EMAIL: "{{ admin_email }}"
      CHMVH_ADMIN_PASSWORD: "{{ <PASSWORD> }}"
      CHMVH_ALLOWED_HOSTS: "{{ chmvh_hosts | join(',') }}"
      CHMVH_DB_HOST: "postgres"
      CHMVH_DB_NAME: "{{ chmvh_db_name }}"
      CHMVH_DB_PASSWORD: "{{ <PASSWORD> }}"
      CHMVH_DB_PORT: "5432"
      CHMVH_DB_USER: "{{ chmvh_db_user }}"
      CHMVH_EMAIL_PASSWORD: "{{ <PASSWORD> }}"
      CHMVH_EMAIL_USER: "{{ sendgrid_user }}"
      CHMVH_GOOGLE_ANALYTICS_ID: "{{ google_analytics_id }}"
      CHMVH_MEDIA_ROOT: "/var/www/media"
      CHMVH_RECAPTCHA_PRIVATE_KEY: "{{ recaptcha_private_key }}"
      CHMVH_RECAPTCHA_PUBLIC_KEY: "{{ recaptcha_public_key }}"
      CHMVH_SECRET_KEY: "{{ chmvh_secret_key }}"
      CHMVH_STATIC_ROOT: "/var/www/static"
    image: "{{ chmvh_web_image }}"
    labels:
      traefik.enable: "true"
      traefik.http.routers.chmvh.entrypoints: websecure
      traefik.http.routers.chmvh.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`)"
      traefik.http.routers.chmvh.tls: "true"
      traefik.http.routers.chmvh.tls.certresolver: "letsencrypt"
      traefik.http.services.chmvh.loadbalancer.server.port: "8000"
      # Redirect HTTP to HTTPS
      traefik.http.routers.chmvh-http.middlewares: "https-redirect@file"
      traefik.http.routers.chmvh-http.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`)"
    name: "chmvh-web"
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    restart_policy: unless-stopped
    volumes:
      - "{{ chmvh_media_root }}:/var/www/media"
      - "{{ chmvh_static_root }}:/var/www/static:ro"
<commit_msg>Prevent input during management commands.<commit_after>---
- name: Create media root
  become: true
  ansible.builtin.file:
    mode: 0755
    path: "{{ chmvh_media_root }}"
    state: directory

- name: Create static root
  become: true
  ansible.builtin.file:
    mode: 0755
    path: "{{ chmvh_static_root }}"
    state: directory

- name: Create OS user for database
  become: true
  ansible.builtin.user:
    create_home: false
    name: "{{ chmvh_db_os_user }}"
  register: db_user

- name: Create database data directory
  become: true
  ansible.builtin.file:
    mode: 0755
    owner: "{{ chmvh_db_os_user }}"
    path: "{{ chmvh_db_data_dir }}"
    state: directory

- name: Run Postgres server
  community.general.docker_container:
    env:
      POSTGRES_PASSWORD: "{{ chmvh_db_super_password }}"
      POSTGRES_USER: "{{ chmvh_db_super_user }}"
    image: postgres:12
    name: postgres
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    ports:
      - 5432:5432
    restart_policy: unless-stopped
    user: "{{ db_user.uid }}"
    volumes:
      - "{{ chmvh_db_data_dir }}:/var/lib/postgresql/data"

- name: Create application database user
  no_log: true
  postgresql_user:
    login_db: postgres
    login_host: localhost
    login_password: "{{ <PASSWORD> }}"
    login_user: "{{ chmvh_db_super_user }}"
    name: "{{ chmvh_db_user }}"
    password: "<PASSWORD>{{ (chmvh_db_password + chmvh_db_user) | hash('md5') }}"

- name: Create application database
  postgresql_db:
    login_host: localhost
    login_password: "{{ <PASSWORD> }}"
    login_user: "{{ chmvh_db_super_user }}"
    name: "{{ chmvh_db_name }}"
    owner: "{{ chmvh_db_user }}"

- name: Run management tasks
  docker_container:
    command: ["{{ item }}", "--no-input"]
    detach: false
    entrypoint: "./manage.py"
    env:
      CHMVH_DB_HOST: "postgres"
      CHMVH_DB_NAME: "{{ chmvh_db_name }}"
      CHMVH_DB_PASSWORD: "{{ <PASSWORD> }}"
      CHMVH_DB_PORT: "5432"
      CHMVH_DB_USER: "{{ chmvh_db_user }}"
      CHMVH_SECRET_KEY: "{{ chmvh_secret_key }}"
      CHMVH_STATIC_ROOT: "/var/www/static"
    image: "{{ chmvh_web_image }}"
    name: "chmvh-{{ item }}"
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    volumes:
      - "{{ chmvh_static_root }}:/var/www/static"
  with_items:
    - "collectstatic"
    - "migrate"

- name: Serve static content
  community.general.docker_container:
    image: nginx:1.19
    labels:
      traefik.enable: "true"
      traefik.http.routers.chmvh-static.entrypoints: websecure
      traefik.http.routers.chmvh-static.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`) && PathPrefix(`/media/`, `/static/`)"
      traefik.http.routers.chmvh-static.tls: "true"
      traefik.http.routers.chmvh-static.tls.certresolver: "letsencrypt"
      traefik.http.services.chmvh-static.loadbalancer.server.port: "80"
      # Redirect HTTP to HTTPS
      traefik.http.routers.chmvh-static-http.middlewares: "https-redirect@file"
      traefik.http.routers.chmvh-static-http.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`) && PathPrefix(`/media/', '/static/`)"
    name: chmvh-static
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    restart_policy: unless-stopped
    volumes:
      - "{{ chmvh_media_root }}:/usr/share/nginx/html/media:ro"
      - "{{ chmvh_static_root }}:/usr/share/nginx/html/static:ro"

- name: Run web server
  docker_container:
    env:
      CHMVH_ADMIN_EMAIL: "{{ admin_email }}"
      CHMVH_ADMIN_PASSWORD: "{{ admin_name }}"
      CHMVH_ALLOWED_HOSTS: "{{ chmvh_hosts | join(',') }}"
      CHMVH_DB_HOST: "postgres"
      CHMVH_DB_NAME: "{{ chmvh_db_name }}"
      CHMVH_DB_PASSWORD: "{{ chmvh_db_password }}"
      CHMVH_DB_PORT: "5432"
      CHMVH_DB_USER: "{{ chmvh_db_user }}"
      CHMVH_EMAIL_PASSWORD: "{{ <PASSWORD> }}"
      CHMVH_EMAIL_USER: "{{ sendgrid_user }}"
      CHMVH_GOOGLE_ANALYTICS_ID: "{{ google_analytics_id }}"
      CHMVH_MEDIA_ROOT: "/var/www/media"
      CHMVH_RECAPTCHA_PRIVATE_KEY: "{{ recaptcha_private_key }}"
      CHMVH_RECAPTCHA_PUBLIC_KEY: "{{ recaptcha_public_key }}"
      CHMVH_SECRET_KEY: "{{ chmvh_secret_key }}"
      CHMVH_STATIC_ROOT: "/var/www/static"
    image: "{{ chmvh_web_image }}"
    labels:
      traefik.enable: "true"
      traefik.http.routers.chmvh.entrypoints: websecure
      traefik.http.routers.chmvh.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`)"
      traefik.http.routers.chmvh.tls: "true"
      traefik.http.routers.chmvh.tls.certresolver: "letsencrypt"
      traefik.http.services.chmvh.loadbalancer.server.port: "8000"
      # Redirect HTTP to HTTPS
      traefik.http.routers.chmvh-http.middlewares: "https-redirect@file"
      traefik.http.routers.chmvh-http.rule: "Host(`{{ chmvh_hosts | join('`, `') }}`)"
    name: "chmvh-web"
    networks:
      - "{{ chmvh_docker_network }}"
    networks_cli_compatible: true
    restart_policy: unless-stopped
    volumes:
      - "{{ chmvh_media_root }}:/var/www/media"
      - "{{ chmvh_static_root }}:/var/www/static:ro"

{'fraction_non_alphanumeric': 0.14776768075859345, 'fraction_numerical': 0.00780323982615567, 'mean_word_length': 3.2685497470489038, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1065774', 'n_tokens_mistral': 4040, 'n_tokens_neox': 3921, 'n_words': 587}