Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,23 @@ jobs:
verbose: true
command: "compose up --dry-run --project-name github-action-test"

- name: Deploy with env-file
id: env-file-test
uses: ./
continue-on-error: true # Ignore dry run error
with:
cwd: "./test"
compose-files: "compose.envfile.yaml"
env-file: "action.env"
command: "compose config --project-name github-action-test"

- name: Verify env-file interpolation
shell: bash
run: |
echo "${STDOUT}" | grep -q "hello-from-env-file" \
|| { echo "expected env-file value not found in output"; exit 1; }
env:
STDOUT: ${{ steps.env-file-test.outputs.stdout }}

- name: Teardown
run: defang config rm --project-name github-action-test DEFANG_GH_ACTION_TEST_MESSAGE
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ jobs:
DB_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }}
```

### Using an Environment File

By default, Defang loads a `.env` file next to your Compose file to resolve `${VARIABLE}` interpolation. To use a different environment file (or several), set the `env-file` input. This mirrors `docker compose --env-file` and, when set, replaces the default `.env`.

```yaml
jobs:
test:
# [...]
steps:
# [...]
- name: Deploy
uses: DefangLabs/defang-github-action@v2
with:
env-file: ".env.production"
```

Pass multiple files whitespace-delimited (`env-file: ".env .env.production"`); later files override earlier ones.

### Projects in a Subdirectory

If your Compose file is in a different directory than your project root, you can specify the path to the project in the `cwd` input.
Expand Down
8 changes: 8 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ inputs:
description: "The compose files to deploy. Format 'file1 file2 file3'"
required: false
default: ""
env-file:
description: "Environment file(s) used for compose interpolation instead of the default .env. Format 'file1 file2 file3'"
required: false
default: ""
cwd:
description: "The directory containing the compose file to deploy."
required: false
Expand Down Expand Up @@ -111,6 +115,10 @@ runs:
[ -n "${{ inputs['provider'] }}" ] && echo "DEFANG_PROVIDER=${{ inputs['provider'] }}" >> $GITHUB_ENV || true
[ -n "${{ inputs['stack'] }}" ] && echo "DEFANG_STACK=${{ inputs['stack'] }}" >> $GITHUB_ENV || true
[ -n "${{ inputs['project'] }}" ] && echo "COMPOSE_PROJECT_NAME=${{ inputs['project'] }}" >> $GITHUB_ENV || true
# The CLI reads COMPOSE_ENV_FILES (comma-separated) like docker compose; convert the space-separated input.
[ -n "$ENV_FILE" ] && echo "COMPOSE_ENV_FILES=$(echo "$ENV_FILE" | tr ' ' ',')" >> $GITHUB_ENV || true
env:
ENV_FILE: ${{ inputs['env-file'] }}

- name: Login to Defang
shell: bash
Expand Down
1 change: 1 addition & 0 deletions test/action.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREETING=hello-from-env-file
7 changes: 7 additions & 0 deletions test/compose.envfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
web:
build: .
ports:
- "3000:3000"
environment:
GREETING: ${GREETING}