commit 444a0e00415d9e67b9ce217c8c28c94a61b0ef9d Author: tsousa111 Date: Sun Oct 29 16:34:24 2023 +0000 init repo diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d623d7 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# GrupoTP-37 diff --git a/codebase/.DS_Store b/codebase/.DS_Store new file mode 100644 index 0000000..b2fba77 Binary files /dev/null and b/codebase/.DS_Store differ diff --git a/codebase/docker/Dockerfile b/codebase/docker/Dockerfile new file mode 100644 index 0000000..6613d7a --- /dev/null +++ b/codebase/docker/Dockerfile @@ -0,0 +1,2 @@ +# Dockerfile for the laravel.io application +# TO DO \ No newline at end of file diff --git a/codebase/gke-cluster-create.yml b/codebase/gke-cluster-create.yml new file mode 100644 index 0000000..cc5eea5 --- /dev/null +++ b/codebase/gke-cluster-create.yml @@ -0,0 +1,7 @@ +# DO NOT CHANGE! +--- +- name: Create a GKE cluster + hosts: localhost + gather_facts: false + roles: + - gke_cluster_create \ No newline at end of file diff --git a/codebase/gke-cluster-destroy.yml b/codebase/gke-cluster-destroy.yml new file mode 100644 index 0000000..a3608a0 --- /dev/null +++ b/codebase/gke-cluster-destroy.yml @@ -0,0 +1,7 @@ +# DO NOT CHANGE! +--- +- name: Destroy GKE cluster + hosts: localhost + gather_facts: false + roles: + - gke_cluster_destroy \ No newline at end of file diff --git a/codebase/inventory/gcp.yml b/codebase/inventory/gcp.yml new file mode 100644 index 0000000..28c10e4 --- /dev/null +++ b/codebase/inventory/gcp.yml @@ -0,0 +1,23 @@ +--- +all: + vars: + + # GKE cluster variables + gcp_project: # ID of GCP Project + gcp_auth_kind: serviceaccount # Do not change + gcp_cred_file: # Path to service account keys (json file downloaded from GCP) + + gcp_zone: us-central1-a + gcp_image_type: ubuntu_containerd + gcp_machine_type: e2-small # Can be changed if necessary + gcp_disk_size_gb: 100 # Can be changed if necessary + gcp_initial_node_count: 2 # Number of nodes to create. Can be changed if necessary + + + # APP variables + app_ip: # Needs to be updated + app_port: # Needs to be updated + + + # Additional variables + # ... \ No newline at end of file diff --git a/codebase/laravelio-deploy.yml b/codebase/laravelio-deploy.yml new file mode 100644 index 0000000..2aa6972 --- /dev/null +++ b/codebase/laravelio-deploy.yml @@ -0,0 +1,3 @@ +--- +# Playbook to deploy laravel.io and its components +# TO DO diff --git a/codebase/laravelio-undeploy.yml b/codebase/laravelio-undeploy.yml new file mode 100644 index 0000000..996dd9e --- /dev/null +++ b/codebase/laravelio-undeploy.yml @@ -0,0 +1,3 @@ +--- +# Playbook to undeploy laravel.io and its component +# TO DO \ No newline at end of file diff --git a/codebase/roles/.DS_Store b/codebase/roles/.DS_Store new file mode 100644 index 0000000..fcc31b9 Binary files /dev/null and b/codebase/roles/.DS_Store differ diff --git a/codebase/roles/gke_cluster_create/tasks/main.yml b/codebase/roles/gke_cluster_create/tasks/main.yml new file mode 100644 index 0000000..83940d4 --- /dev/null +++ b/codebase/roles/gke_cluster_create/tasks/main.yml @@ -0,0 +1,47 @@ +# DO NOT CHANGE! +--- + +- name: Create Google Kubernetes Engine Cluster + gcp_container_cluster: + name: ascn-cluster + initial_node_count: "{{ gcp_initial_node_count }}" + node_config: + machine_type: "{{ gcp_machine_type }}" + disk_size_gb: "{{ gcp_disk_size_gb }}" + image_type: "{{ gcp_image_type }}" + location: "{{ gcp_zone }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_auth_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present + register: cluster + until: "cluster is not failed" + delay: 60 + retries: 3 + +- name: Verify that the cluster was created + shell: gcloud container clusters describe --project="{{ gcp_project}}" --zone="{{ gcp_zone }}" ascn-cluster + register: results + +- name: Verify that the command succeeded + assert: + that: + - results.rc == 0 + +- name: Create a node pool + gcp_container_node_pool: + name: default-pool + initial_node_count: "{{ gcp_initial_node_count }}" + cluster: "{{ cluster }}" + config: + machine_type: "{{ gcp_machine_type }}" + image_type: "{{ gcp_image_type }}" + disk_size_gb: "{{ gcp_disk_size_gb }}" + location: "{{ gcp_zone }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_auth_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: present + +- name: Connect to the cluster (update kubeconfig)" + shell: gcloud container clusters get-credentials --project="{{ gcp_project}}" --zone="{{ gcp_zone }}" ascn-cluster diff --git a/codebase/roles/gke_cluster_destroy/tasks/main.yml b/codebase/roles/gke_cluster_destroy/tasks/main.yml new file mode 100644 index 0000000..0bdb44f --- /dev/null +++ b/codebase/roles/gke_cluster_destroy/tasks/main.yml @@ -0,0 +1,31 @@ +# DO NOT CHANGE! +--- + +- name: Destroy Google Kubernetes Engine Cluster + gcp_container_cluster: + name: ascn-cluster + location: "{{ gcp_zone }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_auth_kind }}" + service_account_file: "{{ gcp_cred_file }}" + state: absent + register: cluster + until: "cluster is not failed" + delay: 60 + retries: 3 + +- name: Verify that the cluster was deleted + gcp_container_cluster_info: + location: "{{ gcp_zone }}" + project: "{{ gcp_project }}" + auth_kind: "{{ gcp_auth_kind }}" + service_account_file: "{{ gcp_cred_file }}" + scopes: + - https://www.googleapis.com/auth/cloud-platform + register: results + +- name: Verify that the command succeeded + assert: + that: + - '''ascn-cluster'' not in "{{ results[''resources''] | map(attribute=''name'') + | list }}"' \ No newline at end of file diff --git a/codebase/roles/test_laravelio/tasks/main.yml b/codebase/roles/test_laravelio/tasks/main.yml new file mode 100644 index 0000000..097aceb --- /dev/null +++ b/codebase/roles/test_laravelio/tasks/main.yml @@ -0,0 +1,14 @@ +--- + +- name: Refresh inventory + meta: refresh_inventory + +- name: Check that you can connect (GET) to App and it returns a status 200 + ansible.builtin.uri: + url: "http://{{ app_ip }}:{{app_port}}/" + method: GET + status_code: 200 + register: result + until: result.status == 200 + retries: 3 + delay: 5 \ No newline at end of file diff --git a/codebase/test-all.yml b/codebase/test-all.yml new file mode 100644 index 0000000..55b8b87 --- /dev/null +++ b/codebase/test-all.yml @@ -0,0 +1,22 @@ +--- +# Playbook to test the full deployment of laravel.io (from creation to destruction) + +- import_playbook: laravelio-deploy.yml + +- name: Tests + hosts: localhost + gather_facts: true + roles: + - { role: test_app } + +- import_playbook: laravelio-undeploy.yml + +- import_playbook: laravelio-deploy.yml + +- name: Tests + hosts: localhost + gather_facts: yes + roles: + - { role: test_app } + +- import_playbook: laravelio-undeploy.yml delete_data='true' \ No newline at end of file