-
Notifications
You must be signed in to change notification settings - Fork 1
58 lines (48 loc) Β· 1.78 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# github repository actions νμ΄μ§μ λνλ μ΄λ¦
name: CI/CD using github actions & docker
# event trigger
# main λΈλμΉμ pushκ° λμμ λ μ€ν
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Create application.yml
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml
cat ./src/main/resources/application.yml
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PWD }}
docker buildx build --push --platform linux/amd64 -t ${{ secrets.DOCKER_IMAGE_NAME }} .
# docker build -t ${{ secrets.DOCKER_IMAGE_NAME }} .
# docker push ${{ secrets.DOCKER_IMAGE_NAME }}
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER_NAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo docker image prune -af
sudo docker pull ${{ secrets.DOCKER_IMAGE_NAME }}
sudo docker stop chat-server-1
sudo docker run -d --rm --name chat-server-1 -p 8080:8080 ${{ secrets.DOCKER_IMAGE_NAME }}
sleep 10
sudo docker stop chat-server-2
sudo docker run -d --rm --name chat-server-2 -p 8081:8080 ${{ secrets.DOCKER_IMAGE_NAME }}