-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_app_only.sh
More file actions
executable file
·141 lines (115 loc) · 3.2 KB
/
Copy pathdeploy_app_only.sh
File metadata and controls
executable file
·141 lines (115 loc) · 3.2 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
AZURE_CONFIG_DIR="${AZURE_CONFIG_DIR:-}"
usage() {
cat <<'EOF'
Usage:
./scripts/deploy_app_only.sh <env-file>
ENV_FILE=./infra/terraform/environments/dev/dev.env ./scripts/deploy_app_only.sh
Required environment variables:
ENV_FILE
RG
WEBAPP_NAME
Optional environment variables:
PACKAGE_PATH default: /tmp/${WEBAPP_NAME}.zip
AZURE_CONFIG_DIR default: use the current Azure CLI profile
SKIP_BROWSE default: false
This script only creates the ZIP deployment package and deploys it to an
existing Azure App Service web app. It does not provision or reconfigure Azure
resources, authentication, identities, or database settings.
ENV_FILE must point to a non-empty file. You can pass it as the first argument
or by setting the ENV_FILE environment variable.
EOF
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
if [[ $# -gt 1 ]]; then
echo "Unexpected arguments." >&2
usage >&2
exit 1
fi
if [[ $# -eq 1 ]]; then
ENV_FILE="$1"
elif [[ -n "${ENV_FILE:-}" ]]; then
ENV_FILE="${ENV_FILE}"
else
echo "Missing required ENV_FILE." >&2
usage >&2
exit 1
fi
require_env() {
local name="$1"
if [[ -z "${!name:-}" ]]; then
echo "Missing required environment variable: ${name}" >&2
exit 1
fi
}
require_command() {
local command_name="$1"
if ! command -v "${command_name}" >/dev/null 2>&1; then
echo "Required command not found: ${command_name}" >&2
exit 1
fi
}
log() {
printf '\n[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
}
require_command az
require_command zip
if [[ ! -f "${ENV_FILE}" || ! -s "${ENV_FILE}" ]]; then
echo "ENV_FILE must exist and be non-empty: ${ENV_FILE}" >&2
usage >&2
exit 1
fi
set -a
# shellcheck disable=SC1090
source "${ENV_FILE}"
set +a
if [[ -n "${AZURE_CONFIG_DIR}" ]]; then
mkdir -p "${AZURE_CONFIG_DIR}"
export AZURE_CONFIG_DIR
fi
require_env RG
require_env WEBAPP_NAME
PACKAGE_PATH="${PACKAGE_PATH:-/tmp/${WEBAPP_NAME}.zip}"
SKIP_BROWSE="${SKIP_BROWSE:-false}"
log "Checking Azure CLI authentication context"
if ! az account show --only-show-errors >/dev/null 2>&1; then
echo "Azure CLI is not authenticated in the active profile." >&2
echo "Run 'az login' or set AZURE_CONFIG_DIR to the profile that contains your login." >&2
exit 1
fi
log "Checking that the target web app exists"
az webapp show \
--resource-group "${RG}" \
--name "${WEBAPP_NAME}" \
--only-show-errors >/dev/null
log "Building ZIP deployment package at ${PACKAGE_PATH}"
rm -f "${PACKAGE_PATH}"
(
cd "${REPO_ROOT}"
zip -r "${PACKAGE_PATH}" app.py requirements.txt templates >/dev/null
)
log "Deploying application package"
az webapp deploy \
--resource-group "${RG}" \
--name "${WEBAPP_NAME}" \
--src-path "${PACKAGE_PATH}" \
--type zip \
--only-show-errors
cat <<EOF
App deployment completed.
Web app name: ${WEBAPP_NAME}
Web app URL: https://${WEBAPP_NAME}.azurewebsites.net
Package path: ${PACKAGE_PATH}
EOF
if [[ "${SKIP_BROWSE}" != "true" ]]; then
log "Opening the deployed site in the browser"
az webapp browse \
--resource-group "${RG}" \
--name "${WEBAPP_NAME}"
fi