feat: docker-compose 버전 명시 삭제 #12
Workflow file for this run
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
name: ShowPot-Dev-CD | |
on: | |
push: | |
branches: | |
- feat-cd-dev | |
jobs: | |
build-and-docker-hub-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'liberica' | |
cache: gradle | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Copy Secrets | |
env: | |
ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} | |
SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} | |
run: | |
echo $ACCESS_KEY > ./app/src/main/resources/application-dev.yml | |
echo $SECRET_KEY > ./app/src/main/resources/application-dev.yml | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build | |
- name: Prepare File for Deployment | |
run: | | |
mkdir -p deployment | |
cp Dockerfile docker-compose.yml deployment/ | |
cp -r ./app/build/libs deployment/ | |
- name: Get Github Actions IP | |
id: ip | |
uses: haythem/[email protected] | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ap-northeast-2 | |
- name: Add Github Actions IP on Security Group | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SECURITY_GROUP_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
- name: Upload files to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_DEV_HOST }} | |
username: ec2-user | |
key: ${{ secrets.EC2_DEV_SSH_PRIVATE_KEY }} | |
source: "deployment/*" | |
target: "/home/ec2-user/" | |
- name: Deploy using Docker Compose | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_DEV_HOST }} | |
username: ec2-user | |
key: ${{ secrets.EC2_DEV_SSH_PRIVATE_KEY }} | |
script: | | |
cd /home/ec2-user/deployment/ | |
docker-compose down | |
docker-compose up -d --build | |
- name: Remove Github Actions IP from Security Group | |
if: always() | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SECURITY_GROUP_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 |