4.27.0 • Published 27 days ago

@fishawack/lab-env v4.27.0

Weekly downloads
29
License
ISC
Repository
bitbucket
Last release
27 days ago

Background

What

A command line utility to spin up and manage FW specific docker containers.

Why

To automate the spinning up of our tech stack and to provide a consistent environment for dev and production.

Dependencies

Click on the following links and follow the instructions.

Alternatively you can install via brew or choco depending on your platform.

Mac

Install brew package manager

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install dependencies

brew install node
brew cask install docker

Optionally install git

brew install git

Windows

Install choco package manager.

The install command needs to be run in an administrative powershell terminal.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Install dependancies

choco install nodejs
choco install docker-desktop

Optionally install git

choco install git

Getting started

Install

npm install @fishawack/lab-env -g

Basic usage

lab-env setup && lab-env start

Commands

To see the full command list and a description of each command run the following command.

lab-env --help

Troubleshooting

Permission denied when mounting nginx conf (Laravel)

Problem

This happens when your using NodeJs installed into the root filesystem (/usr/local/bin), you may see errors similar to this:

ERROR: for nginx  Cannot start service nginx: OCI runtime create failed: container_linux.go:367: starting container process caused: process_linux.go:495: container init caused: rootfs_linux.go:60: mounting "/usr/local/lib/node_modules/@fishawack/lab-env/laravel/8/nginx/nginx.conf" to rootfs at "/var/lib/docker/overlay2/1ea9b758b732df7b4fe4dd5e1bd57836967bfde1d9a1ae44ca1a5c0d6e95db5c/merged/etc/nginx/conf.d/default.conf" caused: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

Solution

Purge your NodeJs installation and install it via NVM https://github.com/nvm-sh/nvm

No space left

Problem

Docker has 64gb of space by default. If you see the below messages you need to have a spring clean and free up some space or give docker more memory.

npm WARN tar ENOSPC: no space left on device, write

When setting up a new project, one of the package may fail to pull from docker and shows an "invalid signature" or "is not signed" error:

=> ERROR [alpine 3/19] RUN apt-get update
Get:1 http://deb.debian.org/debian bullseye InRelease
W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.

Solution

Clean up your docker.

mySql creds

Problem

When a project is first setup the mysql container will create any tables needed based on whats found in the .env file. If the database details are modified in the .env file after the first run those new tables will not be created resulting in the site not being able to connect to mysql.

Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = fide and table_name = migrations)

Solution

The volume needs removing and re-setting up, the easiest way to do this is to commit everything in and re-setup the project.

# Commit/Stash so you don't lose any work
git stash

lab-env nuke
lab-env setup

git stash pop

Watch / Case sensitive issues

Problem

As of docker desktop 3.2.2, if you cd into a directory without correctly matching the case of the folders in your working tree, then you can run into some strange issues, one of them being laravel mix not triggering a watch on javascript or sass files correctly but still working fine for html/twig/blade files.

Solution

Always match the case as it exists in your directory structure.

// Bad (but will work fine for the most part)
cd /Users/mmellor/sites/boilerplate

// Good (notice the case in the 'Sites' folder name)
cd /Users/mmellor/Sites/boilerplate

Memory limit

By default Docker will assign 64gb of memory for Docker to utilize. After a while of using lab-env and potentially other docker setups you may come close to or exceed that limit. To see how much memory docker is using type the following command.

docker system df -v

If you want a full clean up of docker then running the following command will remove all containers, volumes, images and caches.

docker system prune --all --volumes -f

If you just want to remove the images and containers so they can be built fresh then run the following.

docker system prune --all -f

You can also run the slightly less impactful clean command but this command wouldn't do much if you're only use of docker is through lab-env as this tool doesn't currently persist any containers between runs.

docker system prune -f

If you notice it's mainly the volumes that are taking up all the space then you can either clean out all volumes (this will remove every projects node_modules folder meaning they'll need re-installing).

docker volume rm $(docker volume ls -q)

Or you can target specific node_modules and hand pick which ones to remove. For example:

docker volume rm boilerplate_node_modules

Migrating

2.0.0

Wordpress repo's are now structured slightly differently to better match laravel, drupal and craftcms setups. Follow these steps to upgrade a wordpress build and get lab-env working again.

Reset repository

Before starting this migration ensure all code is committed so you don't run the risk of losing anything afterwhich run one of the following.

fw nuke

# or

Remove / Re-clone repository

wp-content

Move the plugins, themes and uploads folder a new wp-content folder at the root of the project.

# Old way
./themes
./plugins
./uploads

# New way
./wp-content/themes
./wp-content/plugins
./wp-content/uploads

.env.example

Replace the contents of the .env.example with the following.

# Old way
DB_DATABASE=wordpress
DB_USERNAME=wordpress
DB_PASSWORD=password
JWT_SECRET=

# New way
DEBUG=true

DB_DATABASE=wordpress
DB_USERNAME=wordpress
DB_PASSWORD=password
DB_HOST=mysql
DB_CHARSET=utf8
DB_COLLATE=

TABLE_PREFIX=wp_

AUTH_KEY=5c94a709b751faeed445f29b92f8513b8bce1652
SECURE_AUTH=09e370e7bfc34b17fc96d80cda1a281427053afd
LOGGED_IN=405de7e577398c86b6975fc4a8bba1df179666dd
NONCE_KEY=10c232cb86bb257af4c0434a7e3b9f993f18ba11
AUTH_SALT=07a08cb5a6c3318633c505fcf1ffffa4d01ab375
SECURE_AUTH=df11e32128f8d5403a7c681d0e5cc4145be2b2ab
LOGGED_IN=a99860e8150b15e11caada875f56421165659a7d
NONCE_SALT=51c6eba59477027e612fc13e38a53acaa2b73d92

CONFIG_EXTRA="
    define( 'WP_HOME', 'http://localhost:3000' );
    define( 'WP_SITEURL', 'http://localhost:3000' );
"

.gitignore

There's a new more complex gitignore now that takes into account the wordpress files that are reverse mounted back to the host machine.

# Old way
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
#     https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
.env


.tmp/
generated/
_Zips/
_Pdfs/
coverage/
**/generated/**/*
_Build/**/pulled/**/*
_Output
_Login
_Packages
_Build/content
_Build/media/content
_App
_Electron
_Node/stats
ssh-*
.ftppass
id_rsa
misc.json
.cache/
themes/twenty*
themes/thirty*
themes/*/css
themes/*/js
plugins/akismet
plugins/hello.php
uploads

# New way
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
#     https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
.env

.tmp/
generated/
_Zips/
_Pdfs/
coverage/
**/generated/**/*
_Build/**/pulled/**/*
_Output
_Login
_Packages
_Build/content
_Build/media/content
_App
_Electron
_Node/stats
ssh-*
.ftppass
id_rsa
misc.json
.cache/

# Wordpress docker image files
.htaccess
license.txt
readme.html
index.php
xmlrpc.php
wp-*
!wp-content**/*
wp-content/index.php
wp-content/plugins/index.php
wp-content/themes/index.php
wp-content/themes/twenty*
wp-content/themes/thirty*
wp-content/themes/fishawack/css
wp-content/themes/fishawack/js
wp-content/plugins/akismet
wp-content/plugins/hello.php
wp-content/uploads

# Generated by MacOS
.DS_Store

Default theme location

The default root attribute needs updating to take into account the new folder structure.

// Old way
"attributes": {
    "root": "themes/fishawack",
}

// New way
"attributes": {
    "root": "wp-content/themes/fishawack",
}

Deploy files

The deploy paths also need updating to take into account the new folder structure.

// Old way
"paths": [
    {
        "src": "plugins",
        "dest": "wp-content/plugins"
    },
    {
        "src": "themes",
        "dest": "wp-content/themes"
    }
]

// New way
"paths": [
    {
        "src": "wp-content/plugins",
        "dest": "wp-content/plugins"
    },
    {
        "src": "wp-content/themes",
        "dest": "wp-content/themes"
    }
]
4.27.0

27 days ago

4.26.0

2 months ago

4.25.2

3 months ago

4.25.3

3 months ago

4.25.1

3 months ago

4.25.0

3 months ago

4.24.0

6 months ago

4.22.0

9 months ago

4.22.1

9 months ago

4.18.0

12 months ago

4.21.0

12 months ago

4.17.0

1 year ago

4.20.0

12 months ago

4.16.0

1 year ago

4.19.0

12 months ago

4.15.0

1 year ago

4.15.1

1 year ago

4.14.0

1 year ago

4.13.0

1 year ago

4.12.0

1 year ago

4.10.0

1 year ago

4.11.0

1 year ago

4.11.1

1 year ago

4.9.0

1 year ago

4.8.0

1 year ago

4.4.0

1 year ago

4.6.0

1 year ago

4.2.1

2 years ago

4.5.0

1 year ago

4.3.1

1 year ago

4.7.0

1 year ago

4.3.0

1 year ago

3.2.0

2 years ago

3.0.0

2 years ago

4.0.0

2 years ago

4.2.0

2 years ago

3.1.0

2 years ago

4.1.0

2 years ago

4.1.1

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.18.1

2 years ago

1.18.0

2 years ago

1.16.0

2 years ago

1.15.0

2 years ago

1.17.0

2 years ago

1.14.0

2 years ago

1.13.0

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.11.0

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.0

3 years ago

0.21.1

3 years ago

0.21.0

3 years ago

0.20.1

3 years ago

0.20.2

3 years ago

0.20.0

3 years ago

0.19.0

3 years ago

0.15.0

3 years ago

0.16.0

3 years ago

0.17.0

3 years ago

0.18.0

3 years ago

0.14.0

3 years ago

0.13.0

3 years ago

0.12.1

3 years ago

0.12.0

3 years ago

0.11.0

3 years ago

0.10.2

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.5.0

3 years ago

0.6.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago