Skip to content

Commit

Permalink
Add in recipes + tests (#1)
Browse files Browse the repository at this point in the history
* Add in recipes + tests

* Adjust tests

* Adjust tests

* Adjust tests

* Adjust tests
  • Loading branch information
John Ouellet authored Jan 10, 2022
1 parent 9f96d51 commit 37a1f66
Show file tree
Hide file tree
Showing 8 changed files with 447 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/pr-laravel-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Laravel Tests

on:
pull_request:

jobs:
leia-tests:
runs-on: ${{ matrix.os }}
env:
TERM: xterm
strategy:
matrix:
leia-tests:
- examples/laravel
lando-versions:
- edge
os:
- ubuntu-20.04
node-version:
- '14'
steps:
# Install deps and cache
# Eventually it would be great if these steps could live in a separate YAML file
# that could be included in line to avoid code duplication
- name: Checkout code
uses: actions/checkout@v2
- name: Install node ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Get Yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Use Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-v2-${{ hashFiles('**/yarn.lock') }}
- name: Install Yarn dependencies
run: yarn install --prefer-offline --frozen-lockfile

# This block should eventually become use lando/actions-hyperdrive@v2
- name: Verify Docker dependencies
run: |
docker --version | grep "20.10."
docker-compose --version | grep "1.29."
- name: Move in lando config appropriate for testing
run: |
mkdir -p ~/.lando/cache
cp -f actions-lando-config.yml ~/.lando/config.yml
echo false > ~/.lando/cache/report_errors
# This part here is cloning a second repository
- name: Checkout Lando CLI from GitHub
uses: actions/checkout@v2
with:
repository: lando/cli
path: cli
ref: main
- name: Install Lando from GitHub Source
run: |
cd cli
yarn install --prefer-offline --frozen-lockfile
yarn build:cli
sudo mv ./dist/@lando/cli /usr/local/bin/lando
sudo chmod +x /usr/local/bin/lando
- name: Verify Lando works and we are dogfooding this plugin for tests
run: |
lando --clear
lando version
lando config --path plugins | grep laravel | grep /home/runner/work/laravel/laravel || echo "::error:: Not dogfooding this plugin correctly! "
# This block should eventually become use lando/actions-leia@v2
# @NOTE? Do we want a way for our leia-action to configure apparmor since
# this might break a whole bunch of tests? or is this literally just a thing
# for the Lagoon mysql/mariadb container?
- name: Configure apparmor
run: |
set -x
sudo apt-get remove mysql-server --purge
sudo apt-get install apparmor-profiles
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
- name: Run leia tests
shell: bash
run: yarn leia "./${{ matrix.leia-tests }}/README.md" -c 'Destroy tests' --stdin --shell bash
1 change: 1 addition & 0 deletions examples/laravel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
laravel
81 changes: 81 additions & 0 deletions examples/laravel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Laravel Example
===============

This example exists primarily to test the following documentation:

* [Laravel Recipe](https://docs.devwithlando.io/tutorials/laravel.html)

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should poweroff
lando poweroff

# Initialize an empty laravel recipe
rm -rf laravel && mkdir -p laravel && cd laravel
lando init --source cwd --recipe laravel --webroot app/public --name lando-laravel --option cache=redis

# Should compose create-project a new laravel app
cd laravel
lando composer create-project --prefer-dist laravel/laravel app

# Should start up successfully
cd laravel
echo -e "\nplugins:\n \"@lando/laravel/\": ./../../" >> .lando.yml
lando start
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should return the laravel default page
cd laravel
lando ssh -s appserver -c "curl -L localhost" | grep "Laravel"

# Should use 7.3 as the default php version
cd laravel
lando php -v | grep "PHP 7.3"

# Should be running apache 2.4 by default
cd laravel
lando ssh -s appserver -c "apachectl -V | grep 2.4"
lando ssh -s appserver -c "curl -IL localhost" | grep Server | grep 2.4

# Should be running mysql 5.7 by default
cd laravel
lando mysql -V | grep 5.7

# Should not enable xdebug by default
cd laravel
lando php -m | grep xdebug || echo $? | grep 1

# Should have redis running
cd laravel
lando ssh -s cache -c "redis-cli CONFIG GET databases"

# Should use the default database connection info
cd laravel
lando mysql -ularavel -plaravel laravel -e quit

# Should have artisan available
cd laravel
lando artisan env
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
cd laravel
lando destroy -y
lando poweroff
```
67 changes: 67 additions & 0 deletions recipes/laravel/builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

// Modules
const _ = require('lodash');

/*
* Helper to get cache
*/
const getCache = cache => {
// Return redis
if (_.includes(cache, 'redis')) {
return {
type: cache,
portforward: true,
persist: true,
};
// Or memcached
} else if (_.includes(cache, 'memcached')) {
return {
type: cache,
portforward: true,
};
}
};

/*
* Build Laravel
*/
module.exports = {
name: 'laravel',
parent: '_lamp',
config: {
confSrc: __dirname,
config: {},
composer: {},
database: 'mysql',
defaultFiles: {
php: 'php.ini',
},
php: '7.3',
services: {appserver: {overrides: {environment: {
APP_LOG: 'errorlog',
}}}},
tooling: {laravel: {service: 'appserver'}},
via: 'apache',
webroot: '.',
xdebug: false,
},
builder: (parent, config) => class LandoLaravel extends parent {
constructor(id, options = {}) {
options = _.merge({}, config, options);
// Add the laravel cli installer command
options.composer['laravel/installer'] = '*';
// Add in artisan tooling
// @NOTE: does artisan always live one up of the webroot?
options.tooling.artisan = {
service: 'appserver',
cmd: `php /app/${options.webroot}/../artisan`,
};
if (_.has(options, 'cache') && options.cache !== 'none') {
options.services.cache = getCache(options.cache);
}
// Send downstream
super(id, options);
};
},
};
46 changes: 46 additions & 0 deletions recipes/laravel/default.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
server {
listen 80 default_server;
listen 443 ssl;
server_name localhost;
ssl_certificate /certs/cert.crt;
ssl_certificate_key /certs/cert.key;
ssl_verify_client off;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
port_in_redirect off;
client_max_body_size 100M;
root "{{LANDO_WEBROOT}}";
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass fpm:9000;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
}
8 changes: 8 additions & 0 deletions recipes/laravel/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/*
* Init Lamp
*/
module.exports = {
name: 'laravel',
};
Loading

0 comments on commit 37a1f66

Please sign in to comment.