Skip to content

Commit

Permalink
env variables section
Browse files Browse the repository at this point in the history
  • Loading branch information
flemay committed May 7, 2024
1 parent 9510194 commit 003a588
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
44 changes: 43 additions & 1 deletion docs/guide/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,49 @@ Examples in this section use `.env` to pass environment variables to a container

Another option is to change the Makefile in a way to use the specified file and not overwrite the `.env` file with it.

## Check env vars in Makefile
## Load envfile from Makefile

Most of the time, environment variables in envfile are passed to the containers via Docker and Compose. There are times when accessing variables before passing to Docker is handy. Environment variables in an envfile can be explicitly loaded from Make:

```bash
# .env
MESSAGE="Hello, World"
```

```makefile
# Snippet from https://lithic.tech/blog/2020-05/makefile-dot-env
ifneq (,$(wildcard ./.env))
include .env
export
endif

echo:
echo "$(MESSAGE)"
```

However, this does not work well if the envfile contains key-only variables:

```bash
# .env
MESSAGE
```

Make will return:

```bash
make echo
#.env:1: *** missing separator. Stop.
```

Given that it does not work well with key-only variables, I simply tend to define the variables directly in the Makefile:

```makefile
MESSAGE ?= "Hello, World!"
echo:
echo "$(MESSAGE)"
```

## Check presence of env vars in Makefile

Here is a way for checking the presence of environment variables before executing a Make target.

Expand Down
5 changes: 1 addition & 4 deletions docs/guide/project-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Example from The [3 Musketeers repository](https://github.com/flemay/3musketeers

```yaml
# docker-compose.yml
version: '3.7'
services:
node:
image: node
Expand All @@ -27,13 +26,12 @@ Official images may not always solve project's dependency requirements and if ot

```yaml
# docker-compose.yml
version: '3.7'
services:
theservice:
image: theorganisation/theimage
```
## Local custom Docker images
## Dev container
If a project has specific dependency requirements, then creating (and maintaining) custom Docker images may be overkill. Instead, the project could have a Dockerfile that encapsulates the dependencies. This approach requires the image to be built locally before use.
Expand All @@ -53,7 +51,6 @@ RUN npm install -g \

```yaml
# docker-compose.yml
version: '3.7'
services:
mycontainer:
build: .
Expand Down

0 comments on commit 003a588

Please sign in to comment.