Skip to content

Merge pull request #9 from LL08-MathematicalModelling-dowell/DOCKERIZ… #10

Merge pull request #9 from LL08-MathematicalModelling-dowell/DOCKERIZ…

Merge pull request #9 from LL08-MathematicalModelling-dowell/DOCKERIZ… #10

Workflow file for this run

name: DataCube CI/CD deployment workflow
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
name: Deploy to VPS
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the latest code
- name: Checkout code
uses: actions/checkout@v2
# Cleanup SSH Directory
- name: Cleanup SSH Directory
run: rm -rf ~/.ssh
# Install SSH Key
- name: Install SSH Key
uses: shimataro/[email protected]
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
# Remove the placeholder known_hosts entry
known_hosts: "just-a-placeholder-so-we-dont-get-errors"
# Adding Known Hosts
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
# Connect to Server and Deploy
- name: Connect to Server, Pull Latest Code, and Rebuild Containers with Docker Script
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "\
set -e && \
echo 'Current directory: $(pwd)' && \
cd ${{ secrets.WORK_DIR }} && \
git checkout main && \
git pull && \
mkdir -p ~/it_works && \
docker-compose down && docker-compose up -d --build
exit"
# Cleanup SSH Keys
- name: Cleanup SSH Keys
run: rm -rf ~/.ssh
# Step 3: Deploy using SSH and Docker Compose
- name: Deploy using SSH and Docker Compose
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << EOF
cd ${{ secrets.WORK_DIR }}
# Pull the latest code from GitHub
git pull origin main
mkdir -p ~/it_works
# Build and restart the services using Docker Compose
docker-compose down && docker-compose up -d --build
EOF
# Cleanup SSH Keys
- name: Cleanup SSH Keys
run: rm -rf ~/.ssh