Skip to content

Commit

Permalink
Merge pull request #55 from 5G-MAG/feature/automated-deployment
Browse files Browse the repository at this point in the history
Automated Linode deployment for production and staging
  • Loading branch information
stojkovicv authored Aug 29, 2024
2 parents 028cb60 + bcd0528 commit 95d4406
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 65 deletions.
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

0 comments on commit 95d4406

Please sign in to comment.