Skip to content

Commit a66d8f0

Browse files
jackivanovdguido
authored andcommitted
on-build python venvs (#1199)
1 parent 9187d8e commit a66d8f0

File tree

26 files changed

+465
-304
lines changed

26 files changed

+465
-304
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ inventory_users
55
*.kate-swp
66
env
77
.DS_Store
8+
venvs/*
9+
!venvs/.gitinit

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ COPY . .
2626
RUN chmod 0755 /algo/algo-docker.sh
2727

2828
# Because of the bind mounting of `configs/`, we need to run as the `root` user
29-
# This may break in cases where user namespacing is enabled, so hopefully Docker
29+
# This may break in cases where user namespacing is enabled, so hopefully Docker
3030
# sorts out a way to set permissions on bind-mounted volumes (`docker run -v`)
3131
# before userns becomes default
3232
# Note that not running as root will break if we don't have a matching userid

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The easiest way to get an Algo server running is to let it set up a _new_ virtua
5858
```bash
5959
$ python -m virtualenv --python=`which python2` env &&
6060
source env/bin/activate &&
61-
python -m pip install -U pip &&
61+
python -m pip install -U pip virtualenv &&
6262
python -m pip install -r requirements.txt
6363
```
6464
On macOS, you may be prompted to install `cc`. You should press accept if so.

config.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ users:
1313
# If True re-init all existing certificates. Boolean
1414
keys_clean_all: False
1515

16+
# Clean up cloud python environments
17+
clean_environment: false
18+
1619
vpn_network: 10.19.48.0/24
1720
vpn_network_ipv6: 'fd9d:bc11:4020::/48'
1821
wireguard_enabled: true

playbooks/cloud-pre.yml

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
'dns_encryption "{{ dns_encryption }}"' \
1515
> /dev/tty
1616

17+
- name: Install the requirements
18+
local_action:
19+
module: pip
20+
state: latest
21+
name:
22+
- pyOpenSSL
23+
- jinja2==2.8
24+
- segno
25+
tags: always
26+
1727
- name: Generate the SSH private key
1828
openssl_privatekey:
1929
path: "{{ SSH_keys.private }}"

requirements.txt

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
setuptools>=11.3
2-
SecretStorage < 3
3-
ansible[azure]==2.5.2
4-
dopy==0.3.5
5-
boto>=2.5
6-
boto3
7-
apache-libcloud
8-
six
9-
pyopenssl
10-
jinja2==2.8
11-
shade
12-
pycrypto
13-
segno
1+
ansible==2.5.2

roles/cloud-azure/defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
azure_venv: "{{ playbook_dir }}/configs/.venvs/azure"
23
_azure_regions: >
34
[
45
{

roles/cloud-azure/tasks/main.yml

+39-34
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
11
---
22
- block:
3-
- name: Include prompts
4-
import_tasks: prompts.yml
3+
- name: Build python virtual environment
4+
import_tasks: venv.yml
55

6-
- set_fact:
7-
algo_region: >-
8-
{% if region is defined %}{{ region }}
9-
{%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ azure_regions[_algo_region.user_input | int -1 ]['name'] }}
10-
{%- else %}{{ azure_regions[default_region | int - 1]['name'] }}{% endif %}
6+
- block:
7+
- name: Include prompts
8+
import_tasks: prompts.yml
119

12-
- name: Create AlgoVPN Server
13-
azure_rm_deployment:
14-
state: present
15-
deployment_name: "AlgoVPN-{{ algo_server_name }}"
16-
template: "{{ lookup('file', 'deployment.json') }}"
17-
secret: "{{ secret }}"
18-
tenant: "{{ tenant }}"
19-
client_id: "{{ client_id }}"
20-
subscription_id: "{{ subscription_id }}"
21-
resource_group_name: "AlgoVPN-{{ algo_server_name }}"
22-
parameters:
23-
AlgoServerName:
24-
value: "{{ algo_server_name }}"
25-
sshKeyData:
26-
value: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
27-
location:
28-
value: "{{ algo_region }}"
29-
WireGuardPort:
30-
value: "{{ wireguard_port }}"
31-
vmSize:
32-
value: "{{ cloud_providers.azure.size }}"
33-
imageReferenceSku:
34-
value: "{{ cloud_providers.azure.image }}"
35-
register: azure_rm_deployment
10+
- set_fact:
11+
algo_region: >-
12+
{% if region is defined %}{{ region }}
13+
{%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ azure_regions[_algo_region.user_input | int -1 ]['name'] }}
14+
{%- else %}{{ azure_regions[default_region | int - 1]['name'] }}{% endif %}
3615
37-
- set_fact:
38-
cloud_instance_ip: "{{ azure_rm_deployment.deployment.outputs.publicIPAddresses.value }}"
39-
ansible_ssh_user: ubuntu
16+
- name: Create AlgoVPN Server
17+
azure_rm_deployment:
18+
state: present
19+
deployment_name: "AlgoVPN-{{ algo_server_name }}"
20+
template: "{{ lookup('file', 'deployment.json') }}"
21+
secret: "{{ secret }}"
22+
tenant: "{{ tenant }}"
23+
client_id: "{{ client_id }}"
24+
subscription_id: "{{ subscription_id }}"
25+
resource_group_name: "AlgoVPN-{{ algo_server_name }}"
26+
parameters:
27+
AlgoServerName:
28+
value: "{{ algo_server_name }}"
29+
sshKeyData:
30+
value: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
31+
location:
32+
value: "{{ algo_region }}"
33+
WireGuardPort:
34+
value: "{{ wireguard_port }}"
35+
vmSize:
36+
value: "{{ cloud_providers.azure.size }}"
37+
imageReferenceSku:
38+
value: "{{ cloud_providers.azure.image }}"
39+
register: azure_rm_deployment
4040

41+
- set_fact:
42+
cloud_instance_ip: "{{ azure_rm_deployment.deployment.outputs.publicIPAddresses.value }}"
43+
ansible_ssh_user: ubuntu
44+
environment:
45+
PYTHONPATH: "{{ azure_venv }}/lib/python2.7/site-packages/"
4146
rescue:
4247
- debug: var=fail_hint
4348
tags: always

roles/cloud-azure/tasks/venv.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
- name: Clean up the environment
3+
file:
4+
dest: "{{ azure_venv }}"
5+
state: absent
6+
when: clean_environment
7+
8+
- name: Install requirements
9+
pip:
10+
name:
11+
- packaging
12+
- requests[security]
13+
- azure-mgmt-compute>=2.0.0,<3
14+
- azure-mgmt-network>=1.3.0,<2
15+
- azure-mgmt-storage>=1.5.0,<2
16+
- azure-mgmt-resource>=1.1.0,<2
17+
- azure-storage>=0.35.1,<0.36
18+
- azure-cli-core>=2.0.12,<3
19+
- msrest==0.4.29
20+
- msrestazure==0.4.31
21+
- azure-mgmt-dns>=1.0.1,<2
22+
- azure-mgmt-keyvault>=0.40.0,<0.41
23+
- azure-mgmt-batch>=4.1.0,<5
24+
- azure-mgmt-sql>=0.7.1,<0.8
25+
- azure-mgmt-web>=0.32.0,<0.33
26+
- azure-mgmt-containerservice>=2.0.0,<3.0.0
27+
- azure-mgmt-containerregistry>=1.0.1
28+
- azure-mgmt-rdbms==1.2.0
29+
- azure-mgmt-containerinstance==0.4.0
30+
state: latest
31+
virtualenv: "{{ azure_venv }}"
32+
virtualenv_python: python2.7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
digitalocean_venv: "{{ playbook_dir }}/configs/.venvs/digitalocean"

roles/cloud-digitalocean/tasks/main.yml

+91-85
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,108 @@
11
- block:
2-
- name: Include prompts
3-
import_tasks: prompts.yml
4-
5-
- name: Set additional facts
6-
set_fact:
7-
algo_do_region: >-
8-
{% if region is defined %}{{ region }}
9-
{%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }}
10-
{%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %}
11-
public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
2+
- name: Build python virtual environment
3+
import_tasks: venv.yml
124

135
- block:
14-
- name: "Delete the existing Algo SSH keys"
15-
digital_ocean:
16-
state: absent
17-
command: ssh
18-
api_token: "{{ algo_do_token }}"
19-
name: "{{ SSH_keys.comment }}"
20-
register: ssh_keys
21-
until: ssh_keys.changed != true
22-
retries: 10
23-
delay: 1
6+
- name: Include prompts
7+
import_tasks: prompts.yml
248

25-
rescue:
26-
- name: Collect the fail error
27-
digital_ocean:
28-
state: absent
29-
command: ssh
30-
api_token: "{{ algo_do_token }}"
31-
name: "{{ SSH_keys.comment }}"
32-
register: ssh_keys
33-
ignore_errors: yes
9+
- name: Set additional facts
10+
set_fact:
11+
algo_do_region: >-
12+
{% if region is defined %}{{ region }}
13+
{%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }}
14+
{%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %}
15+
public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
3416

35-
- debug: var=ssh_keys
17+
- block:
18+
- name: "Delete the existing Algo SSH keys"
19+
digital_ocean:
20+
state: absent
21+
command: ssh
22+
api_token: "{{ algo_do_token }}"
23+
name: "{{ SSH_keys.comment }}"
24+
register: ssh_keys
25+
until: ssh_keys.changed != true
26+
retries: 10
27+
delay: 1
3628

37-
- fail:
38-
msg: "Please, ensure that your API token is not read-only."
29+
rescue:
30+
- name: Collect the fail error
31+
digital_ocean:
32+
state: absent
33+
command: ssh
34+
api_token: "{{ algo_do_token }}"
35+
name: "{{ SSH_keys.comment }}"
36+
register: ssh_keys
37+
ignore_errors: yes
3938

40-
- name: "Upload the SSH key"
41-
digital_ocean:
42-
state: present
43-
command: ssh
44-
ssh_pub_key: "{{ public_key }}"
45-
api_token: "{{ algo_do_token }}"
46-
name: "{{ SSH_keys.comment }}"
47-
register: do_ssh_key
39+
- debug: var=ssh_keys
4840

49-
- name: "Creating a droplet..."
50-
digital_ocean:
51-
state: present
52-
command: droplet
53-
name: "{{ algo_server_name }}"
54-
region_id: "{{ algo_do_region }}"
55-
size_id: "{{ cloud_providers.digitalocean.size }}"
56-
image_id: "{{ cloud_providers.digitalocean.image }}"
57-
ssh_key_ids: "{{ do_ssh_key.ssh_key.id }}"
58-
unique_name: yes
59-
api_token: "{{ algo_do_token }}"
60-
ipv6: yes
61-
register: do
41+
- fail:
42+
msg: "Please, ensure that your API token is not read-only."
6243

63-
- set_fact:
64-
cloud_instance_ip: "{{ do.droplet.ip_address }}"
65-
ansible_ssh_user: root
44+
- name: "Upload the SSH key"
45+
digital_ocean:
46+
state: present
47+
command: ssh
48+
ssh_pub_key: "{{ public_key }}"
49+
api_token: "{{ algo_do_token }}"
50+
name: "{{ SSH_keys.comment }}"
51+
register: do_ssh_key
6652

67-
- name: Tag the droplet
68-
digital_ocean_tag:
69-
name: "Environment:Algo"
70-
resource_id: "{{ do.droplet.id }}"
71-
api_token: "{{ algo_do_token }}"
72-
state: present
53+
- name: "Creating a droplet..."
54+
digital_ocean:
55+
state: present
56+
command: droplet
57+
name: "{{ algo_server_name }}"
58+
region_id: "{{ algo_do_region }}"
59+
size_id: "{{ cloud_providers.digitalocean.size }}"
60+
image_id: "{{ cloud_providers.digitalocean.image }}"
61+
ssh_key_ids: "{{ do_ssh_key.ssh_key.id }}"
62+
unique_name: yes
63+
api_token: "{{ algo_do_token }}"
64+
ipv6: yes
65+
register: do
7366

74-
- block:
75-
- name: "Delete the new Algo SSH key"
76-
digital_ocean:
77-
state: absent
78-
command: ssh
79-
api_token: "{{ algo_do_token }}"
80-
name: "{{ SSH_keys.comment }}"
81-
register: ssh_keys
82-
until: ssh_keys.changed != true
83-
retries: 10
84-
delay: 1
67+
- set_fact:
68+
cloud_instance_ip: "{{ do.droplet.ip_address }}"
69+
ansible_ssh_user: root
70+
71+
- name: Tag the droplet
72+
digital_ocean_tag:
73+
name: "Environment:Algo"
74+
resource_id: "{{ do.droplet.id }}"
75+
api_token: "{{ algo_do_token }}"
76+
state: present
77+
78+
- block:
79+
- name: "Delete the new Algo SSH key"
80+
digital_ocean:
81+
state: absent
82+
command: ssh
83+
api_token: "{{ algo_do_token }}"
84+
name: "{{ SSH_keys.comment }}"
85+
register: ssh_keys
86+
until: ssh_keys.changed != true
87+
retries: 10
88+
delay: 1
8589

86-
rescue:
87-
- name: Collect the fail error
88-
digital_ocean:
89-
state: absent
90-
command: ssh
91-
api_token: "{{ algo_do_token }}"
92-
name: "{{ SSH_keys.comment }}"
93-
register: ssh_keys
94-
ignore_errors: yes
90+
rescue:
91+
- name: Collect the fail error
92+
digital_ocean:
93+
state: absent
94+
command: ssh
95+
api_token: "{{ algo_do_token }}"
96+
name: "{{ SSH_keys.comment }}"
97+
register: ssh_keys
98+
ignore_errors: yes
9599

96-
- debug: var=ssh_keys
100+
- debug: var=ssh_keys
97101

98-
- fail:
99-
msg: "Please, ensure that your API token is not read-only."
102+
- fail:
103+
msg: "Please, ensure that your API token is not read-only."
104+
environment:
105+
PYTHONPATH: "{{ digitalocean_venv }}/lib/python2.7/site-packages/"
100106
rescue:
101107
- debug: var=fail_hint
102108
tags: always
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Clean up the environment
3+
file:
4+
dest: "{{ digitalocean_venv }}"
5+
state: absent
6+
when: clean_environment
7+
8+
- name: Install requirements
9+
pip:
10+
name: dopy
11+
version: 0.3.5
12+
virtualenv: "{{ digitalocean_venv }}"
13+
virtualenv_python: python2.7

0 commit comments

Comments
 (0)