webrobert's avatar

How do you manage your env files?

For over a decade I ran ftp for site management. Then over the last few years I've been migrating to git. That and a recent bout of computer issues (read fresh installs).

I've been entertaining a hacker style approach to machine setup. You know what I mean. The hacker always sets the computer on fire 🔥 then some number of scenes later finds a new machine and runs some terminal commands and/or boots off some flashdrive, and she is once again connected to the world.

Here's what I've done so far, or what I am considering...

  1. I started my own .dotfile inspired by this episode
  2. I am considering Lando after watching it on laracon and @Sinnbeck experience
  3. moved all Mac files to cloud drive (except my dev files)
  4. moved all dev projects/websites files to repositories on GitHub (except envs).
  5. And that brings me to all the related .env/.wp-config.php, databases, etc. files.

I am pondering about some kind of symbolic linking? It maybe a lame idea. But I could certainly link env files to my cloud drive.

So how do you manage/store your local dev files?

0 likes
20 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

1 is already on my bucket list. But I just got a new computer and was up and running in about an hour or so..

Go for 2 : https://sinnbeck.dev/posts/using-lando-to-run-laravel-in-docker

For 5 I make sure my .example.env file is up to date with how the dev environment looks. That way it works when I copy it over and start my containers

1 like
webrobert's avatar

2

Wow, great write up! It's cool that you setup a blog. A couple things, I wished I could copy the code snippets but they paste with the line numbers, and I think there is a typo. lando npm dev isn't that supposed to be lando npm run dev?

Over the weekend I ran Lando on a second machine (using your write up!). I culled down my .dotfiles. Leaving out as many things as possible including php and composer and so on. Just got back my machine this morning. I think I made a clean jump to using Lando (and Docker)! Though I think I may install Composer to speed up the build process when docker spins up a project.

1

all and all .dotfiles has been an interesting journey. I would say it hasn't been perfect. Mainly for the run Fresh.sh concept. Which is meant to happen, once. Though everything really is about managing the files. What I like about this is I now have an aliases file, a brew file and so on. It has also got me thinking about things I want to have. It even inspired me to start making new aliases, and work on writing my own bash files to run things. I even made one for your command to spin up a new site with Lando...

spin new_app

That said, I haven't had a perfect run of using Fresh.sh yet. There have been little errors. and Still refining the .dotfiles to my liking. But implementing the concept has been pretty rad.

Sinnbeck's avatar

@webrobert Thanks! Hope it was easy to follow

Love the idea of the bash script. I have considered adding a downloadable one to my blog just like sail has. That way people could get started by visiting an url. I was also thinking of letting people the laravel version that way

I am also working on part 2 of the guide where we install octane, meili and horizon. Just trying to help with solving a bug in lando first. Let me know if you are missing anything

Sorry about the bug with the line numbers and the typo. I will fix that today

1 like
webrobert's avatar

@Sinnbeck

line numbers

safari and firefox both.

Torchlight add line numbers by default, but you can disable them globally or on the block level by changing the lineNumbers option to false.

where they have them set to false of course they copy without otherwise it's the same on there site too...

 2return [
 3    'extensions' => [
 4        // Add attributes straight from markdown.
 5        AttributesExtension::class,
 6
 7        // Add Torchlight syntax highlighting.
 8        TorchlightExtension::class,
 9    ]
10]

You don't have this issue?

Not sure offhand where I've seen it but there are sites that have a copy button in the corner of the code block.

For bash

I was wanting to add the final .lando.yml file when running spin project_name but I haven't gotten that far.

Sinnbeck's avatar

@webrobert thanks for testing. I will need to try and recreate it. Maybe it's Mac related. It works perfectly in Chrome and Firefox on my Linux machine.

Torchlight uses this css to make sure the numbers aren't selectable

.line-number {
    text-align: right;
    -webkit-user-select: none;
    user-select: none;
}

I will also look into a click to copy icon :)

Sinnbeck's avatar

I have now coded a copy to clipboard button. A bit ugly but it should do the trick :)

1 like
webrobert's avatar

@Sinnbeck,

its looking pretty good now!

I feel somewhat responsible, ha. How bout a little hover visibility?

pre code.torchlight + button {
 ...
 visibility: hidden;
}
article.prose pre:hover button {
 visibility: visible;
}
Sinnbeck's avatar

@webrobert well I am just happy to get better usability. I will try and make it a bit prettier the next time I get a chance. Let me know if you want help with the bash script

1 like
webrobert's avatar

@Sinnbeck,

I'd love some help on expanding the bash script. its completely fresh to me.

Right now its just an alias

alias spin="~/.dotfiles/spin-laravel.sh" # with a lando file

and the bash script.

My thoughts about what's missing,

  1. Presently, it has to be manually made executable before it works, the first time. I'd like to write that in.
  2. Have it make your whole .lando.yml file as default. I briefly looked to into how to do this. trying to find a way in the lando docs. Maybe its just to open the file after Lando creates it and edit/remake it.
  3. Perhaps require the script to be run from a certain directory to prevent initializing a project inside a project.
Sinnbeck's avatar

@webrobert what extra things do you want in the Lando config? Database and php version?

1 like
webrobert's avatar

@Sinnbeck,

I generally like your file...

name: my-app
recipe: laravel
config:
  webroot: ./public
  php: '8.0'
  via: apache
  database: mysql
  cache: redis
services:
  node:
    type: node:16
    scanner: false
    build:
      - npm install
  mail:
    type: mailhog
    portforward: true
    hogfrom:
      - appserver
tooling:
  migrate:
    service: appserver
    cmd: php artisan migrate
  npm:
    service: node
    cmd: npm
proxy: 
  mail:
    - mail.my-app.lndo.site 
Sinnbeck's avatar

@webrobert Ok here is my best try :) It is currently only tested on my linux machine, but I assume it will work the same on mac.

It checks that docker and lando are available, and that there isnt a .git directory (you are inside another project). It then does what you told it to, and finally appends the extra config data

#!/bin/sh

if ! command -v docker > /dev/null  2>&1
then
    echo "Docker not found!"
    exit 1
fi

if ! command -v lando > /dev/null  2>&1
then
    echo "Lando not found!"
    exit 1
fi

if test $(find -maxdepth 1 -type d -name ".git" | wc -c) -eq 1
then
    echo "This seems to be a git directory"
    exit 1
fi

if [ -z "" ]
then
    echo "You must include your app name with the command. 'spin app_name"
    exit 1
fi

docker run --rm --interactive --tty \
  --volume $PWD:/app \
  --user $(id -u):$(id -g) \
  composer create-project laravel/laravel  ^9.0 \
  && cd  \
  && lando init --source cwd --webroot ./public --recipe laravel --name 

FILE=".lando.yml"
cat >> $FILE <<- EOM
  php: '8.0'
  via: apache
  database: mysql
  cache: redis
services:
  node:
    type: node:16
    scanner: false
    build:
      - npm install
  mail:
    type: mailhog
    portforward: true
    hogfrom:
      - appserver
tooling:
  migrate:
    service: appserver
    cmd: php artisan migrate
  npm:
    service: node
    cmd: npm
proxy: 
  mail:
    - mail..lndo.site
EOM
1 like
webrobert's avatar

@Sinnbeck nice!

so all worked but this conditional...

if test $(find -maxdepth 1 -type d -name ".git" | wc -c) -eq 1
then
    echo "This seems to be a git directory"
    exit 1
fi

find: illegal option -- m usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

not sure if it's got sanitized by the forum (notice how it removes all the dollar signs and 1s).

I changed it to...

if [ -f .git ] || [ -f .env ]
then
    echo "Opps! This seems to be a project directory. Run 'sites'"
    exit 1
fi
Sinnbeck's avatar

@webrobert Ah cool. Maybe my used syntax is linux only. Great that you found a shorter solution.

1 like
webrobert's avatar

@Sinnbeck at this line...

if ! command -v lando > /dev/null  2>&1
...

what's happening here /dev/null 2>&1 ?

Sinnbeck's avatar

@webrobert It is actually borrowed from landos source code :p

But first we send the outout to null, so it isnt shown. And seconds port is converting stderr to stdout

Please or to participate in this conversation.