buildAndPublish.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. source_dir=/java_projects/source/front
  3. project_name=mldong-vue
  4. nfs_project_dir=/mnt/
  5. profile=test
  6. k8s_yaml=/java_projects/$project_name/k8s-$profile.yaml
  7. registry_url=https://registry.npm.taobao.org
  8. if [ -d "$source_dir" ]; then
  9. echo "源码存放根目录${source_dir}已存在"
  10. else
  11. echo "源码存放根目录不存在,创建${source_dir}"
  12. cp -p $source_dir
  13. fi
  14. if [ -d "$source_dir/$project_name" ]; then
  15. echo "源码已存在,git pull"
  16. cd $source_dir/$project_name
  17. git pull
  18. else
  19. echo "源码不存在,git clone"
  20. git clone $git_url $source_dir/$project_name
  21. fi
  22. cd $source_dir/$project_name
  23. git pull
  24. git_tag=$(git describe --tags --always)
  25. echo "当前版本:$git_tag"
  26. npm --registry=${registry_url} install --unsafe-perm
  27. npm run build:$profile
  28. if [ $? -ne 0 ]; then
  29. echo "打包失败"
  30. else
  31. # 移出index.html,留最后复制
  32. mv dist/index.html ./
  33. # 创建目录
  34. mkdir -p $nfs_project_dir/$project_name
  35. # 复制文件
  36. cp -r dist/* $nfs_project_dir/$project_name
  37. # 复制index.html
  38. cp index.html $nfs_project_dir/$project_name
  39. # 还原index.html
  40. mv index.html dist/index.html
  41. kubectl apply -f $k8s_yaml
  42. fi