Merge pull request #12 from LL08-MathematicalModelling-dowell/DOCKERI… #13
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
# 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: | |
- main | |
workflow_dispatch: | |
jobs: | |
deploy: | |
name: Deploy and Rebuild Containers | |
runs-on: ubuntu-latest | |
steps: | |
- name: Echo New Changes | |
run: echo 'New changes made to main' | |
# 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" | |
# known_hosts: ${{ secrets.SSH_HOST }} | |
- name: Install SSH Key | |
uses: shimataro/[email protected] | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
strict: false | |
- 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.WORKING_DIR }} && \ | |
git checkout main && \ | |
git pull && \ | |
docker-compose down && docker-compose up -d --build | |
# docker-compose pull | |
mkdir -p ~/it_works | |
# echo "Github action file succesfull!!!" | |
exit" | |
- name: Cleanup SSH Keys | |
run: rm -rf ~/.ssh |