-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from LL08-MathematicalModelling-dowell/DOCKERI…
…ZED_V2 Improved github action comamands
- Loading branch information
Showing
1 changed file
with
77 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
@@ -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 |