Skip to content

Commit

Permalink
Merge pull request entanet-devops#4 from entanet-devops/PLAT-4359
Browse files Browse the repository at this point in the history
Plat 4359
  • Loading branch information
dBrittainEntanet authored Aug 31, 2023
2 parents 67fd216 + c6c7856 commit 59ce2ae
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 95 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.idea/

.DS_Store
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ npm_install: true
delete_env_after_test: true

bitbucket_consumer_key: ""
bitbucket_consumer_secret: ""
bitbucket_consumer_secret: ""

minimum_laravel_version: "5.0.0"
minimum_craftcms_version: "3.0.0"
31 changes: 31 additions & 0 deletions tasks/craftcms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- name: Print Craft CMS framework version
debug:
var: fact_craftcms_version
verbosity: 1

- name: Check for outdated Craft CMS framework
debug:
msg: Craft CMS version ({{ fact_craftcms_version }}) is too old to deploy. Please update framework to v{{ minimum_craftcms_version }} or request a Platform override.
verbosity: 0
when: fact_craftcms_version | regex_search('\d+[.]?\d*[.]?\d*') is not version(minimum_craftcms_version, '>=', strict=true)

- include_tasks: platform-override.yml
when: fact_craftcms_version | regex_search('\d+[.]?\d*[.]?\d*') is not version(minimum_craftcms_version, '>=', strict=true)

- name: Check for codeception.yml
stat:
path: "{{ app_directory }}/codeception.yml"
register: codeception_conf
failed_when: not codeception_conf.stat.exists

- name: Check for testing .env
stat:
path: "{{ app_directory }}/tests/.env"
register: codeception_env
failed_when: not codeception_env.stat.exists

- name: Install mysql-client
apt:
name: mysql-client
state: present
install_recommends: no
20 changes: 20 additions & 0 deletions tasks/laravel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- name: Print Laravel framework version
debug:
var: fact_laravel_version
verbosity: 1

- name: Check for outdated Laravel framework
debug:
msg: Laravel version ({{ fact_laravel_version }}) is too old to deploy. Please update laravel framework to v{{ minimum_laravel_version }} or request a Platform override.
verbosity: 0
when: fact_laravel_version | regex_search('\d+[.]?\d*[.]?\d*') is not version(minimum_laravel_version, '>=', strict=true)

- include_tasks: platform-override.yml
when: fact_laravel_version | regex_search('\d+[.]?\d*[.]?\d*') is not version(minimum_laravel_version, '>=', strict=true)

- name: Check for .env.testing
stat:
path: "{{ app_directory }}/.env.testing"
register: testing_env
failed_when: not testing_env.stat.exists

150 changes: 85 additions & 65 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- name: Install ACL package
apt:
name: acl
state: present

- name: Install application.
apt:
deb: "{{ app_deb_package }}"
Expand All @@ -8,76 +13,91 @@
comment: App user
system: yes

- name: Chown Apps directory
file:
dest: "{{ app_directory }}"
owner: "{{ app_user }}"
group: "{{ app_group }}"
recurse: yes

- name: Chown npm cache directory
file:
path: /var/www/
state: directory
recurse: yes
owner: "{{ app_user }}"
group: "{{ app_group }}"
mode: '0755'

- name: Check if composer.json exists
stat:
path: "{{ app_directory }}/composer.json"
register: run_composer

- include: env.yml

- name: Set bitbucket auth for private composer packages.
shell: "composer config --global --auth bitbucket-oauth.bitbucket.org {{ bitbucket_consumer_key }} {{ bitbucket_consumer_secret }}"
when:
- bitbucket_consumer_key != ""
- bitbucket_consumer_secret != ""
- run_composer.stat.exists

- name: Composer Install.
composer:
command: install
no_dev: no
working_dir: "{{ app_directory }}"
environment:
COMPOSER_ALLOW_SUPERUSER: "1"
when: run_composer.stat.exists

- name: Check if npm package.json exists
stat:
path: "{{ app_directory }}/package.json"
register: run_npm

- name: npm install
command: "npm install --unsafe-perm"
args:
chdir: "{{ app_directory }}"
when: npm_install and run_npm.stat.exists

- name: npm run prod
command: "npm run prod"
args:
chdir: "{{ app_directory }}"
when: npm_install and run_npm.stat.exists

- include: testing.yml
- include: behat.yml

- name: Composer install to remove dev dependecies.
composer:
command: install
working_dir: "{{ app_directory }}"
environment:
COMPOSER_ALLOW_SUPERUSER: "1"
when: run_composer.stat.exists

- include: env.yml

- name: Key Generate.
shell: 'php artisan key:generate'
args:
chdir: "{{ app_directory }}"
when: laravel_app and app_env.APP_KEY is not defined
- name: Validate PHP framework
include_tasks: validation.yml

- name: Chown Apps directory
file:
dest: "{{ app_directory }}"
owner: "{{ app_user }}"
group: "{{ app_group }}"
recurse: yes
- become: true
become_user: "{{ app_user }}"
block:
- name: Set bitbucket auth for private composer packages.
shell: "composer config --global --auth bitbucket-oauth.bitbucket.org {{ bitbucket_consumer_key }} {{ bitbucket_consumer_secret }}"
when:
- bitbucket_consumer_key != ""
- bitbucket_consumer_secret != ""
- run_composer.stat.exists

- name: Composer Install.
composer:
command: install
no_dev: no
working_dir: "{{ app_directory }}"
when: run_composer.stat.exists

- include: testing.yml

- name: Check if npm package.json exists
stat:
path: "{{ app_directory }}/package.json"
register: run_npm

- name: npm install
command: "npm install"
args:
chdir: "{{ app_directory }}"
when: npm_install and run_npm.stat.exists

- name: npm run prod
command: "npm run prod"
args:
chdir: "{{ app_directory }}"
when: npm_install and run_npm.stat.exists

- include: behat.yml

- name: Composer install to remove dev dependecies.
composer:
command: install
working_dir: "{{ app_directory }}"
when: run_composer.stat.exists

- include: env.yml

- name: Craft Security Key Generate.
shell: 'php craft setup/security-key'
args:
chdir: "{{ app_directory }}"
when: fact_craftcms_version | length > 0 and app_env.APP_KEY is not defined

- name: Configure laravel cronjob
cron:
name: Laravel Cron
user: "{{ app_user }}"
job: "cd {{ app_directory }} && php artisan schedule:run >> /dev/null 2>&1"
when: laravel_app
- name: Artisan Key Generate.
shell: 'php artisan key:generate'
args:
chdir: "{{ app_directory }}"
when: fact_laravel_version | length > 0 and app_env.APP_KEY is not defined

- name: Configure laravel cronjob
cron:
name: Laravel Cron
user: "{{ app_user }}"
job: "cd {{ app_directory }} && php artisan schedule:run >> /dev/null 2>&1"
when: fact_laravel_version | length > 0
12 changes: 12 additions & 0 deletions tasks/platform-override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Awaiting Platform override...
wait_for:
path: /tmp/platform
search_regex: ok
state: present
timeout: 3600
msg: Platform override timeout.

- name: Platform override post actions
file:
path: /tmp/platform
state: absent
40 changes: 11 additions & 29 deletions tasks/testing.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
- name: Check testing env
stat:
path: "{{ app_directory }}/.env.testing"
register: run_tests

- name: Check testing directory
stat:
path: "{{ app_directory }}/tests"
register: has_tests

- name: Run PHPUnit tests.
block:
- name: Copy testing env file
copy:
src: "{{ app_directory }}/.env.testing"
dest: "{{ app_directory }}/.env"

- name: Exec PHPUnit
shell: './vendor/bin/phpunit'
args:
chdir: "{{ app_directory }}"
when: run_tests.stat.exists

- name: Remove testing env.
file:
path: "{{ app_directory }}/.env"
state: absent
when: delete_env_after_test
when: run_tests.stat.exists and has_tests.stat.exists
- name: Run PHPUnit
shell: './vendor/bin/phpunit'
args:
chdir: "{{ app_directory }}"
when: fact_laravel_version | length > 0

- name: Run Codeception
shell: './vendor/bin/codecept run Unit'
args:
chdir: "{{ app_directory }}"
when: fact_craftcms_version | length > 0
32 changes: 32 additions & 0 deletions tasks/validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- name: Load composer file
shell: "cat {{ app_directory }}/composer.json"
register: composer

- name: Save composer output
set_fact:
jsondata: "{{ composer.stdout | from_json }}"

- name: Check for Laravel framework
set_fact:
fact_laravel_version: "{{ jsondata | json_query(jmesquery) }}"
vars:
jmesquery: 'require."laravel/framework"'

- name: Check for Craft CMS framework
set_fact:
fact_craftcms_version: "{{ jsondata | json_query(jmesquery) }}"
vars:
jmesquery: 'require."craftcms/cms"'

- name: Check for unknown framework
fail:
msg: Could not recognise PHP framework.
when: fact_laravel_version | length == 0 and fact_craftcms_version | length == 0

- name: Include Laravel tasks
include_tasks: laravel.yml
when: fact_laravel_version | length > 0

- name: Include Craft CMS tasks
include_tasks: craftcms.yml
when: fact_craftcms_version | length > 0

0 comments on commit 59ce2ae

Please sign in to comment.