Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/CD] ec2에 배포하는 CD #3

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Java CI with Gradle
name: CI/CD

on:
push:
Expand Down Expand Up @@ -59,4 +59,24 @@ jobs:

# DockerHub 이미지 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mercury-server
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/mercury-server

deploy:
needs: build
runs-on: ubuntu-latest

steps:
# EC2에 배포
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/mercury-server
docker stop $(docker ps -q) || true
docker rm $(docker ps -a -q) || true
# 사용하지 않는 이미지 정리
docker image prune -f
docker run -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/mercury-server
Loading