Skip to content

chore: ec2 테스트 커넥션 스크립트 #10

chore: ec2 테스트 커넥션 스크립트

chore: ec2 테스트 커넥션 스크립트 #10

Workflow file for this run

name: cicd
on:
push:
branches: [ "dev", "main", "deploy/init" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
# - uses: actions/checkout@v4
# 이 아래 애들은 deploy 스텝에서 적용해야될듯?
- name: Get Gihub Actions VM IP
id: ip
uses: haythem/public-ip@v1.3
- name: Print VM IP
run: |
echo ${{ steps.ip.outputs.ipv4 }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_IAM_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_IAM_ACCESS_SECRET_KEY }}
aws-region: 'ap-northeast-2'
- name: Add GitHub Actions IP
run: |
aws ec2 authorize-security-group-ingress \
--group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \
--protocol tcp \
--port 22 \
--cidr ${{ steps.ip.outputs.ipv4 }}/32
- name: Test EC2 Connection And Manipulation
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.EC2_ELASTIC_IP }}
key: ${{ secrets.EC2_SSH_KEY }}
script_stop: true
script: |
echo "[✔] GitHub Actions Connection Success" | tee -a ~/cicd-log.txt
echo "Time: $(date '+%Y-%m-%d %H:%M:%S')" | tee -a ~/cicd-log.txt
echo "Branch: ${{ github.ref_name }}" | tee -a ~/cicd-log.txt
echo "Commit: ${{ github.sha }}" | tee -a ~/cicd-log.txt
echo "-------------------------------" | tee -a ~/cicd-log.txt
- name: Remove GitHub Actions IP
run: |
aws ec2 revoke-security-group-ingress \
--group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \
--protocol tcp \
--port 22 \
--cidr ${{ steps.ip.outputs.ipv4 }}/32
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
# - name: Build with Gradle Wrapper
# run: ./gradlew build