-
Notifications
You must be signed in to change notification settings - Fork 3
93 lines (82 loc) · 3.98 KB
/
cicd.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
name: Build and Deploy
on:
push:
branches:
- Fix/#58
pull_request:
branches:
- develop
types:
- closed
jobs:
build:
# if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
host port: 3306
container port: 3306
mysql database: ${{ secrets.SPRING_DATASOURCE_NAME }}
mysql root password: ${{ secrets.SPRING_DATASOURCE_PASSWORD }}
- name: Checkout
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 ./wabi/gradlew
- name: Set environment values
run: |
touch ./wabi/src/main/resources/env.properties
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" >> ./env.properties
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" >> ./env.properties
echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" >> ./env.properties
echo "JWT_KEY=${{ secrets.JWT_KEY }}" >> ./env.properties
echo "JWT_EXPIRATION_MINUTES=${{ secrets.JWT_EXPIRATION_MINUTES }}" >> ./env.properties
echo "JWT_REFRESH_EXPIRATION_HOURS=${{ secrets.JWT_REFRESH_EXPIRATION_HOURS }}" >> ./env.properties
echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" >> ./env.properties
- name: Build with Gradle
run: |
cd wabi
./gradlew clean build
- name: Docker build and push
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
cd wabi
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest .
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:${GITHUB_SHA::7}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy using Docker
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
#!/bin/bash
ls
cd /
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}
# Create .env file in the correct directory
echo "SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}" | sudo tee -a .env > /dev/null
echo "SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}" | sudo tee -a .env > /dev/null
echo "SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}" | sudo tee -a .env > /dev/null
echo "JWT_KEY=${{ secrets.JWT_KEY }}" | sudo tee -a .env > /dev/null
echo "JWT_EXPIRATION_MINUTES=${{ secrets.JWT_EXPIRATION_MINUTES }}" | sudo tee -a .env > /dev/null
echo "JWT_REFRESH_EXPIRATION_HOURS=${{ secrets.JWT_REFRESH_EXPIRATION_HOURS }}" | sudo tee -a .env > /dev/null
echo "JWT_ISSUER=${{ secrets.JWT_ISSUER }}" | sudo tee -a .env > /dev/null
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" | sudo tee -a .env > /dev/null
echo "DOCKERHUB_REPOSITORY=${{ secrets.DOCKERHUB_REPOSITORY }}" | sudo tee -a .env > /dev/null
sudo docker-compose down
sudo docker-compose up -d