Skip to content
Merged
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
60 changes: 32 additions & 28 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ on:
- main
pull_request:
branches:
- '**'
- "**"
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
# schedule:
# - cron: "0 0 * * *" # daily at midnight

jobs:
test:
Expand All @@ -19,31 +19,35 @@ jobs:
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deploy
uses: ./
continue-on-error: true # Ignore dry run error
with:
cli-version: v0.5.40
config-env-vars: "DEFANG_GH_ACTION_TEST_MESSAGE"
cwd: "./test"
compose-files: "compose.yaml compose.prod.yaml"
mode: ""
command: "compose up --dry-run"
env:
DEFANG_GH_ACTION_TEST_MESSAGE: ${{ secrets.MESSAGE }}
- name: Deploy
uses: ./
with:
cli-version: v0.5.40
config-env-vars: |
DEFANG_GH_ACTION_TEST_ENV
DEFANG_GH_ACTION_TEST_MESSAGE
cwd: "./test"
compose-files: |
compose.yaml
compose.prod.yaml
mode: ""
command: "compose help"
env:
DEFANG_GH_ACTION_TEST_ENV: "foo"
DEFANG_GH_ACTION_TEST_MESSAGE: ${{ secrets.MESSAGE }}

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

- name: Teardown
run: defang config rm DEFANG_GH_ACTION_TEST_MESSAGE
- name: Teardown
run: defang config rm DEFANG_GH_ACTION_TEST_MESSAGE
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Defang allows you to [securely manage configuration values](https://docs.defang.
To publish a secret stored in GitHub to the cloud as a secure config value with defang, you need to do two things:

1. Use the `env` section of the step to pass the value of the secrets to environment variables that match the names of the config values in your Compose file.
2. Specify the names of the environment variables you want to push to the cloud as config values in the `config-env-vars` input.
2. Specify the names of the environment variables you want to push to the cloud as config values in the `config-env-vars` input, either whitespace delimited or as a YAML literal block scalar (`|`).

The second step is to make sure that we only publish the secrets you explicitly tell us to. For example, you could have a secret in an env var at the job level, instead of the step level that you might not want to push to the cloud, even if it is in a secure store.

Expand All @@ -45,7 +45,9 @@ jobs:
uses: DefangLabs/defang-github-action@v1.2.0
with:
# Note: you need to tell Defang which env vars to push to the cloud as config values here. Only these ones will be pushed up.
config-env-vars: "API_KEY DB_CONNECTION_STRING"
config-env-vars: |
API_KEY
DB_CONNECTION_STRING
env:
API_KEY: ${{ secrets.API_KEY }}
DB_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }}
Expand Down
10 changes: 6 additions & 4 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:

inputs:
cli-version:
description: "The version of the Defang CLI to use."
description: "The version of the Defang CLI to use. Defaults to the latest stable release."
required: false
default: ""
config-env-vars:
Expand All @@ -27,7 +27,7 @@ inputs:
required: false
default: ""
provider:
description: "The cloud provider to deploy to. Options: 'aws', 'defang', 'digitalocean'"
description: "The cloud provider to deploy to. Options: 'aws', 'defang', 'digitalocean', 'gcp'"
required: false
default: "defang"
command:
Expand Down Expand Up @@ -63,7 +63,7 @@ runs:
run: |
# Iterate over the sources and set the environment variables
params=()
for filename in ${{ inputs['compose-files'] }}; do
for filename in $COMPOSE_FILES; do
params+=("-f")
params+=("$filename")
done
Expand All @@ -74,6 +74,7 @@ runs:
done
working-directory: ${{ inputs.cwd }}
env:
COMPOSE_FILES: ${{ inputs['compose-files'] }}
CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }}

- name: Defang ${{ inputs['command'] }}
Expand All @@ -82,7 +83,7 @@ runs:
working-directory: ${{ inputs.cwd }}
run: |
params=()
for filename in ${{ inputs['compose-files'] }}; do
for filename in $COMPOSE_FILES; do
params+=("-f")
params+=("$filename")
done
Expand All @@ -94,3 +95,4 @@ runs:
defang $COMMAND "${params[@]}"
env:
COMMAND: ${{ inputs['command'] }}
COMPOSE_FILES: ${{ inputs['compose-files'] }}