Skip to content

Commit

Permalink
Merge pull request #17 from DefangLabs/lio/add-command-arg
Browse files Browse the repository at this point in the history
Add command input param
  • Loading branch information
lionello authored Oct 30, 2024
2 parents 0ea1c89 + 004dcfa commit b6d06a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ jobs:
config-env-vars: "DEFANG_GH_ACTION_TEST_MESSAGE"
cwd: "./test"
compose-files: "compose.yaml compose.prod.yaml"
mode: "staging"
mode: ""
command: "compose up --dry-run"
env:
DEFANG_GH_ACTION_TEST_MESSAGE: ${{ secrets.MESSAGE }}
DEFANG_INTERNAL_TEST: dfng-test

- name: Deploy-Empty-Params
uses: ./
continue-on-error: true # Ignore dry run error
with:
cli-version: v0.5.40
config-env-vars: ""
cwd: "./test"
compose-files: ""
mode: ""
env:
DEFANG_INTERNAL_TEST: dfng-test
mode: "staging"
command: "compose up --dry-run --project-name github-action-test"

- name: Teardown
run: defang config rm DEFANG_GH_ACTION_TEST_MESSAGE
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
### Managing Config Values
Defang allows you to [securely manage configuration values](https://docs.defang.io/docs/concepts/configuration). You can store your config using [GitHub Actions Secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) and then pass them through to the Defang action.
Defang allows you to [securely manage configuration values](https://docs.defang.io/docs/concepts/configuration). You can store your config using [GitHub Actions Secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) and then pass them through to the Defang action.
To publish a secret stored in GitHub to the cloud as a secure config value with defang, you need to do two things:
Expand Down Expand Up @@ -83,6 +83,23 @@ jobs:
cli-version: v0.5.38
```

### Customizing the Defang Command

If you want to customize the Defang command that is run, you can specify it using the `command` input.
This is useful if you want to run a command other than `compose up` or if you want to pass additional arguments to the command.

```yaml
jobs:
test:
# [...]
steps:
# [...]
- name: Deploy
uses: DefangLabs/[email protected]
with:
command: "compose up --project-name my-project"
```

### Full Example

Here is a full example of a GitHub workflow that does everything we've discussed so far:
Expand Down
22 changes: 12 additions & 10 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ inputs:
required: false
default: ""
provider:
description: "The cloud provider to deploy to. Options: 'aws', 'defang'"
description: "The cloud provider to deploy to. Options: 'aws', 'defang', 'digitalocean'"
required: false
default: "defang"
command:
description: "The command to run."
required: false
default: "compose up"

runs:
using: "composite"
Expand All @@ -55,6 +59,7 @@ runs:
- name: Defang Config Set
shell: bash
if: ${{ inputs['config-env-vars'] != '' }}
run: |
# Iterate over the sources and set the environment variables
params=()
Expand All @@ -71,7 +76,8 @@ runs:
env:
CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }}

- name: Defang Compose Up
- name: Defang ${{ inputs['command'] }}
if: ${{ inputs['command'] != '' }}
shell: bash
working-directory: ${{ inputs.cwd }}
run: |
Expand All @@ -84,11 +90,7 @@ runs:
params+=("--mode=${{ inputs['mode'] }}")
fi
if [[ "${DEFANG_INTERNAL_TEST}" == "dfng-test" ]]; then
# `defang compose up --dry-run` is used for testing as --mode flag is only available to the "compose up" command
echo defang compose "${params[@]}" up --dry-run
defang compose "${params[@]}" up --dry-run
else
echo defang compose "${params[@]}" up
defang compose "${params[@]}" up
fi
echo defang $COMMAND "${params[@]}"
defang $COMMAND "${params[@]}"
env:
COMMAND: ${{ inputs['command'] }}

0 comments on commit b6d06a0

Please sign in to comment.