-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yaml
More file actions
194 lines (177 loc) · 6.99 KB
/
action.yaml
File metadata and controls
194 lines (177 loc) · 6.99 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
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 deploy as config. 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'"
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', 'defang', 'digitalocean', 'gcp'. If not specified, the CLI will determine the appropriate provider."
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"
outputs:
stdout:
description: "The stdout of the command."
value: ${{ steps.command.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'] != '' }}
run: |
# Build compose file parameters
params=()
for filename in $COMPOSE_FILES; do
params+=("-f")
params+=("$filename")
done
# Check for empty environment variables (only for regular config vars)
empty=()
for source in $CONFIG_ENV_VARS; 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_ENV_VARS_INIT_RANDOM" ]; then
echo "Initialize randomly generated configs..."
echo defang config "${params[@]}" set --if-not-set --random $CONFIG_ENV_VARS_INIT_RANDOM
defang config "${params[@]}" set --if-not-set --random $CONFIG_ENV_VARS_INIT_RANDOM
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_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
echo defang $COMMAND "${params[@]}"
output=$(defang $COMMAND "${params[@]}" | tee /dev/stderr)
echo "stdout<<DEFANG_EOF" >> "$GITHUB_OUTPUT"
echo "$output" >> "$GITHUB_OUTPUT"
echo "DEFANG_EOF" >> "$GITHUB_OUTPUT"
env:
COMMAND: ${{ inputs['command'] }}
COMPOSE_FILES: ${{ inputs['compose-files'] }}