Skip to content

Commit

Permalink
ci: enable remote debug
Browse files Browse the repository at this point in the history
  • Loading branch information
liyifango committed Sep 9, 2020
1 parent 5aecc56 commit a44603c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ out/

### VS Code ###
.vscode/

### MAC File ###
.DS_Store

210 changes: 207 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,210 @@ include:
file: '.gitlab-ci-template.yml'
ref: 'master'

code_quality:
artifacts:
paths: [gl-code-quality-report.json]
#k8s部署脚本模板
.k8s-deploy-template: &k8s_deploy_definition
image: lachlanevenson/k8s-kubectl:latest
script: |
if [[ "${BUILD_ENV}" != "node" && "${BUILD_ENV}" != "package" ]]; then export port=8080; else export port=80; fi
cat >> deployment.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: $CI_ENVIRONMENT_SLUG
annotations:
app.gitlab.com/env: $CI_ENVIRONMENT_SLUG
app.gitlab.com/app: $CI_PROJECT_PATH_SLUG
spec:
replicas: 1
selector:
matchLabels:
name: $CI_ENVIRONMENT_SLUG
template:
metadata:
labels:
name: $CI_ENVIRONMENT_SLUG
annotations:
app.gitlab.com/env: $CI_ENVIRONMENT_SLUG
app.gitlab.com/app: $CI_PROJECT_PATH_SLUG
EOF
if [[ "${BUILD_ENV}" != "node" && "${BUILD_ENV}" != "package" ]]; then
cat >> deployment.yaml <<EOF
prometheus.io/scrape: "true"
prometheus.io/port: "${port}"
prometheus.io/path: "/actuator/prometheus"
EOF
fi
if [[ $(echo "${CI_ENVIRONMENT_SLUG%%-*}") == "st" ]]; then
cat >> deployment.yaml << EOF
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: hanlin.arch/enviroment
operator: Exists
- key: hanlin.arch/enviroment-scope.st
operator: Exists
EOF
else
cat >> deployment.yaml << EOF
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: hanlin.arch/enviroment
operator: Exists
- key: hanlin.arch/enviroment-scope.test
operator: Exists
- matchExpressions:
- key: hanlin.arch/enviroment
operator: Exists
- key: hanlin.arch/enviroment-scope.review
operator: Exists
EOF
fi
cat >> deployment.yaml <<EOF
volumes:
- name: time-config
hostPath:
path: /etc/localtime
- name: tz-config
hostPath:
path: /etc/timezone
containers:
- name: $CI_ENVIRONMENT_SLUG
image: $IMAGE_NAME:$CI_COMMIT_SHORT_SHA
volumeMounts:
- mountPath: /etc/localtime
name: time-config
readOnly: true
- mountPath: /etc/timezone
name: tz-config
readOnly: true
EOF
if [[ $(echo "${CI_ENVIRONMENT_SLUG%%-*}") == "st" ]]; then
cat >> deployment.yaml << EOF
resources:
limits:
memory: "4Gi"
cpu: "2000m"
requests:
memory: "1Gi"
cpu: "500m"
EOF
else
cat >> deployment.yaml << EOF
resources:
limits:
memory: "2Gi"
cpu: "1000m"
requests:
memory: "512Mi"
cpu: "50m"
EOF
fi
if [[ $(echo "${CI_ENVIRONMENT_SLUG%%-*}") != "st" && "${BUILD_ENV}" != "node" && "${BUILD_ENV}" != "package" ]]; then
cat >> deployment.yaml <<EOF
args:
- "-Djava.security.egd=file:/dev/./urandom"
- "-Duser.timezone=GMT+08"
- "-Xms256m"
- "-Xmx512m"
- "-server"
- "--server.port=${port}"
- "--spring.profiles.active=$profiles_active"
- "--k8s.domainName=$CI_ENVIRONMENT_SLUG.sino-hanlin.tech"
EOF
elif [[ $(echo "${CI_ENVIRONMENT_SLUG%%-*}") == "st" && "${BUILD_ENV}" != "node" && "BUILD_ENV" != "package"]]; then
cat >> deployment.yaml <<EOF
args:
- "-Djava.security.egd=file:/dev/./urandom"
- "-Duser.timezone=GMT+08"
- "-Xms2g"
- "-Xmx2g"
- "-server"
- "--server.port=${port}"
- "--spring.profiles.active=$profiles_active"
- "--k8s.domainName=$CI_ENVIRONMENT_SLUG.sino-hanlin.tech"
EOF
fi
cat >> deployment.yaml <<EOF
ports:
- name: http
containerPort: ${port}
- name: debug
containerPort: 9999
---
apiVersion: v1
kind: Service
metadata:
name: $CI_ENVIRONMENT_SLUG-service
spec:
selector:
name: $CI_ENVIRONMENT_SLUG
ports:
- name: http
port: ${port}
targetPort: ${port}
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: $CI_ENVIRONMENT_SLUG-debug-service
spec:
type: NodePort
selector:
name: $CI_ENVIRONMENT_SLUG
ports:
- name: http
port: 9999
targetPort: 30100
protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: $CI_ENVIRONMENT_SLUG-ingress
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: "letsencrypt-staging"
spec:
rules:
- host: $CI_ENVIRONMENT_SLUG.sino-hanlin.tech
http:
paths:
- path: /
backend:
serviceName: $CI_ENVIRONMENT_SLUG-service
servicePort: ${port}
tls:
- hosts:
- $CI_ENVIRONMENT_SLUG.sino-hanlin.tech
secretName: hanlin-tls
EOF
cat >> deployment.sh <<EOF
if [ $(kubectl --insecure-skip-tls-verify get deploy ${CI_ENVIRONMENT_SLUG} --no-headers=true -o custom-columns=replicas:.status.replicas || echo 0) -gt 0 ]
then
echo 'the deployment is already exists, do image update ...'
kubectl --insecure-skip-tls-verify set image deployment/${CI_ENVIRONMENT_SLUG} ${CI_ENVIRONMENT_SLUG}=${IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}
else
echo 'the deployment has not been deployed, do create with record...'
kubectl --insecure-skip-tls-verify apply -f deployment.yaml --record
fi
EOF
sh ./deployment.sh
echo "the environment url is https://${CI_ENVIRONMENT_SLUG}.sino-hanlin.tech"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM openjdk:11-jre-slim
FROM openjdk:11-jdk

ARG BUILD_PATH
ADD ${BUILD_PATH} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999","-jar","/app.jar"]
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ ext {
set('springCloudAlibabaVersion', "2.2.1.RELEASE")
}

bootRun {
jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9999"
}

repositories {
mavenLocal()
Expand Down

0 comments on commit a44603c

Please sign in to comment.