Improve API key creation with better error handling and switch to Bas… #210
This file contains hidden or 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 to Production | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # Cache SSH configuration | |
| - name: Cache SSH configuration | |
| uses: actions/cache@v3 | |
| id: ssh-cache | |
| with: | |
| path: ~/.ssh | |
| key: ssh-config-${{ runner.os }}-v1 | |
| - name: Set up SSH | |
| uses: webfactory/[email protected] | |
| with: | |
| ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| - name: Add server to known hosts | |
| if: steps.ssh-cache.outputs.cache-hit != 'true' | |
| run: | | |
| mkdir -p ~/.ssh | |
| # Create SSH config file with custom port and user | |
| cat > ~/.ssh/config << EOF | |
| Host profullstack.com 104.36.23.197 | |
| HostName 104.36.23.197 | |
| User ubuntu | |
| Port 2048 | |
| EOF | |
| chmod 600 ~/.ssh/config | |
| # Run ssh-keyscan with the correct port | |
| ssh-keyscan -p 2048 -T 60 104.36.23.197 > /tmp/known_hosts_entry | |
| # Check if ssh-keyscan succeeded | |
| if [ -s /tmp/known_hosts_entry ]; then | |
| cat /tmp/known_hosts_entry >> ~/.ssh/known_hosts | |
| chmod 644 ~/.ssh/known_hosts | |
| else | |
| echo "${{ secrets.SERVER_KNOWN_HOSTS }}" > ~/.ssh/known_hosts | |
| chmod 644 ~/.ssh/known_hosts | |
| fi | |
| # Note: Apt package caching removed to fix permission issues | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update -qq | |
| sudo apt-get install -y --no-install-recommends rsync zsh curl file golang postgresql-client gnome-keyring dbus-x11 | |
| # Set up dbus for gnome-keyring | |
| mkdir -p ~/.cache | |
| dbus-launch --sh-syntax > ~/.cache/dbus-env | |
| source ~/.cache/dbus-env | |
| # Initialize the keyring | |
| echo -n "password" | gnome-keyring-daemon --unlock | |
| # Export environment variables for subsequent steps | |
| echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" >> $GITHUB_ENV | |
| - name: Create .env file from secret | |
| run: | | |
| # Create .env file from GitHub secret | |
| echo "${{ secrets.ENV_FILE_CONTENT }}" > .env | |
| echo "Created .env file with $(grep -c '' .env) lines" | |
| - name: Prepare for deployment | |
| run: | | |
| # Make scripts executable | |
| chmod +x ./bin/supabase-db.sh | |
| chmod +x ./bin/deploy.sh | |
| chmod +x ./bin/deploy-with-migrations.sh | |
| - name: Deploy to server with migrations | |
| run: | | |
| # Run deploy script with migrations | |
| ./bin/deploy-with-migrations.sh | |
| # Explicitly copy the .env file to the remote server | |
| echo "Copying .env file to remote server..." | |
| scp -P 2048 .env [email protected]:$DEPLOY_REMOTE_DIR/.env | |
| # Create a timestamp file to verify deployment | |
| echo "Creating timestamp file to verify deployment..." | |
| TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S") | |
| ssh -p 2048 [email protected] "echo 'GitHub Actions deployment completed at $TIMESTAMP' > $DEPLOY_REMOTE_DIR/github-actions-test-$(date +%Y%m%d%H%M%S).txt" | |
| env: | |
| DEPLOY_REMOTE_HOST: 104.36.23.197 | |
| DEPLOY_REMOTE_PORT: 2048 | |
| DEPLOY_REMOTE_USER: ubuntu | |
| DEPLOY_REMOTE_DIR: www/convert2doc.com/pdf | |
| INSTALL_SERVICE: true |