-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.yaml
More file actions
233 lines (212 loc) · 8.83 KB
/
Copy pathaction.yaml
File metadata and controls
233 lines (212 loc) · 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: "Defang Deployment Action"
description: "Use Defang to automatically deploy your application to the cloud."
author: "DefangLabs"
branding:
icon: "cloud"
color: "blue"
inputs:
cli-version:
description: "The version or Git ref of the Defang CLI to use. Defaults to the latest stable release."
required: false
default: ""
config-env-vars:
description: "Environment variables to deploy as config. Format: 'VAR1 VAR2 VAR3'"
required: false
default: ""
config-env-vars-init:
description: "Initialize config variables in this list from environment values if they are not already set. Format: 'VAR1 VAR2 VAR3'"
required: false
default: ""
config-vars-init-random:
description: "Initialize config variables in this list with random values if they are not already set. Format: 'VAR1 VAR2 VAR3'"
required: false
default: ""
command:
description: "The command to run."
required: false
default: "compose up"
compose-files:
description: "The compose files to deploy. Format 'file1 file2 file3'"
required: false
default: ""
cwd:
description: "The directory containing the compose file to deploy."
required: false
default: "."
mode:
description: "The deployment mode. Options: 'affordable', 'balanced', 'high-availability'. Deprecated in favor of stack:"
required: false
default: ""
stack:
description: "The stack to deploy."
required: false
default: ""
project:
description: "The project to deploy. If not specified, the CLI will determine the project name from the current directory or compose file."
required: false
default: ""
provider:
description: "The cloud provider to deploy to. Options: 'aws', 'azure', 'digitalocean', 'gcp'. If not specified, the CLI will determine the appropriate provider. Deprecated in favor of stack:"
required: false
default: ""
verbose:
description: "Enable verbose output for debugging."
required: false
default: "false"
allow-upgrade:
description: "Allow upgrading the CD image and Pulumi version to the latest available"
required: false
default: "false"
capture-output:
description: "Capture the command's stdout as an output. Disable for large deployments to avoid GitHub Actions memory limits."
required: false
default: "true"
outputs:
stdout:
description: "The stdout of the command. Only available when capture-output is 'true'."
value: ${{ steps.forward-output.outputs.stdout }}
runs:
using: "composite"
steps:
# If cli-version is a Git ref (not empty, not "nightly", and no dots, eg. no "v1.2.3"),
# build the CLI from source instead of downloading a release.
- name: Checkout CLI repository
id: checkout-cli
if: inputs.cli-version != '' && inputs.cli-version != 'nightly' && !contains(inputs.cli-version, '.')
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: DefangLabs/defang
ref: ${{ inputs.cli-version }}
path: defang-cli
- name: Setup Go
if: steps.checkout-cli.outcome == 'success'
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: defang-cli/src/go.mod
cache-dependency-path: defang-cli/src/go.sum
- name: Build CLI from source
if: steps.checkout-cli.outcome == 'success'
shell: bash
run: cd defang-cli/src && go build -o "$RUNNER_TOOL_CACHE/defang" ./cmd/cli && echo "$RUNNER_TOOL_CACHE" >> "$GITHUB_PATH"
- name: Install defang
shell: bash
run: |
if ! which defang >/dev/null 2>&1; then
. <(curl -fsSL https://raw.githubusercontent.com/DefangLabs/defang/main/src/bin/install || echo return $?)
fi
env:
DEFANG_INSTALL_VERSION: ${{ inputs['cli-version'] }}
GH_TOKEN: ${{ github.token }} # avoid rate-limits
- name: Set Defang environment variables
shell: bash
run: |
[ -n "$RUNNER_DEBUG" ] && echo "DEFANG_DEBUG=$RUNNER_DEBUG" >> $GITHUB_ENV || true
[ -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
- name: Login to Defang
shell: bash
working-directory: ${{ inputs.cwd }}
run: |
defang login
defang whoami
- name: Defang Config Set
shell: bash
if: ${{ inputs['config-env-vars'] != '' || inputs['config-vars-init-random'] != '' || inputs['config-env-vars-init'] != '' }}
run: |
# Build compose file parameters
params=()
for filename in $COMPOSE_FILES; do
params+=("-f")
params+=("$filename")
done
# Check for empty environment variables (only for config vars from env)
empty=()
for source in $CONFIG_ENV_VARS $CONFIG_ENV_VARS_INIT; do
if [ -z "${!source}" ]; then
empty+=("$source")
fi
done
# If there are empty variables, print instructions
if [ ${#empty[@]} -gt 0 ]; then
echo "Some Defang config vars do not have values. To use Github Secrets, add"
echo "these variables to your environment secrets:"
for source in "${empty[@]}"; do
echo "- $source"
done
echo "Here is a link to your repository environments settings:"
echo "https://github.com/${GITHUB_REPOSITORY}/settings/environments"
fi
# Set random config variables
if [ -n "$CONFIG_VARS_INIT_RANDOM" ]; then
echo "Initialize randomly generated configs..."
echo defang config "${params[@]}" set --if-not-set --random $CONFIG_VARS_INIT_RANDOM
defang config "${params[@]}" set --if-not-set --random $CONFIG_VARS_INIT_RANDOM
fi
# Set init config variables
if [ -n "$CONFIG_ENV_VARS_INIT" ]; then
echo "Initialize configs..."
echo defang config "${params[@]}" set --if-not-set -e $CONFIG_ENV_VARS_INIT
defang config "${params[@]}" set --if-not-set -e $CONFIG_ENV_VARS_INIT
fi
# Set regular config variables
if [ -n "$CONFIG_ENV_VARS" ]; then
echo "Updating configs..."
echo defang config "${params[@]}" set -e $CONFIG_ENV_VARS
defang config "${params[@]}" set -e $CONFIG_ENV_VARS
fi
working-directory: ${{ inputs.cwd }}
env:
COMPOSE_FILES: ${{ inputs['compose-files'] }}
CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }}
CONFIG_ENV_VARS_INIT: ${{ inputs['config-env-vars-init'] }}
CONFIG_VARS_INIT_RANDOM: ${{ inputs['config-vars-init-random'] }}
- name: Defang ${{ inputs['command'] }}
id: command
if: ${{ inputs['command'] != '' }}
shell: bash
working-directory: ${{ inputs.cwd }}
run: |
set -o pipefail
params=()
for filename in $COMPOSE_FILES; do
params+=("-f")
params+=("$filename")
done
if [[ -n "${{ inputs['mode'] }}" ]]; then
params+=("--mode=${{ inputs['mode'] }}")
fi
case "${{ inputs['verbose'] }}" in
y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON|1) params+=("--verbose") ;;
esac
case "${{ inputs['allow-upgrade'] }}" in
y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON|1) params+=("--allow-upgrade") ;;
esac
# Unset config vars to avoid Defang CLI warning user that config from shell env is ignored
unset $CONFIG_VARS_INIT_RANDOM $CONFIG_ENV_VARS $CONFIG_ENV_VARS_INIT dont_complain_on_empty
echo defang $COMMAND "${params[@]}"
if [[ "$CAPTURE_OUTPUT" =~ ^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON|1)$ ]]; then
output=$(defang $COMMAND "${params[@]}" | tee /dev/stderr)
echo "stdout<<DEFANG_EOF" >> "$GITHUB_OUTPUT"
echo "$output" >> "$GITHUB_OUTPUT"
echo "DEFANG_EOF" >> "$GITHUB_OUTPUT"
else
defang $COMMAND "${params[@]}"
fi
env:
COMMAND: ${{ inputs['command'] }}
COMPOSE_FILES: ${{ inputs['compose-files'] }}
CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }}
CONFIG_ENV_VARS_INIT: ${{ inputs['config-env-vars-init'] }}
CONFIG_VARS_INIT_RANDOM: ${{ inputs['config-vars-init-random'] }}
CAPTURE_OUTPUT: ${{ inputs['capture-output'] }}
- name: Forward output
id: forward-output
if: ${{ inputs['capture-output'] == 'true' }}
shell: bash
run: |
echo "stdout<<DEFANG_EOF" >> "$GITHUB_OUTPUT"
echo "$STDOUT" >> "$GITHUB_OUTPUT"
echo "DEFANG_EOF" >> "$GITHUB_OUTPUT"
env:
STDOUT: ${{ steps.command.outputs.stdout }}