File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy to EC2
2+
3+ on :
4+ push :
5+ branches : [ "main" ]
6+
7+ jobs :
8+ deploy :
9+ runs-on : ubuntu-latest
10+
11+ steps :
12+ - name : Checkout
13+ uses : actions/checkout@v4
14+
15+ - name : Set up Docker Buildx
16+ uses : docker/setup-buildx-action@v3
17+
18+ - name : Login to Docker Hub
19+ uses : docker/login-action@v3
20+ with :
21+ username : ${{ secrets.DOCKERHUB_USERNAME }}
22+ password : ${{ secrets.DOCKERHUB_TOKEN }}
23+
24+ - name : Build and push Docker image
25+ uses : docker/build-push-action@v6
26+ with :
27+ context : .
28+ push : true
29+ tags : |
30+ ${{ secrets.DOCKERHUB_USERNAME }}/waffle-toy-project:latest
31+ ${{ secrets.DOCKERHUB_USERNAME }}/waffle-toy-project:${{ github.sha }}
32+
33+ - name : Deploy on EC2 via SSH
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 compose pull
41+ docker compose up -d
42+ docker image prune -f
You can’t perform that action at this time.
0 commit comments