deploy #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- main | |
- master | |
env: | |
TARGET_SCHEMA: prod | |
jobs: | |
deploy_git: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
env: | |
SERVER_HOST_KEY: ${{ secrets.SERVER_HOST_KEY }} | |
CLIENT_SECRET_KEY: ${{ secrets.CLIENT_SECRET_KEY }} | |
HOSTNAME: ${{ secrets.HOSTNAME }} | |
SSH_PORT: ${{ secrets.SSH_PORT }} | |
steps: | |
- name: Set up SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SERVER_HOST_KEY" > ~/.ssh/known_hosts | |
chmod 600 ~/.ssh/known_hosts | |
echo "$CLIENT_SECRET_KEY" > ~/.ssh/id_ed25519 | |
chmod 600 ~/.ssh/id_ed25519 | |
- name: Update Server | |
run: | | |
eval "$(ssh-agent -s)" | |
ssh-add ~/.ssh/id_ed25519 | |
ssh -o StrictHostKeyChecking=no -o ForwardAgent=yes root@$HOSTNAME -p $SSH_PORT << 'EOF' | |
cd /workspaces/gtd_ETL | |
git pull origin main | |
. ./bootstrap_env.sh | |
. ./venv/bin/activate | |
pip install -r requirements.txt | |
dbt deps | |
make deploy | |
EOF | |
deploy_lightdash: | |
runs-on: ubuntu-latest | |
needs: deploy_git | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: ./.github/actions/setup-env | |
with: | |
PROD_ENV: ${{ secrets.PROD_ENV }} | |
- name: Cache Python packages | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/pip | |
~/.local | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11.x" | |
- name: Install Python dependencies | |
run: | | |
pip install -r requirements.txt | |
dbt deps | |
- name: Cache npm packages | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.npm | |
~/.cache/npm | |
node_modules | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- uses: actions/[email protected] | |
with: | |
node-version: '20' | |
- name: Get lightdash version | |
uses: sergeysova/jq-action@v2 | |
id: version | |
env: | |
LIGHTDASH_URL: ${{ secrets.LIGHTDASH_URL }} | |
with: | |
cmd: curl -s "${LIGHTDASH_URL}/api/v1/health" | jq -r '.results.version' | |
- name: Install npm dependencies | |
run: npm install -g "@lightdash/cli@${{ steps.version.outputs.value }}" || npm install -g @lightdash/cli@latest | |
- name: Lightdash CLI deploy | |
env: | |
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }} | |
LIGHTDASH_PROJECT: ${{ secrets.LIGHTDASH_PROJECT }} | |
LIGHTDASH_URL: ${{ secrets.LIGHTDASH_URL }} | |
GOOGLE_APPLICATION_CREDENTIALS: '/tmp/googlecredentials.json' | |
run: lightdash deploy |