Skip to content

Commit 75f36ea

Browse files
committed
Add production deployment workflow
1 parent d0f0020 commit 75f36ea

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

.github/workflows/deploy-prd.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Deploy dabdbt (prd)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
environment: prd
12+
permissions:
13+
contents: read
14+
id-token: write
15+
env:
16+
DATABRICKS_HOST: ${{ vars.DATABRICKS_HOST }}
17+
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
18+
DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
19+
DATABRICKS_TENANT_ID: ${{ secrets.DATABRICKS_TENANT_ID }}
20+
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
21+
DATABRICKS_PROFILE: prd-github
22+
AZURE_STORAGE_ACCOUNT: ${{ vars.AZURE_STORAGE_ACCOUNT }}
23+
AZURE_STORAGE_CONTAINER: '$web'
24+
AZURE_BLOB_PATH: 'dabdbt/index.html'
25+
AZURE_BLOB_CONTENT_TYPE: 'text/html; charset=utf-8'
26+
AZURE_BLOB_CONTENT_DISPOSITION: inline
27+
AZURE_SUBSCRIPTION_ID: '${{ secrets.AZURE_SUBSCRIPTION_ID }}'
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: '3.11'
37+
38+
- name: Install dependencies
39+
run: |
40+
python -m pip install --upgrade pip
41+
pip install -r requirements.txt
42+
43+
- name: Install Databricks CLI
44+
run: |
45+
curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/main/install.sh | bash
46+
echo "${HOME}/.databricks/bin" >> "$GITHUB_PATH"
47+
echo "${HOME}/bin" >> "$GITHUB_PATH"
48+
49+
- name: Configure Databricks profile (Service Principal or PAT)
50+
run: |
51+
set -euo pipefail
52+
mkdir -p ~/.databricks
53+
if [ -n "${DATABRICKS_CLIENT_ID:-}" ] && [ -n "${DATABRICKS_CLIENT_SECRET:-}" ]; then
54+
printf '[%s]\nhost = %s\nclient_id = %s\nclient_secret = %s\n' "${DATABRICKS_PROFILE}" "${DATABRICKS_HOST}" "${DATABRICKS_CLIENT_ID}" "${DATABRICKS_CLIENT_SECRET}" > ~/.databrickscfg
55+
if [ -n "${DATABRICKS_TENANT_ID:-}" ]; then
56+
printf 'tenant_id = %s\n' "${DATABRICKS_TENANT_ID}" >> ~/.databrickscfg
57+
fi
58+
elif [ -n "${DATABRICKS_TOKEN:-}" ]; then
59+
printf '[%s]\nhost = %s\ntoken = %s\n' "${DATABRICKS_PROFILE}" "${DATABRICKS_HOST}" "${DATABRICKS_TOKEN}" > ~/.databrickscfg
60+
else
61+
echo "Missing Databricks credentials: set secrets.DATABRICKS_CLIENT_ID/SECRET or secrets.DATABRICKS_TOKEN" >&2
62+
exit 1
63+
fi
64+
65+
- name: Deploy bundle to Databricks (prd)
66+
working-directory: dabdbt
67+
run: |
68+
databricks bundle deploy --target prd --profile "${DATABRICKS_PROFILE}"
69+
70+
- name: Run dabdbt_job (prd)
71+
working-directory: dabdbt
72+
run: |
73+
databricks bundle run dabdbt_job --target prd --profile "${DATABRICKS_PROFILE}"
74+
75+
- name: Authenticate with Azure
76+
uses: azure/login@v2
77+
with:
78+
creds: ${{ secrets.AZURE_CREDENTIALS }}
79+
80+
- name: Set Azure subscription
81+
if: env.AZURE_SUBSCRIPTION_ID != ''
82+
run: |
83+
az account set --subscription "${AZURE_SUBSCRIPTION_ID}"
84+
85+
- name: Fix static website MIME metadata
86+
run: |
87+
az storage blob update \
88+
--account-name "${AZURE_STORAGE_ACCOUNT}" \
89+
--container-name "${AZURE_STORAGE_CONTAINER}" \
90+
--name "${AZURE_BLOB_PATH}" \
91+
--content-type "${AZURE_BLOB_CONTENT_TYPE}" \
92+
--content-disposition "${AZURE_BLOB_CONTENT_DISPOSITION}" \
93+
--auth-mode login

0 commit comments

Comments
 (0)