From cc89ad6d0a292e2cbfc82e0ec09866df39f1a909 Mon Sep 17 00:00:00 2001 From: heyethereum Date: Mon, 17 Jun 2024 23:42:45 +0800 Subject: [PATCH] set portforwarding netcat --- .github/workflows/workflow.yml | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a515490..6ceb0c4 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -35,14 +35,6 @@ jobs: - 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 @@ -56,16 +48,28 @@ 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: Upload Chunks to EC2 + - name: Start `nc` on EC2 to Listen and Save File 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 + 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 -p 1234 > /home/app-0.0.1-SNAPSHOT.jar"]' - - name: Reassemble Chunks on EC2 + - name: Start SSM Port Forwarding + id: start-ssm-port-forwarding 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" + 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 - 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"]' \ No newline at end of file + 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"]' + + +