Skip to content

Commit d342be8

Browse files
Merge pull request #33 from TeamLearningFlow/main
merge
2 parents 11a4ce3 + a6c9a68 commit d342be8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/main.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI/CD for Spring Boot App
2+
3+
on:
4+
push:
5+
branches:
6+
- deploy
7+
8+
jobs:
9+
docker:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# Checkout the repository
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
# Log in to Docker Hub
18+
- name: Log in to Docker Hub
19+
uses: docker/login-action@v2
20+
with:
21+
username: ${{ secrets.DOCKERHUB_USERNAME }}
22+
password: ${{ secrets.DOCKERHUB_TOKEN }}
23+
24+
# Set up Docker Buildx
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v2
27+
28+
# Build and push Docker image
29+
- name: Build and push
30+
uses: docker/build-push-action@v4
31+
with:
32+
context: .
33+
file: ./Dockerfile
34+
push: true
35+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
36+
37+
deploy:
38+
runs-on: ubuntu-latest
39+
needs: [docker]
40+
41+
steps:
42+
# SSH Connect and Docker Image Pull and Container Run
43+
- name: SSH Connect and Docker Image Pull and Container Run
44+
uses: appleboy/ssh-action@v1.0.0
45+
with:
46+
host: ${{ secrets.EC2_HOST }}
47+
username: ${{ secrets.EC2_USER }}
48+
key: ${{ secrets.EC2_SSH_KEY }}
49+
port: 22
50+
script: |
51+
docker stop my-was || true
52+
docker rm my-was || true
53+
docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }} || true
54+
docker run -d -p 8080:8080 \
55+
-v /root/my-proj/resources:/app/resources \
56+
--name my-was ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}

0 commit comments

Comments
 (0)