debug statement added to see if SSH is successful. #8
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: Deploy Jupyter Book to AWS EC2 | |
on: | |
push: | |
branches: | |
- master | |
- docs | |
jobs: | |
deploy-book: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
- name: Install dependencies | |
run: | | |
pip install -r docs/requirements.txt | |
- name: Cache executed notebooks | |
uses: actions/cache@v4 | |
with: | |
path: docs/_build/.jupyter_cache | |
key: jupyter-book-cache-${{ hashFiles('docs/requirements.txt') }} | |
- name: Build the book | |
run: | | |
jupyter-book build docs/ | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.EC2_SSH_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -v -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts || echo "ssh-keyscan failed, continuing..." | |
- name: Debug SSH Info | |
run: | | |
echo "Checking SSH configuration..." | |
echo "EC2_HOST value length: ${#EC2_HOST}" | |
echo "EC2_USER value length: ${#EC2_USER}" | |
echo "SSH key exists: $(test -f ~/.ssh/id_rsa && echo 'Yes' || echo 'No')" | |
echo "SSH key permissions: $(ls -l ~/.ssh/id_rsa)" | |
echo "Known hosts file: $(cat ~/.ssh/known_hosts)" | |
env: | |
EC2_HOST: "${{ secrets.EC2_HOST }}" | |
EC2_USER: "${{ secrets.EC2_USER }}" | |
- name: Deploy to AWS EC2 | |
env: | |
EC2_USER: "${{ secrets.EC2_USER }}" | |
EC2_HOST: "${{ secrets.EC2_HOST }}" | |
run: | | |
if [ -z "$EC2_USER" ] || [ -z "$EC2_HOST" ]; then | |
echo "Error: EC2_USER or EC2_HOST is empty" | |
exit 1 | |
fi | |
echo "Starting deployment to ${EC2_HOST}..." | |
# Install and configure Apache | |
echo "Installing Apache..." | |
if ssh -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" "sudo apt-get update && sudo apt-get install -y apache2"; then | |
echo "✓ Apache installation successful" | |
else | |
echo "× Apache installation failed" | |
exit 1 | |
fi | |
# Create directory and set permissions | |
echo "Creating directory and setting permissions..." | |
if ssh -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" "sudo mkdir -p /var/www/html/jupyterbook_8040/ && sudo chown -R ${EC2_USER}:${EC2_USER} /var/www/html/jupyterbook_8040/"; then | |
echo "✓ Directory setup successful" | |
else | |
echo "× Directory setup failed" | |
exit 1 | |
fi | |
# Copy files | |
echo "Copying files..." | |
if scp -r -o StrictHostKeyChecking=no docs/_build/html/* "${EC2_USER}@${EC2_HOST}:/var/www/html/jupyterbook_8040/"; then | |
echo "✓ File copy successful" | |
else | |
echo "× File copy failed" | |
exit 1 | |
fi | |
# Configure and restart Apache | |
echo "Configuring and restarting Apache..." | |
if ssh -o StrictHostKeyChecking=no "${EC2_USER}@${EC2_HOST}" "sudo sed -i 's/Listen 80/Listen 8040/' /etc/apache2/ports.conf && sudo systemctl restart apache2"; then | |
echo "✓ Apache configuration and restart successful" | |
else | |
echo "× Apache configuration failed" | |
exit 1 | |
fi | |
echo "✓ Deployment completed successfully!" | |
- name: Cleanup SSH key | |
run: rm -f ~/.ssh/id_rsa |