71 lines
2.9 KiB
YAML
71 lines
2.9 KiB
YAML
name: Deploy jar to EC2
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
|
|
permissions:
|
|
id-token: write # This is required for requesting the JWT
|
|
contents: read # This is required for actions/checkout
|
|
|
|
jobs:
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
cache: maven
|
|
|
|
|
|
- name: Create application-local.properties file
|
|
run: |
|
|
echo "spring.datasource.url=${{ secrets.DB_URL }}" >> src/main/resources/application-local.properties
|
|
echo "spring.datasource.username=${{ secrets.DB_USERNAME }}" >> src/main/resources/application-local.properties
|
|
echo "spring.datasource.password=${{ secrets.DB_PASSWORD }}" >> src/main/resources/application-local.properties
|
|
echo "spring.datasource.driver-class-name=${{ secrets.DB_DRIVER }}" >> src/main/resources/application-local.properties
|
|
echo "spring.jpa.hibernate.ddl-auto=update" >> src/main/resources/application-local.properties
|
|
echo "spring.jpa.show-sql=true" >> src/main/resources/application-local.properties
|
|
|
|
- name: Build with Maven
|
|
run: mvn -B package --file pom.xml
|
|
|
|
- name: Split and Encode JAR into Chunks
|
|
run: |
|
|
mkdir -p chunks
|
|
split -b 10M target/app-0.0.1-SNAPSHOT.jar chunks/chunk_
|
|
for file in chunks/chunk_*; do
|
|
base64 $file > ${file}.b64
|
|
done
|
|
|
|
- name: Configure AWS Credentials
|
|
id: configure-aws-credentials
|
|
uses: aws-actions/configure-aws-credentials@v4
|
|
with:
|
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE }}
|
|
aws-region: ${{ secrets.AWS_REGION }}
|
|
|
|
- name: Get Instance ID
|
|
id: get_instance_id
|
|
run: |
|
|
INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=safeqr-ec2" --query "Reservations[0].Instances[0].InstanceId" --output text)
|
|
echo "INSTANCE_ID=$INSTANCE_ID" >> $GITHUB_ENV
|
|
|
|
- name: Upload Chunks to EC2
|
|
run: |
|
|
for file in chunks/chunk_*.b64; do
|
|
aws ssm send-command --instance-ids ${{ env.INSTANCE_ID }} --document-name "AWS-RunShellScript" --comment "Upload chunk" --parameters commands="echo $(cat $file) | base64 --decode > /home/ec2-user/$(basename ${file%.b64})"
|
|
done
|
|
|
|
- name: Reassemble Chunks on EC2
|
|
run: |
|
|
aws ssm send-command --instance-ids ${{ env.INSTANCE_ID }} --document-name "AWS-RunShellScript" --comment "Reassemble chunks" --parameters commands="cat /home/ec2-user/chunk_* > /home/ec2-user/app-0.0.1-SNAPSHOT.jar"
|
|
|
|
- name: Verify File on EC2
|
|
run: |
|
|
aws ssm send-command --instance-ids ${{ env.INSTANCE_ID }} --document-name "AWS-RunShellScript" --comment "Verify JAR file" --parameters 'commands=["ls -l /home/ec2-user/app-0.0.1-SNAPSHOT.jar"]' |