File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy Next.js App to EC2
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ env :
9+ DOCKER_IMAGE : wonchang0314/growit-fe:latest
10+ CONTAINER_NAME : growit-next
11+
12+ jobs :
13+ build-and-deploy :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout code
18+ uses : actions/checkout@v3
19+
20+ - name : Log in to Docker Hub
21+ uses : docker/login-action@v3
22+ with :
23+ username : ${{ secrets.DOCKER_HUB_USERNAME }}
24+ password : ${{ secrets.DOCKER_HUB_PASSWORD }}
25+
26+ # ## Docker 이미지 빌드 & 푸시
27+ - name : Build and push Docker image
28+ run : |
29+ docker build -t $DOCKER_IMAGE .
30+ docker push $DOCKER_IMAGE
31+
32+ # ## EC2에 SSH 접속하여 Docker pull 및 재시작
33+ - name : SSH to EC2 and deploy
34+ uses : appleboy/ssh-action@v1.0.3
35+ with :
36+ host : ${{ secrets.EC2_HOST }}
37+ username : ${{ secrets.EC2_USER }}
38+ key : ${{ secrets.EC2_SSH_KEY }}
39+ script : |
40+ docker pull $DOCKER_IMAGE
41+ docker stop $CONTAINER_NAME || true
42+ docker rm $CONTAINER_NAME || true
43+ docker run -d --name $CONTAINER_NAME -p 3000:3000 $DOCKER_IMAGE
You can’t perform that action at this time.
0 commit comments