Lullabot / drainpipe

GNU General Public License v3.0
30 stars 14 forks source link

Add touch .env to scaffolding #468

Closed YesCT closed 6 months ago

YesCT commented 6 months ago

For pantheon multidev deploys, we needed to add:

$ git diff
diff --git a/.github/actions/drainpipe/ddev/action.yml b/.github/actions/drainpipe/ddev/action.yml
index e0c250b5e..8188bedc3 100644
--- a/.github/actions/drainpipe/ddev/action.yml
+++ b/.github/actions/drainpipe/ddev/action.yml
@@ -22,10 +22,6 @@ inputs:
 runs:
   using: "composite"
   steps:
-    - name: Create empty env file
-      run: touch .env
-      shell: bash
-
     - name: Install and Start DDEV
       run: |
         curl https://apt.fury.io/drud/gpg.key | sudo apt-key add -

We plan to have a followup to prevent the change from being overwritten with something like https://github.com/Lullabot/drainpipe/blob/main/README.md#nightwatch

"extra": {
        "drupal-scaffold": {
            "file-mapping": {
                ".github/actions/drainpipe/ddev/action.yml": {
            "mode": "skip"
        }
    }
}

Question 1: Are we missing something else where we should be setting .env?

Question 2: Is this common enough that making sure .env isn't empty should be added to the default scaffold file??

davereid commented 6 months ago

Are .env files required? What error do you get without the file?

justafish commented 6 months ago

@YesCT why did you need to add it, what happens without it? .env files should only be for local development, not remote deployments

leonel-lullabot commented 6 months ago

@davereid @justafish we were getting this error at the 'Install and Start DDEV' step

env file /home/runner/work/project/project/.env not found: stat /home/runner/work/project/project/.env: no such file or directory
Failed to start project: composeCmd failed to run 'COMPOSE_PROJECT_NAME=ddev-project docker-compose -f /home/runner/work/project/project/.ddev/.ddev-docker-compose-base.yaml -f /home/runner/work/project/project/.ddev/docker-compose.env-file.yaml config', action='[]', err='exit status 14', stdout='', stderr='env file /home/runner/work/project/project/.env not found: stat /home/runner/work/project/project/.env: no such file or directory'
Error: Process completed with exit code 1.
davereid commented 6 months ago

I don't see docker-compose.env-file.yaml coming from drainpipe at all, should the project possibly be re-configured to not require an .env file on non-local environments or gracefully proceeding instead of failing?

davereid commented 6 months ago

I also think generally we encourage the use of https://github.com/vlucas/phpdotenv as a require-dev dependency instead of loading the .env file via DDEV configuration.

The DDEV docs themselves say to use a .ddev/.env file and do not reference loading .env files at the root directly: https://ddev.readthedocs.io/en/latest/users/extend/customization-extendibility/#providing-custom-environment-variables-to-a-container

leonel-lullabot commented 6 months ago

I noticed that we have docker-compose.env-file.yaml inside .ddev with the following:

services:
  web:
    env_file:
      - ../.env

This file was causing the error. Thank you for your help!

YesCT commented 6 months ago

@justafish @davereid Thank you so much for pointing us in the right direction.

Closing this since my questions are answered. :)