diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index dcb7dbf..c45e52c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -35,6 +35,10 @@ jobs: - name: Build with Maven run: mvn -B package --file pom.xml + - name: Split JAR into Chunks + run: | + split -b 10M target/app-0.0.1-SNAPSHOT.jar target/chunk_ + - name: Configure AWS Credentials id: configure-aws-credentials uses: aws-actions/configure-aws-credentials@v4 @@ -48,28 +52,17 @@ jobs: 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: Start `nc` on EC2 to Listen and Save File + - name: Upload Chunks to EC2 run: | - aws ssm send-command --instance-ids ${{ env.INSTANCE_ID }} --document-name "AWS-RunShellScript" --comment "Start netcat to listen and save file" --parameters 'commands=["sudo nc -l 1234 > /home/app-0.0.1-SNAPSHOT.jar"]' + for file in target/chunk_*; do + aws ssm send-command --instance-ids ${{ env.INSTANCE_ID }} --document-name "AWS-RunShellScript" --comment "Upload chunk" --parameters commands="echo \"$(cat $file)\" > /home/ec2-user/$(basename $file)" + done - - name: Start SSM Port Forwarding - id: start-ssm-port-forwarding + - name: Reassemble Chunks on EC2 run: | - aws ssm start-session --target ${{ env.INSTANCE_ID }} --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["1234"],"localPortNumber":["1234"]}' & - sleep 10 - - - name: Install netcat locally - run: sudo apt-get install -y netcat - - - name: Send File to EC2 - run: | - echo "Sending JAR file to EC2 instance..." - nc -w 3 127.0.0.1 1234 < target/app-0.0.1-SNAPSHOT.jar - continue-on-error: false + 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/app-0.0.1-SNAPSHOT.jar"]' - - + 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"]'