vm-tool 1.0.19__tar.gz → 1.0.21__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {vm_tool-1.0.19/vm_tool.egg-info → vm_tool-1.0.21}/PKG-INFO +25 -17
  2. {vm_tool-1.0.19 → vm_tool-1.0.21}/README.md +24 -16
  3. {vm_tool-1.0.19 → vm_tool-1.0.21}/setup.py +1 -1
  4. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/cli.py +1 -1
  5. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/runner.py +55 -29
  6. vm_tool-1.0.21/vm_tool/vm_setup/cleanup.yml +27 -0
  7. vm_tool-1.0.21/vm_tool/vm_setup/docker/docker_setup.yml +7 -0
  8. vm_tool-1.0.21/vm_tool/vm_setup/docker/login_to_docker_hub.yml +6 -0
  9. vm_tool-1.0.21/vm_tool/vm_setup/dynamic_inventory.yml +8 -0
  10. vm_tool-1.0.21/vm_tool/vm_setup/github/git_configuration.yml +22 -0
  11. vm_tool-1.0.21/vm_tool/vm_setup/main.yml +22 -0
  12. vm_tool-1.0.21/vm_tool/vm_setup/project_service.yml +16 -0
  13. vm_tool-1.0.21/vm_tool/vm_setup/setup.yml +5 -0
  14. {vm_tool-1.0.19 → vm_tool-1.0.21/vm_tool.egg-info}/PKG-INFO +25 -17
  15. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool.egg-info/SOURCES.txt +7 -1
  16. vm_tool-1.0.19/vm_tool/vm_setup/dynamic_inventory.yml +0 -0
  17. vm_tool-1.0.19/vm_tool/vm_setup/setup.yml +0 -81
  18. {vm_tool-1.0.19 → vm_tool-1.0.21}/LICENSE +0 -0
  19. {vm_tool-1.0.19 → vm_tool-1.0.21}/MANIFEST.in +0 -0
  20. {vm_tool-1.0.19 → vm_tool-1.0.21}/setup.cfg +0 -0
  21. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/__init__.py +0 -0
  22. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/ssh.py +0 -0
  23. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/vm_setup/docker/create_docker_service.yml +0 -0
  24. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/vm_setup/docker/install_docker_and_compose.yml +0 -0
  25. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool/vm_setup/inventory.yml +0 -0
  26. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool.egg-info/dependency_links.txt +0 -0
  27. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool.egg-info/entry_points.txt +0 -0
  28. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool.egg-info/requires.txt +0 -0
  29. {vm_tool-1.0.19 → vm_tool-1.0.21}/vm_tool.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: vm_tool
3
- Version: 1.0.19
3
+ Version: 1.0.21
4
4
  Summary: A Comprehensive Tool for Setting Up Virtual Machines.
5
5
  Home-page: https://github.com/thesunnysinha/vm_tool
6
6
  Author: Sunny Sinha
@@ -83,10 +83,12 @@ Use the following example to configure and run the VM setup:
83
83
  from vm_tool.runner import SetupRunner, SetupRunnerConfig
84
84
 
85
85
  config = SetupRunnerConfig(
86
- github_username='your_github_username', # e.g., username
87
- github_token='your_github_token', # e.g., token
86
+ github_username='your_github_username', # Required if the repository is private, e.g., username
87
+ github_token='your_github_token', # Required if the repository is private, e.g., token
88
88
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
89
- docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
89
+ docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
90
+ dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
91
+ dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
90
92
  )
91
93
 
92
94
  runner = SetupRunner(config)
@@ -96,11 +98,13 @@ runner.run_setup()
96
98
 
97
99
  ### **What Happens During Setup**
98
100
  The VM Setup Tool will:
99
- 1. Clone the specified GitHub repository to your local machine.
100
- 2. Install **Docker** if it’s not already available on the target machine.
101
- 3. Install **Docker Compose** for managing multi-container applications.
102
- 4. Create, enable, and start the Docker service.
103
- 5. Ensure the Docker container remains active, providing a robust environment for your applications.
101
+ 1. Configure Git with GitHub token if provided.
102
+ 2. Clone the specified GitHub repository to your local machine.
103
+ 3. Install **Docker** if it’s not already available on the target machine.
104
+ 4. Install **Docker Compose** for managing multi-container applications.
105
+ 5. Log in to Docker Hub if credentials are provided.
106
+ 6. Create, enable, and start the Docker service.
107
+ 7. Ensure the Docker container remains active, providing a robust environment for your applications.
104
108
 
105
109
  By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
106
110
 
@@ -113,10 +117,12 @@ The **VM Setup Tool** also supports cloud setup for VMs. Use the following examp
113
117
  from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
114
118
 
115
119
  config = SetupRunnerConfig(
116
- github_username='your_github_username', # e.g., username
117
- github_token='your_github_token', # e.g., token
120
+ github_username='your_github_username', # Required if the repository is private, e.g., username
121
+ github_token='your_github_token', # Required if the repository is private, e.g., token
118
122
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
119
- docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
123
+ docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
124
+ dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
125
+ dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
120
126
  )
121
127
 
122
128
  runner = SetupRunner(config)
@@ -141,11 +147,13 @@ runner.run_cloud_setup(ssh_configs)
141
147
  ### **What Happens During Cloud Setup**
142
148
  When you run the cloud setup, the tool will:
143
149
  1. Connect to the specified cloud VM using SSH.
144
- 2. Clone the specified GitHub repository to the VM.
145
- 3. Install **Docker** if it’s not already available on the VM.
146
- 4. Install **Docker Compose** for managing multi-container applications.
147
- 5. Create, enable, and start the Docker service on the VM.
148
- 6. Ensure the Docker container remains active, providing a robust environment for your applications.
150
+ 2. Configure Git with GitHub token if provided.
151
+ 3. Clone the specified GitHub repository to the VM.
152
+ 4. Install **Docker** if it’s not already available on the VM.
153
+ 5. Install **Docker Compose** for managing multi-container applications.
154
+ 6. Log in to Docker Hub if credentials are provided.
155
+ 7. Create, enable, and start the Docker service on the VM.
156
+ 8. Ensure the Docker container remains active, providing a robust environment for your applications.
149
157
 
150
158
  ---
151
159
 
@@ -29,10 +29,12 @@ Use the following example to configure and run the VM setup:
29
29
  from vm_tool.runner import SetupRunner, SetupRunnerConfig
30
30
 
31
31
  config = SetupRunnerConfig(
32
- github_username='your_github_username', # e.g., username
33
- github_token='your_github_token', # e.g., token
32
+ github_username='your_github_username', # Required if the repository is private, e.g., username
33
+ github_token='your_github_token', # Required if the repository is private, e.g., token
34
34
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
35
- docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
35
+ docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
36
+ dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
37
+ dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
36
38
  )
37
39
 
38
40
  runner = SetupRunner(config)
@@ -42,11 +44,13 @@ runner.run_setup()
42
44
 
43
45
  ### **What Happens During Setup**
44
46
  The VM Setup Tool will:
45
- 1. Clone the specified GitHub repository to your local machine.
46
- 2. Install **Docker** if it’s not already available on the target machine.
47
- 3. Install **Docker Compose** for managing multi-container applications.
48
- 4. Create, enable, and start the Docker service.
49
- 5. Ensure the Docker container remains active, providing a robust environment for your applications.
47
+ 1. Configure Git with GitHub token if provided.
48
+ 2. Clone the specified GitHub repository to your local machine.
49
+ 3. Install **Docker** if it’s not already available on the target machine.
50
+ 4. Install **Docker Compose** for managing multi-container applications.
51
+ 5. Log in to Docker Hub if credentials are provided.
52
+ 6. Create, enable, and start the Docker service.
53
+ 7. Ensure the Docker container remains active, providing a robust environment for your applications.
50
54
 
51
55
  By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
52
56
 
@@ -59,10 +63,12 @@ The **VM Setup Tool** also supports cloud setup for VMs. Use the following examp
59
63
  from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
60
64
 
61
65
  config = SetupRunnerConfig(
62
- github_username='your_github_username', # e.g., username
63
- github_token='your_github_token', # e.g., token
66
+ github_username='your_github_username', # Required if the repository is private, e.g., username
67
+ github_token='your_github_token', # Required if the repository is private, e.g., token
64
68
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
65
- docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
69
+ docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
70
+ dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
71
+ dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
66
72
  )
67
73
 
68
74
  runner = SetupRunner(config)
@@ -87,11 +93,13 @@ runner.run_cloud_setup(ssh_configs)
87
93
  ### **What Happens During Cloud Setup**
88
94
  When you run the cloud setup, the tool will:
89
95
  1. Connect to the specified cloud VM using SSH.
90
- 2. Clone the specified GitHub repository to the VM.
91
- 3. Install **Docker** if it’s not already available on the VM.
92
- 4. Install **Docker Compose** for managing multi-container applications.
93
- 5. Create, enable, and start the Docker service on the VM.
94
- 6. Ensure the Docker container remains active, providing a robust environment for your applications.
96
+ 2. Configure Git with GitHub token if provided.
97
+ 3. Clone the specified GitHub repository to the VM.
98
+ 4. Install **Docker** if it’s not already available on the VM.
99
+ 5. Install **Docker Compose** for managing multi-container applications.
100
+ 6. Log in to Docker Hub if credentials are provided.
101
+ 7. Create, enable, and start the Docker service on the VM.
102
+ 8. Ensure the Docker container remains active, providing a robust environment for your applications.
95
103
 
96
104
  ---
97
105
 
@@ -11,7 +11,7 @@ else:
11
11
 
12
12
  setup(
13
13
  name='vm_tool',
14
- version='1.0.19', # This will be updated by bump2version
14
+ version='1.0.21', # This will be updated by bump2version
15
15
  packages=find_packages(),
16
16
  description='A Comprehensive Tool for Setting Up Virtual Machines.',
17
17
  long_description=long_description,
@@ -2,7 +2,7 @@ import argparse
2
2
 
3
3
  def main():
4
4
  parser = argparse.ArgumentParser(description='Setup VMs using Ansible.')
5
- parser.add_argument('--version', action='version', version='1.0.19')
5
+ parser.add_argument('--version', action='version', version='1.0.21')
6
6
 
7
7
  args = parser.parse_args()
8
8
 
@@ -2,19 +2,45 @@ import sys
2
2
  import ansible_runner
3
3
  import os
4
4
  import yaml
5
- from pydantic import BaseModel, HttpUrl, validator
6
- from typing import List
5
+ from pydantic import BaseModel, validator
6
+ from typing import List, Optional
7
7
 
8
8
  class SetupRunnerConfig(BaseModel):
9
- github_username: str
10
- github_token: str
11
- github_project_url: HttpUrl
9
+ github_username: Optional[str] = None
10
+ github_token: Optional[str] = None
11
+ github_project_url: str
12
12
  docker_compose_file_path: str = 'docker-compose.yml'
13
+ dockerhub_username: Optional[str] = None
14
+ dockerhub_password: Optional[str] = None
13
15
 
14
16
  @validator('docker_compose_file_path', pre=True, always=True)
15
17
  def set_default_docker_compose_file_path(cls, v):
16
18
  return v or 'docker-compose.yml'
17
19
 
20
+ @validator('dockerhub_password', always=True)
21
+ def check_dockerhub_password(cls, v, values):
22
+ if values.get('dockerhub_username') and not v:
23
+ raise ValueError("DockerHub password must be provided if DockerHub username is specified")
24
+ return v
25
+
26
+ @validator('dockerhub_username', always=True)
27
+ def check_dockerhub_username(cls, v, values):
28
+ if values.get('dockerhub_password') and not v:
29
+ raise ValueError("DockerHub username must be provided if DockerHub password is specified")
30
+ return v
31
+
32
+ @validator('github_token', always=True)
33
+ def check_github_token(cls, v, values):
34
+ if values.get('github_username') and not v:
35
+ raise ValueError("GitHub token must be provided if GitHub username is specified")
36
+ return v
37
+
38
+ @validator('github_username', always=True)
39
+ def check_github_username(cls, v, values):
40
+ if values.get('github_token') and not v:
41
+ raise ValueError("GitHub username must be provided if GitHub token is specified")
42
+ return v
43
+
18
44
  class SSHConfig(BaseModel):
19
45
  ssh_username: str
20
46
  ssh_password: str
@@ -26,6 +52,8 @@ class SetupRunner:
26
52
  self.github_token = config.github_token
27
53
  self.github_project_url = config.github_project_url
28
54
  self.docker_compose_file_path = config.docker_compose_file_path
55
+ self.dockerhub_username = config.dockerhub_username
56
+ self.dockerhub_password = config.dockerhub_password
29
57
 
30
58
  def _run_ansible_playbook(self, extravars, inventory_file):
31
59
  # Get the current directory of this script
@@ -38,7 +66,7 @@ class SetupRunner:
38
66
  os.makedirs(venv_dir, exist_ok=True)
39
67
 
40
68
  # Construct dynamic paths
41
- playbook_path = os.path.join(current_dir, 'vm_setup', 'setup.yml')
69
+ playbook_path = os.path.join(current_dir, 'vm_setup', 'main.yml')
42
70
  inventory_path = os.path.join(current_dir, 'vm_setup', inventory_file)
43
71
 
44
72
  try:
@@ -62,6 +90,8 @@ class SetupRunner:
62
90
  'GITHUB_USERNAME': self.github_username,
63
91
  'GITHUB_TOKEN': self.github_token,
64
92
  'GITHUB_PROJECT_URL': self.github_project_url,
93
+ 'DOCKERHUB_USERNAME': self.dockerhub_username,
94
+ 'DOCKERHUB_PASSWORD': self.dockerhub_password,
65
95
  'EXECUTION_TYPE': "normal"
66
96
  }
67
97
 
@@ -74,39 +104,35 @@ class SetupRunner:
74
104
  # Define the path for the dynamic inventory file
75
105
  inventory_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vm_setup', 'dynamic_inventory.yml')
76
106
 
77
- # Check if the dynamic inventory file already exists
78
- if os.path.exists(inventory_file_path):
79
- # Read the existing inventory file
80
- with open(inventory_file_path, 'r') as inventory_file:
81
- inventory_content = yaml.safe_load(inventory_file)
82
- else:
83
- # Create dynamic inventory content
84
- inventory_content = {
85
- 'all': {
86
- 'hosts': {},
87
- 'vars': {
88
- 'ansible_python_interpreter': '/usr/bin/python3'
89
- }
107
+ # Create dynamic inventory content
108
+ inventory_content = {
109
+ 'all': {
110
+ 'hosts': {},
111
+ 'vars': {
112
+ 'ansible_python_interpreter': '/usr/bin/python3'
90
113
  }
91
114
  }
115
+ }
92
116
 
93
- for i, ssh_config in enumerate(ssh_configs):
94
- host_key = f'cloud_host_{i}'
95
- inventory_content['all']['hosts'][host_key] = {
96
- 'ansible_host': ssh_config.ssh_hostname,
97
- 'ansible_user': ssh_config.ssh_username,
98
- 'ansible_ssh_pass': ssh_config.ssh_password
99
- }
117
+ for i, ssh_config in enumerate(ssh_configs):
118
+ host_key = f'cloud_host_{i}'
119
+ inventory_content['all']['hosts'][host_key] = {
120
+ 'ansible_host': ssh_config.ssh_hostname,
121
+ 'ansible_user': ssh_config.ssh_username,
122
+ 'ansible_ssh_pass': ssh_config.ssh_password
123
+ }
100
124
 
101
- # Write dynamic inventory to a file
102
- with open(inventory_file_path, 'w') as inventory_file:
103
- yaml.dump(inventory_content, inventory_file)
125
+ # Write dynamic inventory to a file
126
+ with open(inventory_file_path, 'w') as inventory_file:
127
+ yaml.dump(inventory_content, inventory_file)
104
128
 
105
129
  # Construct extravars dictionary
106
130
  extravars = {
107
131
  'GITHUB_USERNAME': self.github_username,
108
132
  'GITHUB_TOKEN': self.github_token,
109
133
  'GITHUB_PROJECT_URL': self.github_project_url,
134
+ 'DOCKERHUB_USERNAME': self.dockerhub_username,
135
+ 'DOCKERHUB_PASSWORD': self.dockerhub_password,
110
136
  'EXECUTION_TYPE': "cloud"
111
137
  }
112
138
 
@@ -0,0 +1,27 @@
1
+ - name: Cleanup VM
2
+ block:
3
+ - name: Remove GitHub credentials from git-credentials
4
+ file:
5
+ path: ~/.git-credentials
6
+ state: absent
7
+ become: yes
8
+ when: GITHUB_TOKEN is defined
9
+
10
+ - name: Clear Git credential helper configuration
11
+ shell: git config --global --unset credential.helper
12
+ become: yes
13
+ when: GITHUB_TOKEN is defined
14
+
15
+ - name: Unset environment variables
16
+ shell: |
17
+ unset GITHUB_PROJECT_URL
18
+ unset GITHUB_USERNAME
19
+ unset GITHUB_TOKEN
20
+ unset DOCKERHUB_USERNAME
21
+ unset DOCKERHUB_PASSWORD
22
+ environment:
23
+ GITHUB_PROJECT_URL: "{{ GITHUB_PROJECT_URL }}"
24
+ GITHUB_USERNAME: "{{ GITHUB_USERNAME }}"
25
+ GITHUB_TOKEN: "{{ GITHUB_TOKEN }}"
26
+ DOCKERHUB_USERNAME: "{{ DOCKERHUB_USERNAME }}"
27
+ DOCKERHUB_PASSWORD: "{{ DOCKERHUB_PASSWORD }}"
@@ -0,0 +1,7 @@
1
+ - name: Docker Setup Playbook
2
+ block:
3
+ - name: Adding Docker and Compose packages
4
+ include_tasks: docker/install_docker_and_compose.yml
5
+
6
+ - name: Log in to Docker Hub
7
+ include_tasks: docker/login_to_docker_hub.yml
@@ -0,0 +1,6 @@
1
+ - name: Dockerhub Login
2
+ block:
3
+ - name: Log in to Docker Hub
4
+ shell: echo "{{ DOCKERHUB_PASSWORD }}" | docker login --username "{{ DOCKERHUB_USERNAME }}" --password-stdin
5
+ ignore_errors: yes
6
+ become: yes
@@ -0,0 +1,8 @@
1
+ all:
2
+ hosts:
3
+ cloud_host_0:
4
+ ansible_host: 172.105.49.244
5
+ ansible_ssh_pass: Sunny@27072000@
6
+ ansible_user: root
7
+ vars:
8
+ ansible_python_interpreter: /usr/bin/python3
@@ -0,0 +1,22 @@
1
+ - name: Git Configuration Playbook
2
+ block:
3
+ - name: Configure Git with GitHub token
4
+ shell: |
5
+ git config --global credential.helper store
6
+ echo "https://{{ GITHUB_USERNAME }}:{{ GITHUB_TOKEN }}@github.com" > ~/.git-credentials
7
+ become: yes
8
+ when: GITHUB_TOKEN is defined and GITHUB_USERNAME is defined
9
+
10
+ - name: Remove existing Project repository if present
11
+ file:
12
+ path: "{{ project_dest_dir }}"
13
+ state: absent
14
+ force: yes
15
+ become: yes
16
+
17
+ - name: Clone the Project repository
18
+ git:
19
+ repo: "{{ GITHUB_PROJECT_URL }}"
20
+ dest: "{{ project_dest_dir }}"
21
+ version: main
22
+ become: yes
@@ -0,0 +1,22 @@
1
+ - name: Main Playbook
2
+ hosts: all
3
+ gather_facts: yes
4
+
5
+ vars:
6
+ static_playbook_dir: "{{ playbook_dir }}"
7
+
8
+ tasks:
9
+ - name: Setup
10
+ include_tasks: setup.yml
11
+
12
+ - name: Git Configuration
13
+ include_tasks: github/git_configuration.yml
14
+
15
+ - name: Docker Setup
16
+ include_tasks: docker/docker_setup.yml
17
+
18
+ - name: Project Service
19
+ include_tasks: project_service.yml
20
+
21
+ - name: Cleanup
22
+ include_tasks: cleanup.yml
@@ -0,0 +1,16 @@
1
+ - name: Project Service Playbook
2
+ block:
3
+ - name: Set service_file_path variable
4
+ set_fact:
5
+ service_file_path: /etc/systemd/system/project.service
6
+
7
+ - name: Create Docker Service
8
+ include_tasks: docker/create_docker_service.yml
9
+
10
+ - name: Enable and start project service
11
+ ansible.builtin.systemd:
12
+ name: project
13
+ state: started
14
+ enabled: yes
15
+ become: yes
16
+ ignore_errors: yes
@@ -0,0 +1,5 @@
1
+ - name: Setup VM
2
+ block:
3
+ - name: Set project_dest_dir variable
4
+ set_fact:
5
+ project_dest_dir: "{{ static_playbook_dir }}/project"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: vm_tool
3
- Version: 1.0.19
3
+ Version: 1.0.21
4
4
  Summary: A Comprehensive Tool for Setting Up Virtual Machines.
5
5
  Home-page: https://github.com/thesunnysinha/vm_tool
6
6
  Author: Sunny Sinha
@@ -83,10 +83,12 @@ Use the following example to configure and run the VM setup:
83
83
  from vm_tool.runner import SetupRunner, SetupRunnerConfig
84
84
 
85
85
  config = SetupRunnerConfig(
86
- github_username='your_github_username', # e.g., username
87
- github_token='your_github_token', # e.g., token
86
+ github_username='your_github_username', # Required if the repository is private, e.g., username
87
+ github_token='your_github_token', # Required if the repository is private, e.g., token
88
88
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
89
- docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
89
+ docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
90
+ dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
91
+ dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
90
92
  )
91
93
 
92
94
  runner = SetupRunner(config)
@@ -96,11 +98,13 @@ runner.run_setup()
96
98
 
97
99
  ### **What Happens During Setup**
98
100
  The VM Setup Tool will:
99
- 1. Clone the specified GitHub repository to your local machine.
100
- 2. Install **Docker** if it’s not already available on the target machine.
101
- 3. Install **Docker Compose** for managing multi-container applications.
102
- 4. Create, enable, and start the Docker service.
103
- 5. Ensure the Docker container remains active, providing a robust environment for your applications.
101
+ 1. Configure Git with GitHub token if provided.
102
+ 2. Clone the specified GitHub repository to your local machine.
103
+ 3. Install **Docker** if it’s not already available on the target machine.
104
+ 4. Install **Docker Compose** for managing multi-container applications.
105
+ 5. Log in to Docker Hub if credentials are provided.
106
+ 6. Create, enable, and start the Docker service.
107
+ 7. Ensure the Docker container remains active, providing a robust environment for your applications.
104
108
 
105
109
  By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
106
110
 
@@ -113,10 +117,12 @@ The **VM Setup Tool** also supports cloud setup for VMs. Use the following examp
113
117
  from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
114
118
 
115
119
  config = SetupRunnerConfig(
116
- github_username='your_github_username', # e.g., username
117
- github_token='your_github_token', # e.g., token
120
+ github_username='your_github_username', # Required if the repository is private, e.g., username
121
+ github_token='your_github_token', # Required if the repository is private, e.g., token
118
122
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
119
- docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
123
+ docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
124
+ dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
125
+ dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
120
126
  )
121
127
 
122
128
  runner = SetupRunner(config)
@@ -141,11 +147,13 @@ runner.run_cloud_setup(ssh_configs)
141
147
  ### **What Happens During Cloud Setup**
142
148
  When you run the cloud setup, the tool will:
143
149
  1. Connect to the specified cloud VM using SSH.
144
- 2. Clone the specified GitHub repository to the VM.
145
- 3. Install **Docker** if it’s not already available on the VM.
146
- 4. Install **Docker Compose** for managing multi-container applications.
147
- 5. Create, enable, and start the Docker service on the VM.
148
- 6. Ensure the Docker container remains active, providing a robust environment for your applications.
150
+ 2. Configure Git with GitHub token if provided.
151
+ 3. Clone the specified GitHub repository to the VM.
152
+ 4. Install **Docker** if it’s not already available on the VM.
153
+ 5. Install **Docker Compose** for managing multi-container applications.
154
+ 6. Log in to Docker Hub if credentials are provided.
155
+ 7. Create, enable, and start the Docker service on the VM.
156
+ 8. Ensure the Docker container remains active, providing a robust environment for your applications.
149
157
 
150
158
  ---
151
159
 
@@ -12,8 +12,14 @@ vm_tool.egg-info/dependency_links.txt
12
12
  vm_tool.egg-info/entry_points.txt
13
13
  vm_tool.egg-info/requires.txt
14
14
  vm_tool.egg-info/top_level.txt
15
+ vm_tool/vm_setup/cleanup.yml
15
16
  vm_tool/vm_setup/dynamic_inventory.yml
16
17
  vm_tool/vm_setup/inventory.yml
18
+ vm_tool/vm_setup/main.yml
19
+ vm_tool/vm_setup/project_service.yml
17
20
  vm_tool/vm_setup/setup.yml
18
21
  vm_tool/vm_setup/docker/create_docker_service.yml
19
- vm_tool/vm_setup/docker/install_docker_and_compose.yml
22
+ vm_tool/vm_setup/docker/docker_setup.yml
23
+ vm_tool/vm_setup/docker/install_docker_and_compose.yml
24
+ vm_tool/vm_setup/docker/login_to_docker_hub.yml
25
+ vm_tool/vm_setup/github/git_configuration.yml
File without changes
@@ -1,81 +0,0 @@
1
- - name: Setup Docker and Docker Compose on Ubuntu
2
- hosts: all
3
- gather_facts: yes
4
-
5
- vars:
6
- static_playbook_dir: "{{ playbook_dir }}"
7
-
8
- tasks:
9
- - name: Gather package facts
10
- package_facts:
11
- manager: auto
12
-
13
- - name: Install sshpass if execution type is cloud and not already installed
14
- apt:
15
- name: sshpass
16
- state: present
17
- when: EXECUTION_TYPE == "cloud" and "'sshpass' not in ansible_facts.packages"
18
- become: yes
19
-
20
- - name: Set project_dest_dir variable
21
- set_fact:
22
- project_dest_dir: "{{ static_playbook_dir }}/project"
23
-
24
- - name: Configure Git with GitHub token
25
- shell: |
26
- git config --global credential.helper store
27
- echo "https://{{ GITHUB_USERNAME }}:{{ GITHUB_TOKEN }}@github.com" > ~/.git-credentials
28
- become: yes
29
-
30
- - name: Remove existing Project repository if present
31
- file:
32
- path: "{{ project_dest_dir }}"
33
- state: absent
34
- force: yes
35
- become: yes
36
-
37
- - name: Clone the Project repository
38
- git:
39
- repo: "{{ GITHUB_PROJECT_URL }}"
40
- dest: "{{ project_dest_dir }}"
41
- version: main
42
- become: yes
43
-
44
- - name: Set service_file_path variable
45
- set_fact:
46
- service_file_path: /etc/systemd/system/project.service
47
-
48
- - name: Adding Docker and Compose packages
49
- include_tasks: docker/install_docker_and_compose.yml
50
-
51
- - name: Create Docker Service
52
- include_tasks: docker/create_docker_service.yml
53
-
54
- - name: Enable and start project service
55
- ansible.builtin.systemd:
56
- name: project
57
- state: started
58
- enabled: yes
59
- become: yes
60
- ignore_errors: yes
61
-
62
- # Cleanup section
63
- - name: Remove GitHub credentials from git-credentials
64
- file:
65
- path: ~/.git-credentials
66
- state: absent
67
- become: yes
68
-
69
- - name: Clear Git credential helper configuration
70
- shell: git config --global --unset credential.helper
71
- become: yes
72
-
73
- - name: Unset environment variables
74
- shell: |
75
- unset GITHUB_PROJECT_URL
76
- unset GITHUB_USERNAME
77
- unset GITHUB_TOKEN
78
- environment:
79
- GITHUB_PROJECT_URL: "{{ GITHUB_PROJECT_URL }}"
80
- GITHUB_USERNAME: "{{ GITHUB_USERNAME }}"
81
- GITHUB_TOKEN: "{{ GITHUB_TOKEN }}"
File without changes
File without changes
File without changes
File without changes
File without changes