-
Notifications
You must be signed in to change notification settings - Fork 2
109 lines (95 loc) · 4.08 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Java CI/CD with Gradle
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop"]
types: [ closed ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
env:
PROFILE: ${{ secrets.PROFILE }}
DB_PROD_HOST: ${{ secrets.DB_PROD_HOST }}
DB_PROD_USERNAME: ${{ secrets.DB_PROD_USERNAME }}
DB_PROD_PASSWD: ${{ secrets.DB_PROD_PASSWD }}
WAS_HOST: ${{ secrets.WAS_HOST }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
CLIENT_ID: ${{ secrets.CLIENT_ID }}
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ap-northeast-2
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew --warning-mode all build -i
docker-build:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle (without Test)
run: ./gradlew clean build -x test --stacktrace
- name: Docker Hub build & push
run: |
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PWD }}
docker build --build-arg PROFILE=${{ secrets.PROFILE }} \
--build-arg DB_PROD_HOST=${{ secrets.DB_PROD_HOST }} \
--build-arg DB_PROD_USERNAME=${{ secrets.DB_PROD_USERNAME }} \
--build-arg DB_PROD_PASSWD=${{ secrets.DB_PROD_PASSWD }} \
--build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \
--build-arg CLIENT_ID=${{ secrets.CLIENT_ID }} \
--build-arg AWS_S3_BUCKET_NAME=${{ secrets.AWS_S3_BUCKET_NAME }} \
--build-arg AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
--build-arg AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
--build-arg AWS_REGION=ap-northeast-2 \
-t likelion12/likelion12baby:latest .
docker images
docker push likelion12/likelion12baby:latest
- name: deploy
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.WAS_HOST }}
key: ${{ secrets.PRIVATE_KEY }}
port: ${{ secrets.WAS_PORT }}
script: |
echo "Checking Docker installation..."
CONTAINER_ID=$(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }})
if [ ! -z "$CONTAINER_ID" ]; then
echo "Docker could not be found, installing Docker"
sudo docker stop $CONTAINER_ID
sudo docker rm $CONTAINER_ID
fi
echo "Pulling Docker image..."
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}
sudo docker run -d -e PROFILE=${{ secrets.PROFILE }} \
-e DB_PROD_HOST=${{ secrets.DB_PROD_HOST }} \
-e DB_PROD_USERNAME=${{ secrets.DB_PROD_USERNAME }} \
-e DB_PROD_PASSWD=${{ secrets.DB_PROD_PASSWD }} \
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \
-e CLIENT_ID=${{ secrets.CLIENT_ID }} \
-e AWS_S3_BUCKET_NAME=${{ secrets.AWS_S3_BUCKET_NAME }} \
-e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \
-e AWS_REGION=ap-northeast-2 \
-p 8080:8080 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}
sudo docker logs $(sudo docker ps -q —filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }})
sudo docker image prune -f