Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft of .github/workflows/deploy_on_push.yml #18

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/deploy_on_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
push:
branches:
- main

jobs:
run_pull:
name: Run Pull and Manage Containers
runs-on: ubuntu-latest

steps:
- name: Install SSH keys
run: |
echo "Installing SSH keys..."
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
echo "SSH keys installed."

- name: Connect and pull latest code
run: |
echo "Pulling latest code from remote repository..."
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.WORK_DIR }} && git checkout ${{ secrets.MAIN_BRANCH }} && git pull"
echo "Code pulled successfully."

- name: Manage Docker Compose on Remote Server
run: |
echo "Managing Docker Compose on remote server..."
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
echo "Stopping and removing Docker containers..."
cd ${{ secrets.WORK_DIR }}
docker-compose down
echo "Removing Docker images..."
docker rmi file_uploader-backend:latest || true
docker rmi file_uploader-frontend:latest || true
echo "Starting Docker containers..."
docker-compose up -d
echo "Containers started."
EOF
echo "Docker Compose managed successfully."

- name: Cleanup SSH keys
run: |
echo "Cleaning up SSH keys..."
rm -rf ~/.ssh
echo "SSH keys cleaned up."

Loading