-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
147 lines (123 loc) · 4.1 KB
/
build.gradle
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.hidetake.ssh' version '2.10.1'
id 'com.gorylenko.gradle-git-properties' version '2.4.1'
id 'com.google.cloud.tools.jib' version '3.4.2'
}
allprojects {
group = 'me.synolgy.hajubal'
version = '2.0.0'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.3"
}
}
test {
useJUnitPlatform()
}
}
bootJar.enabled = false
jar.enabled = false
ext.SSH_HOST = project.getProperties().getOrDefault("SSH_HOST", "127.0.0.1")
ext.SSH_ID = project.getProperties().getOrDefault("SSH_ID", "test")
ext.SSH_PW = project.getProperties().getOrDefault("SSH_PW", "test")
ext.SSH_PORT = project.getProperties().getOrDefault("SSH_PORT", "22")
ext.USERNAME = project.getProperties().getOrDefault("USERNAME", "user")
ext.PASSWORD = project.getProperties().getOrDefault("PASSWORD", "password")
//서버 접속 정보
remotes {
dockerServer {
host = "${SSH_HOST}"
user = "${SSH_ID}"
password = "${SSH_PW}"
port = Integer.parseInt("${SSH_PORT}")
}
}
tasks.withType(JavaCompile) {
options.compilerArgs.add("-parameters")
}
ssh.settings {
knownHosts = allowAnyHosts
}
jib {
from {
image = 'openjdk:17-alpine'
auth {
username = "${USERNAME}" // Defined in 'gradle.properties'.
password = "${PASSWORD}"
}
}
to {
image = 'hajubal/pickupcoin'
tags = [project.version.toString()]
}
container {
// TODO 이렇게 설정하면 안되는 이유 확인.
// appRoot = '/app'
// entrypoint = ['java', 'jar', "/app/${bootJar.archiveFile.get().asFile.name}", '--spring.profiles.active=dev']
ports = ['8080']
environment = [
SPRING_OUTPUT_ANSI_ENABLED: "ALWAYS",
"SPRING_PROFILES_ACTIVE": "dev",
"TZ": "Asia/Seoul"
]
labels = [Iversion: project.version, name: project.name, group: project.group]
format = 'Docker'
}
extraDirectories {
paths {
path {
from = file('build/libs')
}
}
}
}
//도커 서버에 이미지 생성 및 컨테이너 실행
//org.hidetake.groovy.ssh.operation.SftpException: Failed SFTP PUT: d:\~~ -> dockerServer:/var/~~: (SSH_FX_NO_SUCH_FILE: A reference was made to a file which does not exist): No such file
//오류 나면서 안됨. 원인 파악 불가
//==> 원인: 시놀로지의 경우 ssh로 보여지는 path와 ftp로 보는 경로가 다름. 그래서 scp로 업로도할 경로는 ftp로 접속해서 보여지는 경로로 업로드 해야 함.
tasks.register('dockerDeploy') {
dependsOn('build')
doLast {
println ssh.version
ssh.run {
session(remotes.dockerServer) {
def jarFile = bootJar.archiveFile.get().asFile
//시놀로지의 경우 ssh로 보여지는 path와 ftp로 보는 경로가 다름.
def to = "/homes/hajubal/dockerfile/${project.name}"
//시놀로지 명령어가 실행되는 경로
def commandTo = "/var/services/homes/hajubal/dockerfile/${project.name}"
def dockerFile = project.file("Dockerfile")
def dockerComposeFile = project.file("docker-compose.yml")
def envFile = project.file(".env")
//프로젝트 폴더에 파일 복사
put from: jarFile, into: "${to}/pickupcoins.jar"
put from: dockerFile, into: to
put from: dockerComposeFile, into: to
put from: envFile, into: to
execute("/usr/local/bin/docker-compose -f ${commandTo}/docker-compose.yml build", ignoreError: true){r->println r}
execute("/usr/local/bin/docker-compose -f ${commandTo}/docker-compose.yml up -d", ignoreError: true){r->println r}
}
}
}
}