Skip to content

Commit d20c116

Browse files
committed
chore: ci-cd 파이프라인 구축
1 parent 3f713d0 commit d20c116

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CI/CD using github actions & docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
CI-CD:
13+
runs-on: ubuntu-latest
14+
name: Build
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up JDK 21
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '21'
24+
distribution: 'temurin'
25+
26+
- name: Cache Gradle packages
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.gradle/caches
31+
~/.gradle/wrapper
32+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
33+
restore-keys: |
34+
${{ runner.os }}-gradle-
35+
36+
- name: Grant execute permission for gradlew
37+
run: chmod +x gradlew
38+
39+
- name: Create application.properties
40+
run: |
41+
echo "${{ secrets.APPLICATION }}" > src/main/resources/application.properties
42+
43+
- name: Create application-prod.properties
44+
run: |
45+
echo "${{ secrets.APPLICATION_PROD }}" > src/main/resources/application-prod.properties
46+
47+
- name: Build with Gradle
48+
run: ./gradlew clean build
49+
50+
- name: Login to Docker Hub
51+
uses: docker/login-action@v3
52+
with:
53+
username: ${{ secrets.DOCKER_USERNAME }}
54+
password: ${{ secrets.DOCKER_PASSWORD }}
55+
56+
- name: Build and push Docker image
57+
run: |
58+
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/wibby:${{ github.sha }} .
59+
docker push ${{ secrets.DOCKER_USERNAME }}/wibby:${{ github.sha }}
60+
61+
- name: Deploy to EC2
62+
uses: appleboy/[email protected]
63+
with:
64+
host: ${{ secrets.EC2_HOST }}
65+
username: ${{ secrets.EC2_USER }}
66+
key: ${{ secrets.EC2_PRIVATE_KEY }}
67+
script: |
68+
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/wibby:${{ github.sha }}
69+
docker stop wibby || true
70+
docker rm wibby || true
71+
docker run -d -p 8080:80 \
72+
-e SPRING_DATA_REDIS_HOST=${{ secrets.REDIS_HOST }} \
73+
-e SPRING_DATA_REDIS_PORT=${{ secrets.REDIS_PORT }} \
74+
-e SPRING_DATA_REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }} \
75+
-e SPRING_PROFILES_ACTIVE=prod \
76+
--name wibby \
77+
${{ secrets.DOCKER_USERNAME }}/wibby:${{ github.sha }}

0 commit comments

Comments
 (0)