Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
czy21 committed Nov 19, 2024
1 parent 949de6f commit eab20f2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
25 changes: 25 additions & 0 deletions jenkins/resources/org/ops/docker-compose-java.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.9"

x-traefik-label: &traefik-label
traefik.enable: true
traefik.http.routers.${param_release_name}.service: ${param_release_name}
traefik.http.services.${param_release_name}.loadbalancer.server.port: 8080

services:
app:
image: ${param_registry_repo}/library/${param_release_name}:${param_release_version}
pull_policy: always
container_name: ${param_release_name}
labels:
<<: *traefik-label
expose:
- "8080"
volumes:
- ${param_docker_data}/${param_release_name}/data/:/app/data/
- ${param_docker_data}/${param_release_name}/log/:/app/log/
restart: always

networks:
default:
name: local
external: true
22 changes: 22 additions & 0 deletions jenkins/resources/org/ops/docker-compose-web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.9"

x-traefik-label: &traefik-label
traefik.enable: true
traefik.http.routers.${param_release_name}.service: ${param_release_name}
traefik.http.services.${param_release_name}.loadbalancer.server.port: 80

services:
app:
image: ${param_registry_repo}/library/${param_release_name}:${param_release_version}
pull_policy: always
container_name: ${param_release_name}
labels:
<<: *traefik-label
expose:
- "80"
restart: always

networks:
default:
name: local
external: true
8 changes: 4 additions & 4 deletions jenkins/src/org/ops/Builder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ def build() {
},
go : {
pathMap.get("go").call()
cmd = StringUtils.format("cd {0};go build -o build main.go;", env.param_project_context)
def cmd = StringUtils.format("cd {0};go build -o build main.go;", env.param_project_context)
sh "${cmd}"
},
web : {
pathMap.get("node").call()
cmd = StringUtils.format("npm_config_registry={1} npm_config_node_linker=hoisted pnpm --dir {0} install && pnpm --dir {0} run build", env.param_project_context, env.param_npm_repo)
def cmd = StringUtils.format("npm_config_registry={1} npm_config_node_linker=hoisted pnpm --dir {0} install && pnpm --dir {0} run build", env.param_project_context, env.param_npm_repo)
sh "${cmd}"
},
dotnet: {
pathMap.get("dotnet").call()
configFileProvider([configFile(fileId: "nuget.config", variable: 'CONFIG_FILE_NUGET')]) {
cmd = StringUtils.format(
def cmd = StringUtils.format(
"rm -rf {0}/build && dotnet publish --configfile {1} -c Release {0} -o {0}/build",
env.param_project_root,
"${CONFIG_FILE_NUGET}"
Expand All @@ -76,7 +76,7 @@ def build() {
}
},
shell : {
cmd = StringUtils.format("chmod +x {0};{0}", PathUtils.ofPath(env.param_project_root, env.param_project_shell_file))
def cmd = StringUtils.format("chmod +x {0};{0}", PathUtils.ofPath(env.param_project_root, env.param_project_shell_file))
sh "${cmd}"
}
]
Expand Down
41 changes: 18 additions & 23 deletions jenkins/src/org/ops/Docker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,38 @@ import org.ops.util.StringUtils
def build() {
configFileProvider([configFile(fileId: "docker.config", targetLocation: '.jenkins/docker/config.json')]) {}

def docker_file = "${env.param_docker_file}"
def docker_file = env.param_docker_file

if (!fileExists(docker_file)) {
docker_file = ".jenkins/Dockerfile-${env.param_code_type}"
def docker_file_content = libraryResource "org/ops/Dockerfile-${env.param_code_type}"
writeFile file: docker_file, text: docker_file_content, encoding: 'utf-8'
def content = libraryResource "org/ops/Dockerfile-${env.param_code_type}"
writeFile file: docker_file, text: content, encoding: 'utf-8'
}

docker_config_dir = PathUtils.ofPath("${env.WORKSPACE}", ".jenkins/docker/")
docker_image_tag = "${env.param_release_image}:${env.param_release_version}"
docker_build_cmd = "docker build --tag ${docker_image_tag} --file ${docker_file} ${env.param_docker_context} --pull"
def docker_config_dir = PathUtils.ofPath("${env.WORKSPACE}", ".jenkins/docker/")
def docker_image_tag = "${env.param_release_image}:${env.param_release_version}"
def docker_build_cmd = "docker build --tag ${docker_image_tag} --file ${docker_file} ${env.param_docker_context} --pull"
if (StringUtils.isNotEmpty(env.param_docker_build_args)) {
env.param_docker_build_args.split(",").each { t -> docker_build_cmd += " --build-arg $t" }
}
docker_push_cmd = "docker --config ${docker_config_dir} push ${docker_image_tag}"
docker_rmi_cmd = "docker rmi ${docker_image_tag}"
def docker_push_cmd = "docker --config ${docker_config_dir} push ${docker_image_tag}"
def docker_rmi_cmd = "docker rmi ${docker_image_tag}"
sh "${docker_build_cmd} && ${docker_push_cmd} && ${docker_rmi_cmd}"
}

def deploy() {
deployMap = [
java: {
configFileProvider([configFile(fileId: "docker-compose-java-v1.yaml", targetLocation: '.jenkins/docker-compose.yaml')]) {}
},
web : {
configFileProvider([configFile(fileId: "docker-compose-web-v1.yaml", targetLocation: '.jenkins/docker-compose.yaml')]) {}
}
]
if (fileExists("${env.param_docker_compose_file}")) {
sh "cp ${env.param_docker_compose_file} .jenkins/docker-compose.yaml"
} else {
deployMap.get(env.param_code_type).call()

def compose_file = env.param_docker_compose_file

if (!fileExists(compose_file)) {
compose_file = ".jenkins/docker-compose-${env.param_code_type}.yaml"
def content = libraryResource "org/ops/docker-compose-${env.param_code_type}.yaml"
writeFile file: compose_file, text: content, encoding: 'utf-8'
}

withCredentials([dockerCert(credentialsId: 'docker-client', variable: 'DOCKER_CERT_PATH')]) {
param_file = PathUtils.ofPath("${env.WORKSPACE}", ".jenkins/param.yaml")
docker_compose_file = PathUtils.ofPath("${env.WORKSPACE}", ".jenkins/docker-compose.yaml")
cmd = "DOCKER_TLS_VERIFY=1 DOCKER_HOST=tcp://${env.param_docker_deploy_host}:2376 docker-compose --project-name ${env.param_release_name} --file ${docker_compose_file} --env-file ${param_file} up --detach --remove-orphans"
def param_file = PathUtils.ofPath("${env.WORKSPACE}", ".jenkins/param.yaml")
cmd = "DOCKER_TLS_VERIFY=1 DOCKER_HOST=tcp://${env.param_docker_deploy_host}:2376 docker-compose --project-name ${env.param_release_name} --file ${compose_file} --env-file ${param_file} up --detach --remove-orphans"
sh "${cmd}"
}
}
Expand Down

0 comments on commit eab20f2

Please sign in to comment.