Skip to content

Commit

Permalink
Merge pull request #10 from LL08-MathematicalModelling-dowell/DOCKERI…
Browse files Browse the repository at this point in the history
…ZED_V2

Improved github action comamands
  • Loading branch information
Goldeno10 authored Oct 15, 2024
2 parents 717329e + b2591d5 commit ba12139
Showing 1 changed file with 77 additions and 34 deletions.
111 changes: 77 additions & 34 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
name: DataCube CI/CD deployment workflow
# 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

# # THIS IS THE ACTUAL WORKFLOW FILE CONTENT
# - name: Cleanup SSH Directory
# run: rm -rf ~/.ssh

# - name: Install SSH Key
# uses: shimataro/[email protected]
# with:
# key: ${{ secrets.SSH_PRIVATE_KEY }}
# known_hosts: 'just-a-placeholder-so-we-dont-get-errors'

# - name: Adding Known Hosts
# run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts

# - 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

# # echo "Github action file succesfull!!!"
# exit"
# - name: Cleanup SSH Keys
# run: rm -rf ~/.ssh

# # Step 3: Deploy to the VPS
# - 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
# # docker-compose pull

# # Run migrations and collect static files
# # docker-compose exec web python manage.py migrate
# # docker-compose exec web python manage.py collectstatic --noinput
# EOF
# - name: Cleanup SSH Keys
# run: rm -rf ~/.ssh

name: DataCube CI/CD deployment workflow
on:
push:
branches:
Expand All @@ -8,62 +75,38 @@ on:

jobs:
deploy:
name: Deploy to VPS
name: Deploy and Rebuild Containers
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the latest code
- name: Checkout code
uses: actions/checkout@v2
- name: Echo New Changes
run: echo 'New changes made to main'

# Cleanup SSH Directory
# THIS IS THE ACTUAL WORKFLOW FILE CONTENT
- 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 }} && \
cd ${{ secrets.WORKING_DIR }} && \
git checkout main && \
git pull && \
mkdir -p ~/it_works && \
docker-compose down && docker-compose up -d --build
docker-compose down && docker-compose up -d --build
# docker-compose pull
mkdir -p ~/it_works
# echo "Github action file succesfull!!!"
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

0 comments on commit ba12139

Please sign in to comment.