-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9657 from hmislk/#9642_Report_Upload_(Out_Source)
- Loading branch information
Showing
12 changed files
with
685 additions
and
136 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: DEV Deployment Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev-ci-cd-setup | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
|
||
- name: Cache Maven Packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.m2 | ||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Build with Maven | ||
run: mvn clean package -DskipTests | ||
|
||
- name: Archive Build Artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: build-artifacts | ||
path: target/*.war | ||
|
||
# - name: Run Tests | ||
# run: mvn test | ||
|
||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download Build Artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: build-artifacts | ||
path: ./ | ||
|
||
- name: Deploy to Payara | ||
env: | ||
SERVER_IP: ${{ secrets.SERVER_IP }} | ||
SERVER_USER: ${{ secrets.SERVER_USER }} | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
PAYARA_ADMIN_PASS: ${{ secrets.PAYARA_ADMIN_PASS }} | ||
run: | | ||
# Add SSH private key to the SSH agent | ||
echo "$SSH_PRIVATE_KEY" > private_key.pem | ||
chmod 600 private_key.pem | ||
# Variables | ||
WAR_NAME="hmis.war" | ||
WAR_DIR="~/app/latest" | ||
# Ensure deployment directory exists | ||
ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " | ||
mkdir -p $WAR_DIR | ||
cd $WAR_DIR | ||
# Remove old backup if it exists | ||
if [ -f $WAR_NAME.old ]; then | ||
rm $WAR_NAME.old | ||
fi | ||
# If the current WAR file exists, back it up | ||
if [ -f $WAR_NAME ]; then | ||
mv $WAR_NAME $WAR_NAME.old | ||
fi | ||
" | ||
# Copy new WAR file to the server | ||
rsync -aL --progress -e "ssh -i private_key.pem" ./*.war $SERVER_USER@$SERVER_IP:$WAR_DIR/$WAR_NAME | ||
# Deploy the WAR using asadmin | ||
ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " | ||
echo 'AS_ADMIN_PASSWORD=${{ secrets.PAYARA_ADMIN_PASS }}' > /tmp/payara-admin-pass.txt | ||
/opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt undeploy sethmademo || true | ||
/opt/payara5/bin/asadmin --user admin --passwordfile /tmp/payara-admin-pass.txt deploy --force $WAR_DIR/$WAR_NAME | ||
rm /tmp/payara-admin-pass.txt | ||
" | ||
# Validate if the application is running | ||
ssh -i private_key.pem -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP " | ||
STATUS=\$(/opt/payara5/bin/asadmin list-applications | grep 'sethmademo') | ||
if echo \"$STATUS\" | grep -q 'running'; then | ||
echo 'Application is running.' | ||
else | ||
echo 'Application failed to start.' >&2 | ||
exit 1 | ||
fi | ||
" | ||
# Verify that the application is reachable via HTTP | ||
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://$SERVER_IP/sethmademo) | ||
if [ "$RESPONSE_CODE" != "200" ]; then | ||
echo "Application is not reachable at http://$SERVER_IP/sethmademo (HTTP $RESPONSE_CODE)" >&2 | ||
exit 1 | ||
fi | ||
# Cleanup | ||
rm -f private_key.pem |
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
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
Oops, something went wrong.