Skip to content

Commit c39a87e

Browse files
CI/CD
1 parent 5035229 commit c39a87e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

.github/workflows/ci.yml

Whitespace-only changes.

.github/workflows/deploy.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

0 commit comments

Comments
 (0)