Skip to content

Commit

Permalink
deploy ec2 instance directly
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed Dec 2, 2024
1 parent 7366d2d commit 747f0a4
Showing 1 changed file with 65 additions and 9 deletions.
74 changes: 65 additions & 9 deletions .github/workflows/report.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,73 @@
# name: Generate Data Usage Report
#
# on:
# pull_request:
# branches:
# - main
#
---
name: Generate Data Usage Report

on:
pull_request:
branches:
- main


jobs:
generate-jobs-usage-report:
runs-on: ubuntu-latest

steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Launch EC2 Instance
id: launch_ec2
run: |
INSTANCE_ID=$(aws ec2 run-instances \
--image-id ami-0c02fb55956c7d316 \
--count 1 \
--instance-type t3.micro \
--key-name dandihub-gh-actions \
--security-group-ids sg-xxxxxxxx \
--subnet-id subnet-xxxxxxxx \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=EC2dfTest}]" \
--query 'Instances[0].InstanceId' --output text)
echo "INSTANCE_ID=${INSTANCE_ID}" >> $GITHUB_ENV
- name: Wait for EC2 to Initialize
run: |
aws ec2 wait instance-status-ok --instance-ids ${{ env.INSTANCE_ID }}
- name: Retrieve EC2 Public IP
id: get_ip
run: |
PUBLIC_IP=$(aws ec2 describe-instances \
--instance-ids ${{ env.INSTANCE_ID }} \
--query 'Reservations[0].Instances[0].PublicIpAddress' --output text)
echo "PUBLIC_IP=${PUBLIC_IP}" >> $GITHUB_ENV
- name: Execute df Command on EC2
uses: appleboy/[email protected]
with:
host: ${{ env.PUBLIC_IP }}
username: ec2-user
key: ${{ secrets.EC2_SSH_KEY }}
script: |
echo "Running df command on EC2 instance..."
df -h
echo "Command completed."
- name: Terminate EC2 Instance
run: |
aws ec2 terminate-instances --instance-ids ${{ env.INSTANCE_ID }}
aws ec2 wait instance-terminated --instance-ids ${{ env.INSTANCE_ID }}
# jobs:
# generate_data_usage_report:
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
#
# - name: Log in to DockerHub
# uses: docker/login-action@v2
Expand Down

0 comments on commit 747f0a4

Please sign in to comment.