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

Automated Linode deployment for production and staging #55

Merged
merged 2 commits into from
Aug 29, 2024
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
18 changes: 18 additions & 0 deletions .github/workflows/deploy_development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: deploy_development

on:
push:
branches:
- 'development'

jobs:
deploy_staging:
uses: ./.github/workflows/linode-deployment.yml
with:
ENV_NAME: development
WEB_SERVER_PATH: '~/webui-staging/'
PORT: '8001'
secrets:
LINODE_IP: ${{ secrets.LINODE_IP }}
USER: ${{ secrets.USER }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
18 changes: 18 additions & 0 deletions .github/workflows/deploy_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: deploy_production

on:
push:
branches:
- 'master'

jobs:
deploy_production:
uses: ./.github/workflows/linode-deployment.yml
with:
ENV_NAME: master
WEB_SERVER_PATH: '~/webui-production/'
PORT: '8000'
secrets:
LINODE_IP: ${{ secrets.LINODE_IP }}
USER: ${{ secrets.USER }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
14 changes: 0 additions & 14 deletions .github/workflows/docker-build.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/docker-compose.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/integration-test.yml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/linode-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: linode-deployment

on:
workflow_call:
inputs:
ENV_NAME:
required: true
type: string
WEB_SERVER_PATH:
required: true
type: string
PORT:
required: true
type: string
secrets:
LINODE_IP:
required: true
USER:
required: true
PRIVATE_KEY:
required: true

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Set up SSH connection
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{secrets.PRIVATE_KEY}}

- name: List added SSH keys (for debugging)
run: ssh-add -l

- name: Deploy to Linode instance
env:
LINODE_IP: ${{secrets.LINODE_IP}}
USER: ${{secrets.USER}}
WEB_SERVER_PATH: ${{inputs.WEB_SERVER_PATH}}
ENV_NAME: ${{inputs.ENV_NAME}}
PORT: ${{inputs.PORT}}
run: |
echo "Starting deployment for ${ENV_NAME} environment on port ${PORT}"

ssh -v -o StrictHostKeyChecking=no $USER@$LINODE_IP << EOF
set -e
echo "Connected to Linode server"
echo "Deploying for ${ENV_NAME} branch"

cd $WEB_SERVER_PATH
if [ ! -d ".git" ]; then
echo "Error: .git directory not found in $WEB_SERVER_PATH"
exit 1
fi
git pull origin $ENV_NAME || { echo 'Git pull for ${ENV_NAME} failed'; exit 1; }
echo "Successfully updated ${ENV_NAME} code"
echo "Accessing management-ui directory"
cd $WEB_SERVER_PATH/management-ui
pkill -f "uvicorn.*${PORT}" || echo "No process to kill on port ${PORT}"
echo "Clearing port ${PORT}"

nohup uvicorn server:app --host 127.0.0.1 --port ${PORT} > ${WEB_SERVER_PATH}/nohup.out 2>&1 &
echo "Activated FastAPI server for ${ENV_NAME} environment on port ${PORT}"

echo "Deployment completed."
EOF