-
Notifications
You must be signed in to change notification settings - Fork 1
86 lines (71 loc) · 2.41 KB
/
cicd_prod.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
name: TogetUp-Server-Prod CI/CD
on:
push:
branches: [ "product","env/docker-cd" ]
env:
S3_BUCKET_NAME: togetup-storage
FILE_PATH: /home/ubuntu/app/
FILE_NAME: TogetUp-0.0.1-SNAPSHOT.jar
jobs:
deploy_prod:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Get CurrentTime
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00"
- name: Show Current Time
run: echo "CurrentTime=${{steps.current-time.outputs.formattedTime}}"
shell: bash
- name: Make application.yml
run: |
## create application.yml
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application.yml
echo '${{ secrets.TOGETUP_PROD_APPLICATION }}' >> ./application.yml
cat ./application.yml
shell: bash
- name: Gradle caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Docker build & push
run: |
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/togetupprod .
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/togetupprod
- name: Deploy to prod
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}
script: |
sudo docker ps -qa | grep -q . && sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/togetupprod
sudo docker-compose up -d
sudo docker image prune -f