Ansible GitHub action and DevOps වැඩ්ඩනි පොඩි උදව්වක් ඔනේ

DevOps_Boy

Active member
  • Jul 28, 2023
    238
    120
    43
    මම මේ දවස් වල ඔෆිස් එකේ ප්‍රොජෙක්ට් එකක හිර වෙලා ඉන්නේ. මට මේකට මේකෙ ඉන්න DevOps engineers or මෙවා ගැන දන්න කවුරු හරි උදව්වක් දෙන්නකෝ. මේකයි case එක.
    මට NodeJS application එකක් තියනවා ගිට් එකෙන් කෝඩ් එක අරන් බිල්ඩ් කරලා remote server එකකට deploy කරන්න. අනිත් එක තමයි ගිට් රිපෝ එකක තියන war files දෙකක් අරන් ඒකත් tomcat Apache (inside of the webapp directory) එකක ඩිප්ලෝයි කරන්න. හැබැයි ඊට කලින් ඩේටබේස් එකෙයි තව directories කීපයක බැකප් ග්න්නත් ඔනේ. ඒකට මම ඇන්සිබ්ල් script එක්කින් කරන්න බැලුවේ. හැබැයි මේ සිටුවේශන් දෙකම එක පාර ඒ කිව්වෙ සම්හර වෙලාවට NodeJS or WAR file දෙකෙන් එකක් හෝ දෙකම එක පාර deploy කරන්න පුලුව්න් වෙන්නත් ඔනේ ඒ කිව්වෙ මට ඒක චූස් කරන්න තිබ්බොත් හොදයි.. හැබැයි මේකේ ගිට් URL දෙකක් තියෙන්නෙ. එකක UI and එකක WAR file තියනවා. මම දැනට ට්‍ර්යි කලේ මන් ගාව තිය්නව github self runner server එකක්. ඒකට ansible දාලා එකෙන් කරන්න බැලුවේ. එත් එකේදි මාර එරර්ස් ගොඩක් එන්වා. මම දැනට ජිතබ් එකේ github action ස්ක්‍රිප්ට් එකක් හදලා එකෙන් ansible script එක run කරලා බැලුවට errors එනවා මාරෙට. මට හිතගන්න බැරුව ඉන්නේ. මම ට්‍ර්‍යි කරපු github action script එකයි ansible script එකයි දන්නම් පහලින්. මට දැනගනන් ඔනේ මේක කරන්න තව effective widiyak thiyeda? නැත්තම් මේකෙ මොන්වද අඩුපාඩු?
    guys මට මේක ගොඩ දාගන්න පොඩි සප් එකක් දෙන්නකෝ.

    Github Action Script
    YAML:
    name: Integrated Deployment
    
    on:
      push:
        branches:
          - main
    
    jobs:
      deploy_and_backup:
        runs-on: self-hosted
    
        env:
          #TARGET_SERVER_IP: ${{ secrets.TARGET_SERVER_IP }}
          UI_REPOSITORY: "https://github.com/dev-test/Daily_Releases_UI.git"
          WAR_REPOSITORY: "https://github.com/dev-test/Daily_Releases_WAR.git"
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
            with:
              repository: dev-test/Daily_Releases_UI
              ref: ${{ github.event.before }}
    
    
          - name: Run Ansible playbook for backup
            run: ansible-playbook /etc/ansible/playbook/backup.yml
    
          - name: Deploy NodeJS Application or War files
            run: |
              if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/main" ]; then
                if [ "${{ inputs.deployment-type }}" == "UI" ] || [ "${{ inputs.deployment-type }}" == "Both" ]; then
                  # Your NodeJS deployment steps here
                  echo "Deploying NodeJS Application..."
                  steps:
                    - name: Get code
                      uses: actions/checkout@v4
                    - name: Install NodeJS
                      uses: actions/setup-node@v3
                      with:
                        node-version: 10
                    - name: Install dependencies
                      run: NODE_OPTIONS=--max_old_space_size=4096 npm install
                    - name: Check Nodejs
                      run: npx browserslist@latest --update-db
                    - name: Build project
                      run: NODE_OPTIONS=--max_old_space_size=4096 npm run build
                    - name: Deploy to the server.
                      uses: easingthemes/ssh-deploy@main
                      with:
                        SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_DEPLOYER_TESTING }}
                        SOURCE: "build/*"
                        REMOTE_HOST: "50.35.45.55"
                        REMOTE_USER: "deployer"
                        TARGET: "/var/www/html/"
                fi
              fi
              if [ "${{ github.event_name }}" == "repository_dispatch" ] && [ "${{ inputs.deployment-type }}" == "War" ]; then
                # Your War files deployment steps here
                echo "Deploying War files..."
                git clone --branch ${{ github.event.client_payload.branch }} ${{ env.WAR_REPOSITORY }} /tmp/war-files
                # Continue with your War files deployment steps using the contents in /tmp/war-files
                rsync -av /tmp/war-files/ [email protected]:/usr/local/tomcat/webapps/
                ssh -i ${{ secrets.SSH_PRIVATE_KEY_DEPLOYER_TESTING }} -p 22 [email protected] "cd /usr/local/tomcat/bin && ./shutdown.sh && ./startup.sh"
              fi
     

    Janatha Jhon

    Well-known member
  • Nov 24, 2023
    10,570
    14,444
    113
    මම මේ දවස් වල ඔෆිස් එකේ ප්‍රොජෙක්ට් එකක හිර වෙලා ඉන්නේ. මට මේකට මේකෙ ඉන්න DevOps engineers or මෙවා ගැන දන්න කවුරු හරි උදව්වක් දෙන්නකෝ. මේකයි case එක.
    මට NodeJS application එකක් තියනවා ගිට් එකෙන් කෝඩ් එක අරන් බිල්ඩ් කරලා remote server එකකට deploy කරන්න. අනිත් එක තමයි ගිට් රිපෝ එකක තියන war files දෙකක් අරන් ඒකත් tomcat Apache (inside of the webapp directory) එකක ඩිප්ලෝයි කරන්න. හැබැයි ඊට කලින් ඩේටබේස් එකෙයි තව directories කීපයක බැකප් ග්න්නත් ඔනේ. ඒකට මම ඇන්සිබ්ල් script එක්කින් කරන්න බැලුවේ. හැබැයි මේ සිටුවේශන් දෙකම එක පාර ඒ කිව්වෙ සම්හර වෙලාවට NodeJS or WAR file දෙකෙන් එකක් හෝ දෙකම එක පාර deploy කරන්න පුලුව්න් වෙන්නත් ඔනේ ඒ කිව්වෙ මට ඒක චූස් කරන්න තිබ්බොත් හොදයි.. හැබැයි මේකේ ගිට් URL දෙකක් තියෙන්නෙ. එකක UI and එකක WAR file තියනවා. මම දැනට ට්‍ර්යි කලේ මන් ගාව තිය්නව github self runner server එකක්. ඒකට ansible දාලා එකෙන් කරන්න බැලුවේ. එත් එකේදි මාර එරර්ස් ගොඩක් එන්වා. මම දැනට ජිතබ් එකේ github action ස්ක්‍රිප්ට් එකක් හදලා එකෙන් ansible script එක run කරලා බැලුවට errors එනවා මාරෙට. මට හිතගන්න බැරුව ඉන්නේ. මම ට්‍ර්‍යි කරපු github action script එකයි ansible script එකයි දන්නම් පහලින්. මට දැනගනන් ඔනේ මේක කරන්න තව effective widiyak thiyeda? නැත්තම් මේකෙ මොන්වද අඩුපාඩු?
    guys මට මේක ගොඩ දාගන්න පොඩි සප් එකක් දෙන්නකෝ.

    Github Action Script
    YAML:
    name: Integrated Deployment
    
    on:
      push:
        branches:
          - main
    
    jobs:
      deploy_and_backup:
        runs-on: self-hosted
    
        env:
          #TARGET_SERVER_IP: ${{ secrets.TARGET_SERVER_IP }}
          UI_REPOSITORY: "https://github.com/dev-test/Daily_Releases_UI.git"
          WAR_REPOSITORY: "https://github.com/dev-test/Daily_Releases_WAR.git"
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
            with:
              repository: dev-test/Daily_Releases_UI
              ref: ${{ github.event.before }}
    
    
          - name: Run Ansible playbook for backup
            run: ansible-playbook /etc/ansible/playbook/backup.yml
    
          - name: Deploy NodeJS Application or War files
            run: |
              if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/main" ]; then
                if [ "${{ inputs.deployment-type }}" == "UI" ] || [ "${{ inputs.deployment-type }}" == "Both" ]; then
                  # Your NodeJS deployment steps here
                  echo "Deploying NodeJS Application..."
                  steps:
                    - name: Get code
                      uses: actions/checkout@v4
                    - name: Install NodeJS
                      uses: actions/setup-node@v3
                      with:
                        node-version: 10
                    - name: Install dependencies
                      run: NODE_OPTIONS=--max_old_space_size=4096 npm install
                    - name: Check Nodejs
                      run: npx browserslist@latest --update-db
                    - name: Build project
                      run: NODE_OPTIONS=--max_old_space_size=4096 npm run build
                    - name: Deploy to the server.
                      uses: easingthemes/ssh-deploy@main
                      with:
                        SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_DEPLOYER_TESTING }}
                        SOURCE: "build/*"
                        REMOTE_HOST: "50.35.45.55"
                        REMOTE_USER: "deployer"
                        TARGET: "/var/www/html/"
                fi
              fi
              if [ "${{ github.event_name }}" == "repository_dispatch" ] && [ "${{ inputs.deployment-type }}" == "War" ]; then
                # Your War files deployment steps here
                echo "Deploying War files..."
                git clone --branch ${{ github.event.client_payload.branch }} ${{ env.WAR_REPOSITORY }} /tmp/war-files
                # Continue with your War files deployment steps using the contents in /tmp/war-files
                rsync -av /tmp/war-files/ [email protected]:/usr/local/tomcat/webapps/
                ssh -i ${{ secrets.SSH_PRIVATE_KEY_DEPLOYER_TESTING }} -p 22 [email protected] "cd /usr/local/tomcat/bin && ./shutdown.sh && ./startup.sh"
              fi
    කොටහා කීයද ?
     

    Don GasCan

    Well-known member
  • Nov 3, 2010
    43,333
    49,712
    113
    සේදවත්ත
    Ansible get url module eken oya git එකේ තියන දෙක ඇදල කරන්න බැරිද ?

    තව ඇන්සිබල් ගිට් මොඩුයුල් එකක් තියනවා .

    ඩොකුමන්ට් දෙකම රීඩ් කරන්න.

    ඔය මොඩුයුල් දෙකෙන් එකක් භාවිත කරලා කරන්න පුලුවන් ලේසියෙන්
     

    nevermindNevergiveup

    Well-known member
  • Jul 28, 2017
    28,435
    36,355
    113
    මැදමහනුවර
    a1f8745a-439f-44bb-8ad9-6d3d2635b9d0-removebg-preview.png