Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add continuous deployment to Dash server #12

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: reusable deployment workflow

on:
workflow_call:
secrets:
DASH_SSH_KEY:
required: true
DASH_ENTERPRISE_URL:
required: true
APP_NAME:
required: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "deploy"
deploy:
# The type of runner that the job will run on
runs-on: ubuntu-22.04
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Add git remote
run: git remote add plotly git@$DASH_ENTERPRISE_URL:$APP_NAME
env:
DASH_ENTERPRISE_URL: ${{secrets.DASH_ENTERPRISE_URL}}
APP_NAME: ${{secrets.APP_NAME}}
- name: Setup project directory
run: |
set -x
pwd
ls -al
mkdir -p /home/runner/.ssh
- name: Setup SSH key
run: |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa # permissioning
eval "$(ssh-agent -s)" # setting ssh environment variable
ssh-add ~/.ssh/id_rsa
echo "Host *
Port 22
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null" > ~/.ssh/config
env:
SSH_PRIVATE_KEY: ${{secrets.DASH_SSH_KEY}}
- name: Deploy
run: |
git push --force plotly HEAD:refs/heads/master
13 changes: 13 additions & 0 deletions .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: production deployment

on:
push:
branches: [main]

jobs:
prod-deploy:
uses: ./.github/workflows/deploy.yml
secrets:
DASH_SSH_KEY: ${{secrets.DASH_SSH_KEY}}
APP_NAME: ${{secrets.APP_NAME}}
DASH_ENTERPRISE_URL: ${{secrets.DASH_ENTERPRISE_URL}}
66 changes: 66 additions & 0 deletions .github/workflows/staging-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: staging deployment

on: pull_request

jobs:
test-and-lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python 3.9.16
uses: actions/setup-python@v3
with:
python-version: '3.9.16'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test formatting with black
run: |
black . --check
staging-deploy:
needs: test-and-lint
uses: ./.github/workflows/deploy.yml
secrets:
DASH_SSH_KEY: ${{secrets.DASH_SSH_KEY}}
APP_NAME: ${{secrets.APP_NAME}}-staging
DASH_ENTERPRISE_URL: ${{secrets.DASH_ENTERPRISE_URL}}
comment-deploy-link:
needs: staging-deploy
runs-on: ubuntu-22.04
steps:
- name: Check for existing comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
- name: Post comment
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Staging application has been deployed and is available at: https://${{secrets.DASH_ENTERPRISE_URL}}/${{secrets.APP_NAME}}-staging
Production app name: `${{secrets.APP_NAME}}`
Current branch name: `${{github.head_ref}}`
Commit: ${{github.sha}}
- name: Update comment
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
Staging application has been deployed and is available at: https://${{secrets.DASH_ENTERPRISE_URL}}/${{secrets.APP_NAME}}-staging
Production app name: `${{secrets.APP_NAME}}`
Current branch name: `${{github.head_ref}}`
Commit: ${{github.sha}}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:server --workers 4 --preload