-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ permissions: | |
jobs: | ||
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정 | ||
build-docker-image: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: checkout | ||
|
@@ -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 | ||
|
@@ -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 |