Skip to content

Commit

Permalink
Update docker-ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
pingowl authored Apr 10, 2024
1 parent 69ddc56 commit 4dc30e8
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정
build-docker-image:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: checkout
Expand Down Expand Up @@ -64,6 +64,31 @@ jobs:
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/drugbox-grad

# 6. EC2 보안그룹에 Github Actions 추가
- name: Get Github action IP
id: ip
uses: haythem/[email protected]

- name: Setting environment variables
run: |
echo "AWS_DEFAULT_REGION=ap-northeast-2" >> $GITHUB_ENV
echo "AWS_SG_NAME=launch-wizard-2" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-name ${{ secrets.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2


# Deploy Images with Docker compose
- name: executing remote ssh commands using password
Expand All @@ -82,3 +107,12 @@ jobs:
sudo docker-compose -f $COMPOSE down
sudo docker pull ${{ secrets.DOCKER_REPO }}/drugbox-grad
sudo docker-compose -f $COMPOSE up -d
- name: Remove Github Actions IP from security group
run: |
aws ec2 revoke-security-group-ingress --group-name ${{ secrets.AWS_SG_NAME }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-2

0 comments on commit 4dc30e8

Please sign in to comment.