File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Ansible Lint
2+
3+ on :
4+ push :
5+ pull_request :
6+
7+ jobs :
8+ lint :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - uses : actions/checkout@v3
12+ - name : Set up Python
13+ uses : actions/setup-python@v4
14+ with :
15+ python-version : ' 3.11'
16+ - name : Install Ansible Lint
17+ run : |
18+ pip install ansible-lint
19+ - name : Run Ansible Lint
20+ run : |
21+ ansible-lint
Original file line number Diff line number Diff line change 1+ .ansible
Original file line number Diff line number Diff line change 1+ pyproxy :
2+ # "compose", "docker", "source"
3+ deploy_method : " compose"
4+
5+ # Compose
6+ compose :
7+ install_path : " /opt/pyproxy"
8+ name : pyproxy
9+ image : ghcr.io/6c656c65/pyproxy
10+ tag : latest
11+ bind_port :
12+ - 8080:8080
13+ - 5000:5000
14+ volumes :
15+ - /opt/pyproxy/logs:/app/logs
16+ environment :
17+ - name : PYPROXY_DEBUG
18+ value : " True"
19+
20+ # Docker
21+ docker :
22+ name : pyproxy
23+ image : ghcr.io/6c656c65/pyproxy
24+ tag : latest
25+ bind_port :
26+ - 8080:8080
27+ - 5000:5000
28+ volumes :
29+ - /opt/pyproxy/logs:/app/logs
30+ environment :
31+ - name : PYPROXY_DEBUG
32+ value : " True"
33+
34+ # Source
35+ source :
36+ repo : " https://github.com/6C656C65/pyproxy.git"
37+ install_path : " /opt/pyproxy"
38+ venv_path : " /opt/pyproxy/venv"
39+ service_name : " pyproxy"
Original file line number Diff line number Diff line change 1+ - name : Restart pyproxy service
2+ ansible.builtin.systemd :
3+ name : " {{ pyproxy.source.service_name }}"
4+ state : restarted
5+ enabled : true
6+ daemon_reload : true
Original file line number Diff line number Diff line change 1+ - name : Create the destination directory for docker-compose.yml
2+ ansible.builtin.file :
3+ path : " {{ pyproxy.compose.install_path }}"
4+ state : directory
5+ mode : ' 0755'
6+
7+ - name : Create docker-compose.yml file
8+ ansible.builtin.template :
9+ src : docker-compose.yml
10+ dest : " {{ pyproxy.compose.install_path }}/docker-compose.yml"
11+ mode : ' 0644'
12+
13+ - name : Pull the latest image using docker-compose
14+ ansible.builtin.command : docker-compose pull
15+ args :
16+ chdir : " {{ pyproxy.compose.install_path }}"
17+ register : pull_result
18+ changed_when : " 'Pulling' in pull_result.stdout or 'up to date' not in pull_result.stdout"
19+
20+ - name : Start the pyproxy service using docker-compose
21+ ansible.builtin.command : docker-compose up -d
22+ args :
23+ chdir : " {{ pyproxy.compose.install_path }}"
24+ register : up_result
25+ changed_when : " 'Creating' in up_result.stdout or 'Recreating' in up_result.stdout"
Original file line number Diff line number Diff line change 1+ - name : Prepare environment variables for Docker container
2+ ansible.builtin.set_fact :
3+ pyproxy_env_vars : " {{ pyproxy.docker.environment |
4+ map(attribute='name') |
5+ zip(pyproxy.docker.environment |
6+ map(attribute='value') |
7+ map('quote')) |
8+ list |
9+ items2dict }}"
10+
11+ - name : Ensure the volume directories exist
12+ ansible.builtin.file :
13+ path : " {{ item }}"
14+ state : directory
15+ owner : 1000
16+ group : 1000
17+ mode : ' 0755'
18+ loop : " {{ pyproxy.docker.volumes | map('split', ':') | map('first') | list }}"
19+
20+ - name : Run pyproxy container
21+ community.docker.docker_container :
22+ name : " {{ pyproxy.docker.name }}"
23+ image : " {{ pyproxy.docker.image }}:{{ pyproxy.docker.tag }}"
24+ pull : true
25+ recreate : true
26+ state : started
27+ restart_policy : always
28+ published_ports : " {{ pyproxy.docker.bind_port }}"
29+ volumes : " {{ pyproxy.docker.volumes }}"
30+ env : " {{ pyproxy_env_vars }}"
31+ detach : true
Original file line number Diff line number Diff line change 1+ - name : Install git and python3-venv
2+ ansible.builtin.apt :
3+ name : [git, python3-venv]
4+ state : present
5+ update_cache : true
6+
7+ - name : Create a user with no shell
8+ ansible.builtin.user :
9+ name : pyproxy
10+ shell : /bin/false
11+ state : present
12+
13+ - name : Clone the repository
14+ ansible.builtin.git :
15+ repo : " {{ pyproxy.source.repo }}"
16+ dest : " {{ pyproxy.source.install_path }}"
17+ version : main
18+
19+ - name : Configure git safe.directory for pyproxy repo
20+ community.general.git_config :
21+ name : safe.directory
22+ value : " {{ pyproxy.source.install_path }}"
23+ scope : global
24+
25+ - name : Set ownership of the installation path
26+ ansible.builtin.file :
27+ path : " {{ pyproxy.source.install_path }}"
28+ owner : pyproxy
29+ group : pyproxy
30+ recurse : true
31+
32+ - name : Create a virtual environment
33+ ansible.builtin.command : python3 -m venv {{ pyproxy.source.venv_path }}
34+ args :
35+ creates : " {{ pyproxy.source.venv_path }}"
36+
37+ - name : Install dependencies
38+ ansible.builtin.pip :
39+ requirements : " {{ pyproxy.source.install_path }}/requirements.txt"
40+ virtualenv : " {{ pyproxy.source.venv_path }}"
41+
42+ - name : Create a systemd service
43+ ansible.builtin.template :
44+ src : pyproxy.service
45+ dest : " /etc/systemd/system/{{ pyproxy.source.service_name }}.service"
46+ owner : root
47+ group : root
48+ mode : ' 0644'
49+ notify : Restart pyproxy service
50+ changed_when : true
Original file line number Diff line number Diff line change 1+ - name : Include install from source
2+ ansible.builtin.include_tasks : install_from_source.yml
3+ when : pyproxy.deploy_method == "source"
4+
5+ - name : Include install from docker
6+ ansible.builtin.include_tasks : install_from_docker.yml
7+ when : pyproxy.deploy_method == "docker"
8+
9+ - name : Include install from compose
10+ ansible.builtin.include_tasks : install_from_compose.yml
11+ when : pyproxy.deploy_method == "compose"
Original file line number Diff line number Diff line change 1+ version : ' 3.8'
2+
3+ services :
4+ {{ pyproxy.compose.name }}:
5+ image : " {{ pyproxy.compose.image }}:{{ pyproxy.compose.tag }}"
6+ container_name : " {{ pyproxy.compose.name }}"
7+ restart : always
8+ ports :
9+ {% for port in pyproxy.compose.bind_port %}
10+ - " {{ port }}"
11+ {% endfor %}
12+ volumes :
13+ {% for volume in pyproxy.compose.volumes %}
14+ - " {{ volume }}"
15+ {% endfor %}
16+ environment :
17+ {% for env in pyproxy.compose.environment %}
18+ - " {{ env.name }}={{ env.value }}"
19+ {% endfor %}
Original file line number Diff line number Diff line change 1+ [Unit]
2+ Description =PyProxy Service
3+ After =network.target
4+
5+ [Service]
6+ User =pyproxy
7+ ExecStart =python3 pyproxy.py
8+ Restart =always
9+ WorkingDirectory ={{ pyproxy.source.install_path }}
10+ Environment =PATH ={{ pyproxy.source.venv_path }}/bin
11+
12+ [Install]
13+ WantedBy =multi-user.target
You can’t perform that action at this time.
0 commit comments