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

workflows-cont #25

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
31 changes: 26 additions & 5 deletions .github/workflows/deploy_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Create .ssh directory
run: |
echo "Creating .ssh directory..."
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo ".ssh directory created."

- name: Install SSH keys
run: |
Expand All @@ -21,27 +28,41 @@ jobs:
chmod 700 ~/.ssh
echo "${{ secrets.EC2_PRIVATE_KEY }}" | tr -d '\r' > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
echo "SSH key file created and permissions set."
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
echo "SSH keys installed."
echo "SSH host key added to known_hosts."
env:
EC2_PRIVATE_KEY: ${{ secrets.EC2_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}

- name: Debug List .ssh directory contents
run: |
echo "Listing ~/.ssh directory contents..."
ls -la ~/.ssh
cat ~/.ssh/id_ed25519
echo "Done listing ~/.ssh directory contents."

- name: Test SSH connection
run: |
echo "Testing SSH connection..."
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "echo 'SSH connection successful'"
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}

- name: Create .ssh directory on remote server
run: |
echo "Creating .ssh directory on remote server..."
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "mkdir -p ~/.ssh && chmod 700 ~/.ssh"
echo ".ssh directory created on remote server."

- name: Pull latest code
- name: Pull latest code on remote server
run: |
echo "Pulling latest code from remote repository..."
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ 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
- name: Manage Docker Compose on remote server
run: |
echo "Managing Docker Compose on remote server..."
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
Expand All @@ -58,7 +79,7 @@ jobs:
EOF
echo "Docker Compose managed successfully."

- name: Cleanup SSH keys
- name: Cleanup SSH keys on GitHub runner
run: |
echo "Cleaning up SSH keys..."
rm -rf ~/.ssh/id_ed25519
Expand Down
Loading