forked from nhnacademy-be6-AA/buzz-book-front-server
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (75 loc) · 2.74 KB
/
maven.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: JAVA CI with Maven
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
env:
IMAGE_NAME: parkseol/front-server
TAG: latest
run: |
docker build -t $IMAGE_NAME:$TAG .
docker push $IMAGE_NAME:$TAG
deploy1:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Deploy to Front Server 1
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
docker pull parkseol/front-server:latest
docker stop front-server-1 || true
docker rm front-server-1 || true
docker run -d --name front-server-1 --network api_network -p 8081:8081 -e SPRING_PROFILES_ACTIVE=prod parkseol/front-server:latest
deploy2:
runs-on: ubuntu-latest
needs: deploy1
steps:
- name: Deploy to Front Server 2
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
docker pull parkseol/front-server:latest
docker stop front-server-2 || true
docker rm front-server-2 || true
docker run -d --name front-server-2 --network api_network -p 8082:8082 -e SPRING_PROFILES_ACTIVE=prod2 parkseol/front-server:latest