Deploy to SSH Server #42
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 to SSH Server | |
on: | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install SSH key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
- name: SSH and Deploy | |
run: | | |
ssh -i ~/.ssh/id_rsa ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF' | |
cd /fossbot-platform | |
sudo git fetch origin | |
sudo git reset --hard origin/master | |
sudo rm -f .env | |
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" | sudo tee -a .env > /dev/null | |
echo "ADMIN_USERNAME=${{ secrets.ADMIN_USERNAME }}" | sudo tee -a .env > /dev/null | |
echo "ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }}" | sudo tee -a .env > /dev/null | |
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" | sudo tee -a .env > /dev/null | |
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" | sudo tee -a .env > /dev/null | |
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" | sudo tee -a .env > /dev/null | |
echo "DATABASE=postgresql://${{secrets.POSTGRES_USER}}:${{secrets.POSTGRES_PASSWORD}}@db:5432/${{secrets.POSTGRES_DB}}" | sudo tee -a .env > /dev/null | |
echo "MATOMO_DATABASE_HOST=db" | sudo tee -a .env > /dev/null | |
echo "MATOMO_DATABASE_ADAPTER=pgsql" | sudo tee -a .env > /dev/null | |
echo "MATOMO_DATABASE_TABLES_PREFIX=matomo_" | sudo tee -a .env > /dev/null | |
echo "MATOMO_DATABASE_USERNAME=${{secrets.POSTGRES_USER}}" | sudo tee -a .env > /dev/null | |
echo "MATOMO_DATABASE_PASSWORD=${{secrets.POSTGRES_PASSWORD}}" | sudo tee -a .env > /dev/null | |
echo "MATOMO_DATABASE_DBNAME=matomo_db" | sudo tee -a .env > /dev/null | |
sudo docker compose -f docker-compose-production.yml down | |
sudo docker compose -f docker-compose-production.yml build --no-cache | |
sudo docker compose -f docker-compose-production.yml up -d | |
EOF |