Compare commits
No commits in common. "c532d498c4ea0bf9d0dce78fd725f38a501c5c14" and "ce3ea0583196c65041be3475eaa78ae34dd0b748" have entirely different histories.
c532d498c4
...
ce3ea05831
14 changed files with 25 additions and 307 deletions
|
@ -16,7 +16,7 @@ all:
|
|||
|
||||
# APP variables
|
||||
app_ip: <APP_SERVICE_IP> # Needs to be updated
|
||||
app_port: 30000 # Needs to be updated
|
||||
app_port: <APP_PORT> # Needs to be updated
|
||||
|
||||
|
||||
# Additional variables
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
---
|
||||
- name: Deploy Laravelio
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
roles:
|
||||
- mysql_deploy
|
||||
- laravelio_deploy
|
||||
- post_deploy
|
||||
# need to add pre_deploy to pip install kubernetes
|
||||
# Playbook to deploy laravel.io and its components
|
||||
# TO DO
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
---
|
||||
- name: Get MySQL Service Info
|
||||
kubernetes.core.k8s_info:
|
||||
api_version: v1
|
||||
kind: Service
|
||||
name: mysql-service
|
||||
namespace: default
|
||||
register: service_info
|
||||
|
||||
- name: Extract ClusterIP from MySQL service
|
||||
set_fact:
|
||||
cluster_ip: "{{ service_info.resources[0].spec.clusterIP }}"
|
||||
|
||||
- name: Print ClusterIP
|
||||
debug:
|
||||
var: cluster_ip
|
||||
- name: Create ConfigMap for laravelio
|
||||
kubernetes.core.k8s:
|
||||
name: laravelio-config
|
||||
namespace: default
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: laravelio-config
|
||||
data:
|
||||
DB_HOST: "{{ cluster_ip }}"
|
||||
DB_DATABASE: laravelio
|
||||
DB_USERNAME: laraveliouser
|
||||
DB_PASSWORD: "123456"
|
||||
|
||||
- name: Create laravelio Deployment
|
||||
kubernetes.core.k8s:
|
||||
namespace: default
|
||||
state: present
|
||||
src: roles/laravelio_deploy/templates/laravelio-deployment.yml
|
||||
|
||||
- name: Create laravelio Service
|
||||
kubernetes.core.k8s:
|
||||
namespace: default
|
||||
state: present
|
||||
src: roles/laravelio_deploy/templates/laravelio-service.yml
|
||||
wait: yes
|
||||
|
||||
- name: Seed database
|
||||
kubernetes.core.k8s_exec:
|
||||
namespace: default
|
||||
pod: laravelio
|
||||
command: "php artisan db:seed"
|
||||
when: seed_database is defined and seed_database == "true"
|
|
@ -1,29 +0,0 @@
|
|||
---
|
||||
# Deployment for Laravelio
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: laravelio-deployment
|
||||
labels:
|
||||
app: laravelio
|
||||
tier: app
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: laravelio
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: laravelio
|
||||
tier: app
|
||||
spec:
|
||||
containers:
|
||||
- name: laravelio
|
||||
image: crispyjeasus/laravelio:latest
|
||||
envFrom: # The variables below could be set on a ConfigMap object
|
||||
- configMapRef:
|
||||
name: laravelio-config
|
||||
ports:
|
||||
- containerPort: 8000
|
|
@ -1,16 +0,0 @@
|
|||
---
|
||||
# Service for exposing Laravel
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: laravelio-service # logical name of the service, which will also become the DNS name of the service when it is created.
|
||||
labels:
|
||||
app: laravelio
|
||||
tier: app
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: laravelio
|
||||
ports:
|
||||
- port: 30000
|
||||
targetPort: 8000
|
|
@ -1,19 +0,0 @@
|
|||
---
|
||||
- name: Create MySQL Persistent Volume Claim
|
||||
kubernetes.core.k8s:
|
||||
namespace: default
|
||||
state: present
|
||||
src: roles/mysql_deploy/templates/mysql-pvc.yml
|
||||
|
||||
- name: Create MySQL Deployment
|
||||
kubernetes.core.k8s:
|
||||
namespace: default
|
||||
state: present
|
||||
src: roles/mysql_deploy/templates/mysql-deployment.yml
|
||||
|
||||
- name: Create MySQL Service
|
||||
kubernetes.core.k8s:
|
||||
namespace: default
|
||||
state: present
|
||||
src: roles/mysql_deploy/templates/mysql-service.yml
|
||||
wait: yes
|
|
@ -1,42 +0,0 @@
|
|||
---
|
||||
# Deployment for MySQL
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mysql-deployment
|
||||
labels:
|
||||
app: mysql
|
||||
tier: database
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mysql
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mysql
|
||||
tier: database
|
||||
spec:
|
||||
containers:
|
||||
- name: mysql
|
||||
image: mysql:latest
|
||||
env: # The variables below could be set on a ConfigMap object
|
||||
- name: MYSQL_ALLOW_EMPTY_PASSWORD
|
||||
value: "true"
|
||||
- name: MYSQL_DATABASE
|
||||
value: laravelio
|
||||
- name: MYSQL_USER
|
||||
value: laraveliouser
|
||||
- name: MYSQL_PASSWORD
|
||||
value: "123456" # Use Secret object in real usage
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
volumeMounts:
|
||||
- name: mysql-persistent-storage
|
||||
mountPath: /var/lib/mysql
|
||||
volumes:
|
||||
- name: mysql-persistent-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: mysql-pv-claim
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
# Persistent Volume Claim for MySQL pod
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mysql-pv-claim
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
storageClassName: local-storage
|
||||
resources:
|
||||
requests:
|
||||
storage: 20Gi
|
|
@ -1,16 +0,0 @@
|
|||
---
|
||||
# Service for exposing MySQL
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mysql-service # logical name of the service, which will also become the DNS name of the service when it is created.
|
||||
labels:
|
||||
app: mysql
|
||||
tier: database
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mysql
|
||||
ports:
|
||||
- targetPort: 3306 # port that containers are listening on
|
||||
port: 3306 # port number exposed internally in the cluster
|
|
@ -1,26 +0,0 @@
|
|||
---
|
||||
- name: Get laravelio Service Info
|
||||
kubernetes.core.k8s_info:
|
||||
api_version: v1
|
||||
kind: Service
|
||||
namespace: default
|
||||
label_selectors:
|
||||
- "app=laravelio"
|
||||
register: service_info
|
||||
until: service_facts.resources[0].status.loadBalancer.ingress[0].ip is defined
|
||||
retries: 60
|
||||
delay: 10
|
||||
|
||||
- name: Store app_ip
|
||||
set_fact:
|
||||
app_ip: "{{ service_facts.resources[0].status.loadBalancer.ingress[0].ip }}"
|
||||
|
||||
- name: Update app_ip in Inventory
|
||||
lineinfile:
|
||||
path: inventory/gcp.yml
|
||||
regexp: '^ app_ip: (.*)$'
|
||||
line: ' app_ip: {{ app_ip }}'
|
||||
backrefs: yes
|
||||
|
||||
- name: Refresh Inventory
|
||||
meta: refresh_inventory
|
14
roles/test_laravelio/tasks/main.yml
Normal file
14
roles/test_laravelio/tasks/main.yml
Normal file
|
@ -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
|
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
|
||||
- name: Refresh inventory
|
||||
meta: refresh_inventory
|
||||
|
||||
- name: Test Access - Check access to App (HTTP GET should return {{app_status_code}})
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ app_ip }}:{{app_port}}/"
|
||||
method: GET
|
||||
status_code: "{{app_status_code}}"
|
||||
register: result
|
||||
until: result.status == app_status_code
|
||||
retries: 6
|
||||
delay: 30
|
|
@ -1,53 +0,0 @@
|
|||
---
|
||||
|
||||
- name: Refresh inventory
|
||||
meta: refresh_inventory
|
||||
|
||||
- name: Test Login - Get Login page (HTTP GET should return 200)
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ app_ip }}:{{app_port}}/login"
|
||||
method: GET
|
||||
status_code: 200
|
||||
timeout: 300
|
||||
dest: /tmp/index.html
|
||||
register: result
|
||||
|
||||
- name: Test Login - Extract CSRF token
|
||||
shell: cat /tmp/index.html | grep "csrf-token" | sed "s/.* content=\"\(.*\)\".*/\1/"
|
||||
register: parse_res
|
||||
|
||||
- set_fact:
|
||||
token: "{{parse_res.stdout_lines[0]}}"
|
||||
|
||||
- name: Test Login - Login as testing user (HTTP POST should return 302)
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ app_ip }}:{{app_port}}/login"
|
||||
method: POST
|
||||
body:
|
||||
username: "testing"
|
||||
password: "password"
|
||||
_token: "{{token}}"
|
||||
body_format: json
|
||||
return_content: true
|
||||
dest: /tmp/login.html
|
||||
status_code: 302
|
||||
timeout: 300
|
||||
headers:
|
||||
Cookie: "{{ result.cookies_string }}"
|
||||
Cache-Control: no-cache
|
||||
Content-Type: 'application/json; charset=UTF-8'
|
||||
validate_certs: false
|
||||
register: login
|
||||
|
||||
- name: Test Login - Get User page (HTTP GET should return 200)
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ app_ip }}:{{app_port}}/user"
|
||||
method: GET
|
||||
status_code: 200
|
||||
follow_redirects: true
|
||||
dest: /tmp/index.html
|
||||
headers:
|
||||
Cookie: "{{ login.set_cookie }}"
|
||||
register: user_page
|
||||
|
||||
|
28
test-all.yml
28
test-all.yml
|
@ -1,34 +1,22 @@
|
|||
---
|
||||
|
||||
# Checkpoint #2
|
||||
# Playbook to test the full deployment of laravel.io (from creation to destruction)
|
||||
|
||||
- import_playbook: laravelio-deploy.yml
|
||||
vars:
|
||||
seed_database: 'true'
|
||||
tags: ['test1']
|
||||
|
||||
- name: Tests
|
||||
hosts: localhost
|
||||
gather_facts: true
|
||||
roles:
|
||||
- { role: test_laravelio/test_access, app_status_code: 200 }
|
||||
tags: ['test2']
|
||||
|
||||
- name: Tests
|
||||
hosts: localhost
|
||||
gather_facts: true
|
||||
roles:
|
||||
- { role: test_laravelio/test_login }
|
||||
tags: ['test3']
|
||||
- { role: test_app }
|
||||
|
||||
- import_playbook: laravelio-undeploy.yml
|
||||
vars:
|
||||
delete_data: 'true'
|
||||
tags: ['test4']
|
||||
|
||||
- import_playbook: laravelio-deploy.yml
|
||||
|
||||
- name: Tests
|
||||
hosts: localhost
|
||||
gather_facts: true
|
||||
gather_facts: yes
|
||||
roles:
|
||||
- { role: test_laravelio/test_access, app_status_code: -1 }
|
||||
tags: ['test5']
|
||||
- { role: test_app }
|
||||
|
||||
- import_playbook: laravelio-undeploy.yml delete_data='true'
|
Loading…
Reference in a new issue