PHP容器化demo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.4 KiB

3 years ago
  1. // Jenkinsfile.beta
  2. // @version 180820:1
  3. // @author zhangxuhong <zhangxuhong@xitu.io>
  4. //
  5. def appName = "suid-generator"
  6. def label = "worker-${UUID.randomUUID().toString()}"
  7. def registryHost = "harbor02.juejin.id/beta/"
  8. def deployLocation = "beta.kube01.lobj.juejin.id"
  9. podTemplate(
  10. label: label,
  11. containers: [
  12. containerTemplate(
  13. name: 'git',
  14. image: 'harbor02.juejin.id/infrastructure/git-1.8.3.1-centos:0.0.3',
  15. command: 'cat',
  16. ttyEnabled: true
  17. ),
  18. containerTemplate(
  19. name: 'dind',
  20. image: 'harbor02.juejin.id/infrastructure/docker-18.06.0-ce-dind:0.0.2',
  21. command: 'cat',
  22. ttyEnabled: true
  23. ),
  24. containerTemplate(
  25. name: 'kubectl',
  26. image: 'harbor02.juejin.id/infrastructure/kubectl-1.11.1-centos-with-cert-cluster01.lobj:latest',
  27. command: 'cat',
  28. ttyEnabled: true
  29. ),
  30. ],
  31. volumes: [
  32. hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
  33. ],
  34. cloud: deployLocation
  35. ){
  36. node(label) {
  37. // start deploy phrase
  38. stage("[1/4] check out"){
  39. container('git'){
  40. checkout scm
  41. sh "git rev-parse --short HEAD > commit-id"
  42. tag = readFile('commit-id').replace("\n", "").replace("\r", "")
  43. imageName = "${registryHost}${appName}:${tag}"
  44. env.BUILDIMG=imageName
  45. }
  46. }
  47. stage("[2/4] Build"){
  48. container('dind'){
  49. sh "docker version"
  50. sh "docker build -t ${imageName} ./"
  51. }
  52. }
  53. stage("[3/4] Push"){
  54. container('dind'){
  55. sh "/usr/local/bin/docker-login.sh"
  56. sh "docker push ${imageName}"
  57. }
  58. }
  59. stage("[4/4] Deploy"){
  60. container('kubectl'){
  61. sh "sed -i 's#__IMAGE__#$BUILDIMG#g' ./config/kubernetes/Deployment.yaml"
  62. sh "cat ./config/kubernetes/Deployment.yaml"
  63. sh "kubectl --kubeconfig=/root/.kube/config apply -f ./config/kubernetes/Service.yaml"
  64. sh "kubectl --kubeconfig=/root/.kube/config apply -f ./config/kubernetes/Ingress.yaml"
  65. sh "kubectl --kubeconfig=/root/.kube/config apply -f ./config/kubernetes/Deployment.yaml"
  66. }
  67. }
  68. }
  69. }