|
| 1 | +name: Build and Deploy API war file |
| 2 | +permissions: |
| 3 | + contents: write |
| 4 | + id-token: write |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + environment: |
| 9 | + description: env to build war file |
| 10 | + type: choice |
| 11 | + default: dev |
| 12 | + options: |
| 13 | + - dev |
| 14 | + - prod |
| 15 | + environment_target: |
| 16 | + description: target environment |
| 17 | + type: choice |
| 18 | + default: Ddev |
| 19 | + options: |
| 20 | + - dev |
| 21 | + - prod |
| 22 | + code_branch: |
| 23 | + description: branch to build |
| 24 | + required: true |
| 25 | + default: main |
| 26 | +run-name: "Build WARs for ${{ github.event.inputs.environment }} (branch: ${{ github.event.inputs.code_branch }}, target: ${{ github.event.inputs.environment_target }})" |
| 27 | +jobs: |
| 28 | + build: |
| 29 | + name: Build war file |
| 30 | + runs-on: cbiit-global-runners |
| 31 | + environment: ${{ inputs.environment }} |
| 32 | + env: |
| 33 | + CODE_BRANCH: "${{ github.event.inputs.code_branch }}" |
| 34 | + outputs: |
| 35 | + artifact-name: hpc-api-artifacts |
| 36 | + steps: |
| 37 | + - name: check git installation |
| 38 | + run: git --version |
| 39 | + |
| 40 | + - name: Checkout Code Repository |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + #ref: ${{ github.event.inputs.code_branch }} |
| 44 | + ref: ${{ env.CODE_BRANCH }} |
| 45 | + - name: Set up Java |
| 46 | + uses: actions/setup-java@v4 |
| 47 | + with: |
| 48 | + distribution: 'corretto' |
| 49 | + java-version: '21' |
| 50 | + cache: 'maven' |
| 51 | + - name: set up maven |
| 52 | + uses: stCarolas/setup-maven@v4.5 |
| 53 | + with: |
| 54 | + maven-version: '3.9.4' |
| 55 | + - name: build the war |
| 56 | + run: | |
| 57 | + #cd HPC_DME_APIs/src |
| 58 | + cd $GITHUB_WORKSPACE/src |
| 59 | + mvn clean install -D${{ github.event.inputs.environment_target }} |
| 60 | + - name: upload artifacts for deployment job |
| 61 | + uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: hpc-api-artifacts |
| 64 | + path: | |
| 65 | + src/hpc-server/hpc-ws-rs-impl/target/*.war |
| 66 | + src/hpc-server/hpc-scheduler/target/*.war |
| 67 | + src/hpc-server/hpc-scheduler-migration/target/*.war |
| 68 | +
|
| 69 | + deploy: |
| 70 | + needs: build |
| 71 | + runs-on: cbiit-global-runners |
| 72 | + steps: |
| 73 | + - name: Download Artifacts |
| 74 | + uses: actions/download-artifact@v4 |
| 75 | + with: |
| 76 | + name: hpc-api-artifacts |
| 77 | + path: ./artifacts |
| 78 | + |
| 79 | + - name: list downloaded artifacts |
| 80 | + run: | |
| 81 | + ls -R ./artifacts || echo "Artifacts not found!" |
| 82 | +
|
| 83 | + - name: Set up SSH |
| 84 | + run: | |
| 85 | + mkdir -p ~/.ssh |
| 86 | + echo "${{ secrets.TOMCAT_SSH_KEY }}" > ~/.ssh/id_rsa |
| 87 | + chmod 600 ~/.ssh/id_rsa |
| 88 | + ssh-keyscan -H ${{ secrets.TOMCAT_HOST }} >> ~/.ssh/known_hosts |
| 89 | +
|
| 90 | + - name: deploy tomcat |
| 91 | + env: |
| 92 | + remote_user: ${{ secrets.REMOTE_USER }} |
| 93 | + remote: ${{ secrets.TOMCAT_HOST }} |
| 94 | + tomcat_home: /local/content/tomcat/ncifhpcdmsvcp |
| 95 | + dist: /local/content/tomcat/ncifhpcdmsvcp/webapps |
| 96 | + remote_tomcat: tomcat-ncifhpcdmsvcp |
| 97 | + app: hpc-server |
| 98 | + app1: hpc-scheduler |
| 99 | + app2: hpc-scheduler-migration |
| 100 | + unit: hpc-server.war |
| 101 | + unit1: hpc-scheduler.war |
| 102 | + unit2: hpc-scheduler-migration.war |
| 103 | + run: | |
| 104 | + set -xe |
| 105 | + echo "Stopping tomcat" |
| 106 | + ssh -qt $remote_user@$remote "sudo /sbin/service $remote_tomcat stop" |
| 107 | + echo "Cleaning old backups and symlinks..." |
| 108 | + ssh -qt ${remote_user}@${remote} " umask 022; cd ${dist} && if [ -d ${app} ]; then rm -rf ${app}; fi ; " |
| 109 | + ssh -qt ${remote_user}@${remote} " umask 022; cd ${dist} && if [ -d ${app1} ]; then rm -rf ${app1}; fi ; " |
| 110 | + ssh -qt ${remote_user}@${remote} " umask 022; cd ${dist} && if [ -d ${app2} ]; then rm -rf ${app2}; fi ; " |
| 111 | + ssh -qt ${remote_user}@${remote} " cd ${dist}; rm -f hpc-server-[0-9]*.war_backup* hpc-server-[0-9]*.war.backup*; rm -f hpc-scheduler-[0-9]*.war_backup* hpc-scheduler-[0-9]*.war.backup*; rm -f hpc-scheduler-migration-[0-9]*.war_backup* hpc-scheduler-migration-[0-9]*.war.backup* " |
| 112 | + ssh -qt ${remote_user}@${remote} " cd ${dist} && if [ -L ${unit} ]; then rm -f ${unit}; else echo "No symlink found"; fi ; " |
| 113 | + ssh -qt ${remote_user}@${remote} " cd ${dist} && if [ -L ${unit1} ]; then rm -f ${unit1}; else echo "No symlink found"; fi ; " |
| 114 | + ssh -qt ${remote_user}@${remote} " cd ${dist} && if [ -L ${unit2} ]; then rm -f ${unit2}; else echo "No symlink found"; fi ; " |
| 115 | + ssh -qt ${remote_user}@${remote} " export TZ='America/New_York'; cd ${dist}; find -type f -name ${app}-*.war -exec mv {} {}_backup_$(date +%Y%m%d.%H%M) \; && find -type f -name ${app1}-[0-9]*.war -exec mv {} {}_backup_$(date +%Y%m%d.%H%M) \; && find -type f -name ${app2}-*.war -exec mv {} {}_backup_$(date +%Y%m%d.%H%M) \;" || exit $? |
| 116 | + echo "upoading wars to remote server" |
| 117 | + scp -pq artifacts/hpc-ws-rs-impl/target/${app}-*.war ${remote_user}@${remote}:${dist} |
| 118 | + scp -pq artifacts/hpc-scheduler/target/${app1}-*.war ${remote_user}@${remote}:${dist} |
| 119 | + scp -pq artifacts/hpc-scheduler-migration/target/${app2}-*.war ${remote_user}@${remote}:${dist} |
| 120 | + echo "creating symlink" |
| 121 | + ssh -qt ${remote_user}@${remote} " cd ${dist} && ln -s $app-*.war ${unit}; cd ${dist} && ln -s $app1-[0-9]*.war ${unit1}; cd ${dist} && ln -s $app2-*.war ${unit2}" |
| 122 | + echo "restart tomcat" |
| 123 | + ssh -qt ${remote_user}@${remote} " sudo /sbin/service $remote_tomcat start" |
0 commit comments