Skip to content

Commit c33e47d

Browse files
committed
chore: cd workflow 생성
1 parent 1f12284 commit c33e47d

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Deploy to Develop
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
env:
9+
DOCKERHUB_USERNAME: ht3064
10+
DOCKERHUB_IMAGE_NAME: syncfit-server
11+
12+
jobs:
13+
build-deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '17'
24+
distribution: 'temurin'
25+
26+
- name: Grant execute permission for gradlew
27+
run: chmod +x ./gradlew
28+
29+
- name: Build with Gradle
30+
run: ./gradlew clean build -x test
31+
32+
- name: Login to DockerHub
33+
uses: docker/login-action@v2
34+
with:
35+
username: ${{ env.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
37+
38+
- name: Extract metadata for Docker
39+
id: metadata
40+
uses: docker/metadata-action@v4
41+
with:
42+
images: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
43+
tags: |
44+
type=sha,prefix=
45+
46+
- name: Build and Push Docker image
47+
uses: docker/build-push-action@v4.1.1
48+
with:
49+
context: .
50+
push: true
51+
tags: ${{ steps.metadata.outputs.tags }}
52+
53+
- name: Copy docker-compose.yml to EC2
54+
uses: appleboy/scp-action@v0.1.4
55+
with:
56+
host: ${{ secrets.EC2_HOST }}
57+
username: ${{ secrets.EC2_USERNAME }}
58+
key: ${{ secrets.EC2_SSH_KEY }}
59+
source: docker-compose.yml
60+
target: /home/ubuntu/
61+
62+
- name: Deploy to EC2
63+
uses: appleboy/ssh-action@master
64+
env:
65+
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }}
66+
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }}
67+
with:
68+
host: ${{ secrets.EC2_HOST }}
69+
username: ${{ secrets.EC2_USERNAME }}
70+
key: ${{ secrets.EC2_SSH_KEY }}
71+
envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME
72+
script: |
73+
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin
74+
docker compose up -d
75+
docker image prune -a -f

0 commit comments

Comments
 (0)