-
Notifications
You must be signed in to change notification settings - Fork 2
92 lines (79 loc) · 3.45 KB
/
deploy.yml
File metadata and controls
92 lines (79 loc) · 3.45 KB
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
# 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.
# This workflow will build a Java project with Gradle 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-gradle
name: Java CD with Gradle
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Copy secrets
env:
BOLETTO_SECRET: ${{ secrets.BOLETTO_SECRET }}
BOLETTO_FIREBASE_SECRET: ${{ secrets.BOLETTO_FIREBASE_SECRET }}
BOLETTO_OCI_SECRET: ${{ secrets.BOLETTO_OCI_SECRET }}
BOLETTO_SECRET_DIR: src/main/resources
BOLETTO_SECRET_DIR_FILE_NAME: application-secret.yml
BOLETTO_FIREBASE_SECRET_FILE_NAME: firebase-adminsdk.json
BOLETTO_OCI_SECRET_FILE_NAME: oci-private-key.pem
BOLETTO_APPLE_SECRET_FILE_PATH: ${{ secrets.BOLETTO_APPLE_SECRET_FILE_PATH }}
BOLETTO_APPLE_SECRET_FILE: ${{ secrets.BOLETTO_APPLE_SECRET_FILE }}
run: |
echo $BOLETTO_SECRET | base64 --decode > $BOLETTO_SECRET_DIR/$BOLETTO_SECRET_DIR_FILE_NAME
echo $BOLETTO_FIREBASE_SECRET | base64 --decode > $BOLETTO_SECRET_DIR/$BOLETTO_FIREBASE_SECRET_FILE_NAME
echo $BOLETTO_OCI_SECRET | base64 --decode > $BOLETTO_SECRET_DIR/$BOLETTO_OCI_SECRET_FILE_NAME
echo $BOLETTO_APPLE_SECRET_FILE | base64 --decode > $BOLETTO_SECRET_DIR/$BOLETTO_APPLE_SECRET_FILE_PATH
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle Wrapper
run: ./gradlew bootJar
- name: Setup docker buildx
uses: docker/setup-buildx-action@v3
- name: Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/deploy:boletto_server
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
- name: Execute remote ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.BOLETTO_HOST }}
username: ${{ secrets.BOLETTO_USERNAME }}
key: ${{ secrets.BOLETTO_KEY }}
port: ${{ secrets.BOLETTO_PORT }}
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/deploy:boletto_server
docker stop boletto
docker rm boletto
docker run -d --name boletto -p 8080:8080 -v /home/ubuntu/secret/wallet:/secret/wallet ${{ secrets.DOCKERHUB_USERNAME }}/deploy:boletto_server