diff --git a/.github/workflows/build-deploy-dev.yml b/.github/workflows/build-deploy-dev.yml deleted file mode 100644 index 4351322b..00000000 --- a/.github/workflows/build-deploy-dev.yml +++ /dev/null @@ -1,189 +0,0 @@ - -name: BitcoinDeepaBot Deployment - Dev - -on: - push: - branches: - - dev - -defaults: - run: - working-directory: . - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - env: - GO_VERSION: "1.21" - PROJECT_NAME: "⚡ BitcoinDeepaBot - Dev" - DEPLOY_PATH: "/root/projects/ceyloncash/bitcoin-deepa/dev/" - PROJECT_DIR: "bitcoin-deepa-bot" - SERVICE_NAME: "bitcoin_deepa_bot_dev.service" - BINARY_NAME: "BitcoinDeepaBot" - - steps: - - name: Notify Build Start - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=${PROJECT_NAME} Build Started 🚀 - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE}" - - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Notify Build Complete - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=${PROJECT_NAME} Code Checked Out 📦 - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE}" - - # ✅ Check if .git directory exists remotely - - name: Check if Git Exists on Server - id: check_git - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - port: ${{ secrets.SERVER_PORT }} - script: | - if [ -d "${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }}/.git" ]; then - echo "true" - else - echo "false" - fi - - # ✅ Capture the above output - - name: Set git_exists output - id: set_git_output - run: echo "::set-output name=git_exists::$(echo '${{ steps.check_git.outputs.stdout }}' | tr -d '\r')" - - - name: Copy Files to Server - if: steps.set_git_output.outputs.git_exists == 'false' - uses: appleboy/scp-action@master - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - port: ${{ secrets.SERVER_PORT }} - source: "." - target: "${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }}" - strip_components: 1 - rm: true - - - name: Deploy Application - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - port: ${{ secrets.SERVER_PORT }} - script: | - cd ${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }} - - # Handle git repository - pull if .git exists, otherwise fresh deployment - if [ -d ".git" ]; then - echo "Git repository exists, pulling latest changes..." - git fetch origin - git reset --hard origin/dev - git clean -fd - else - echo "Fresh deployment - no git repository found" - fi - - # Set Go environment - export PATH=$PATH:/usr/local/go/bin - export GOPATH=$HOME/go - export GOOS=linux - export GOARCH=amd64 - - # Build the application on the server - echo "Building application on server..." - go mod download - go mod verify - CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -buildvcs=false -o ${{ env.BINARY_NAME }} . - - # Make binary executable - chmod +x ${{ env.BINARY_NAME }} - - # Update service definition - sudo bash -c 'cat > "/etc/systemd/system/${{ env.SERVICE_NAME }}" <<- EOM - [Unit] - Description=${{ env.PROJECT_NAME }} - After=network.target - - [Service] - Type=simple - Restart=always - RestartSec=5s - WorkingDirectory=${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }} - ExecStart=${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }}/${{ env.BINARY_NAME }} - Environment=HOME=/root - User=root - - [Install] - WantedBy=multi-user.target - EOM' - - # Create data directory if it doesn't exist - mkdir -p data/dalle - - # Reload systemd and restart service - sudo systemctl daemon-reload - sudo systemctl enable ${{ env.SERVICE_NAME }} - sudo systemctl restart ${{ env.SERVICE_NAME }} - - # Wait a moment and check service status - sleep 3 - sudo systemctl status ${{ env.SERVICE_NAME }} --no-pager - - - name: Notify Deploy Complete - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=${PROJECT_NAME} Deploy Complete ✅ - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE}" - - - name: Notify Deploy Failure - if: failure() - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=❌ ${PROJECT_NAME} Deploy Failed! - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE} - - Please check the GitHub Actions logs for more details." diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml deleted file mode 100644 index 138e7066..00000000 --- a/.github/workflows/build-deploy.yml +++ /dev/null @@ -1,189 +0,0 @@ -name: BitcoinDeepaBot Deployment - Prod - -on: - push: - branches: - - main - -defaults: - run: - working-directory: . - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - env: - GO_VERSION: "1.21" - PROJECT_NAME: "⚡ BitcoinDeepaBot - Prod" - DEPLOY_PATH: "/root/projects/ceyloncash/bitcoin-deepa/prod/" - PROJECT_DIR: "bitcoin-deepa-bot" - SERVICE_NAME: "bitcoin_deepa_bot_prod.service" - BINARY_NAME: "BitcoinDeepaBot" - - steps: - - name: Notify Build Start - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=${PROJECT_NAME} Build Started 🚀 - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE}" - - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Notify Build Complete - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=${PROJECT_NAME} Code Checked Out 📦 - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE}" - - # ✅ Check if .git directory exists remotely - - name: Check if Git Exists on Server - id: check_git - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - port: ${{ secrets.SERVER_PORT }} - script: | - if [ -d "${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }}/.git" ]; then - echo "true" - else - echo "false" - fi - - # ✅ Capture the above output - - name: Set git_exists output - id: set_git_output - run: echo "::set-output name=git_exists::$(echo '${{ steps.check_git.outputs.stdout }}' | tr -d '\r')" - - - - name: Copy Files to Server - if: steps.set_git_output.outputs.git_exists == 'false' - uses: appleboy/scp-action@master - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - port: ${{ secrets.SERVER_PORT }} - source: "." - target: "${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }}" - strip_components: 1 - rm: true - - - name: Deploy Application - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USERNAME }} - key: ${{ secrets.SERVER_KEY }} - port: ${{ secrets.SERVER_PORT }} - script: | - cd ${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }} - - # Handle git repository - pull if .git exists, otherwise fresh deployment - if [ -d ".git" ]; then - echo "Git repository exists, pulling latest changes..." - git fetch origin - git reset --hard origin/main - git clean -fd - else - echo "Fresh deployment - no git repository found" - fi - - # Set Go environment - export PATH=$PATH:/usr/local/go/bin - export GOPATH=$HOME/go - export GOOS=linux - export GOARCH=amd64 - - # Build the application on the server - echo "Building application on server..." - go mod download - go mod verify - CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o ${{ env.BINARY_NAME }} . - - # Make binary executable - chmod +x ${{ env.BINARY_NAME }} - - # Update service definition - sudo bash -c 'cat > "/etc/systemd/system/${{ env.SERVICE_NAME }}" <<- EOM - [Unit] - Description=${{ env.PROJECT_NAME }} - After=network.target - - [Service] - Type=simple - Restart=always - RestartSec=5s - WorkingDirectory=${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }} - ExecStart=${{ env.DEPLOY_PATH }}${{ env.PROJECT_DIR }}/${{ env.BINARY_NAME }} - Environment=HOME=/root - User=root - - [Install] - WantedBy=multi-user.target - EOM' - - # Create data directory if it doesn't exist - mkdir -p data/dalle - - # Reload systemd and restart service - sudo systemctl daemon-reload - sudo systemctl enable ${{ env.SERVICE_NAME }} - sudo systemctl restart ${{ env.SERVICE_NAME }} - - # Wait a moment and check service status - sleep 3 - sudo systemctl status ${{ env.SERVICE_NAME }} --no-pager - - - name: Notify Deploy Complete - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=${PROJECT_NAME} Deploy Complete ✅ - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE}" - - - name: Notify Deploy Failure - if: failure() - env: - TELEGRAM_BOT_TOKEN: ${{ secrets.DEV_ACTIONS_BOT_TOKEN }} - TELEGRAM_CHAT_ID: ${{ secrets.DEV_ACTIONS_GROUP_ID }} - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} - COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }} - run: | - curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ - --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ - --data-urlencode "text=❌ ${PROJECT_NAME} Deploy Failed! - 📁 Repository: ${GITHUB_REPOSITORY} - 👤 Initiator: ${GITHUB_ACTOR} - 🕒 Timestamp: ${COMMIT_TIMESTAMP} - 📝 Commit Message: ${COMMIT_MESSAGE} - - Please check the GitHub Actions logs for more details."