ci: update to staging environemnt #3
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: CD — Deploy Ollama Stack | |
| on: | |
| push: | |
| branches: [ "main", "production" ] | |
| paths: | |
| - "ollama/**" | |
| - ".github/**" | |
| workflow_dispatch: # Trigger manual dari GitHub Actions UI | |
| jobs: | |
| deploy-ollama: | |
| name: Deploy Ollama Stack via SSH | |
| runs-on: ubuntu-latest | |
| environment: staging | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Copy Ollama Docker Compose file via SCP | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| port: ${{ secrets.SERVER_PORT || '22' }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| source: "ollama/docker-compose.yml" | |
| target: "${{ vars.DEPLOY_PATH_OLLAMA || secrets.DEPLOY_PATH_OLLAMA || format('/home/{0}/mini-grafana-ollama', secrets.SERVER_USER) }}" | |
| - name: Deploy Ollama Stack to Server via SSH | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| port: ${{ secrets.SERVER_PORT || '22' }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script_stop: true | |
| script: | | |
| echo "==========================================================" | |
| echo " [1/3] Menentukan direktori dan Git Pull (Ollama)" | |
| echo "==========================================================" | |
| DEPLOY_DIR="${{ vars.DEPLOY_PATH_OLLAMA || secrets.DEPLOY_PATH_OLLAMA || format('/home/{0}/mini-grafana-ollama', secrets.SERVER_USER) }}" | |
| echo "Directori ollama deployment: $DEPLOY_DIR" | |
| mkdir -p "$DEPLOY_DIR" | |
| cd "$DEPLOY_DIR" || exit 1 | |
| # Jika ini repositori git atau folder tersendiri: | |
| if [ -d ".git" ]; then | |
| git fetch --all | |
| git reset --hard origin/main | |
| fi | |
| echo "==========================================================" | |
| echo " [2/3] Menulis file .env dari secret ENV_OLLAMA" | |
| echo "==========================================================" | |
| cat <<'EOF_ENV' > .env | |
| ${{ secrets.ENV_OLLAMA }} | |
| EOF_ENV | |
| chmod 600 .env | |
| echo "==========================================================" | |
| echo " [3/3] Merestart Container Ollama LLM" | |
| echo "==========================================================" | |
| docker network inspect proxy_network >/dev/null 2>&1 || docker network create proxy_network | |
| cd ollama && docker compose up -d --force-recreate | |
| echo "✅ Deployment Ollama Stack selesai!" |