mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-04-05 19:47:40 +08:00
chrome: 删除无用脚本和注释,优化ci自动化
This commit is contained in:
6
.github/workflows/code-ci.yml
vendored
6
.github/workflows/code-ci.yml
vendored
@@ -37,7 +37,7 @@ jobs:
|
||||
version: 7
|
||||
run_install: true
|
||||
|
||||
- name: Code ESlint Fix
|
||||
run: pnpm lintfix
|
||||
- name: Code Fix
|
||||
run: ./scripts/lint --fix
|
||||
- name: Build Site
|
||||
run: pnpm build
|
||||
run: ./scripts/bundle build
|
||||
|
||||
14
.github/workflows/docker-image.yml
vendored
14
.github/workflows/docker-image.yml
vendored
@@ -41,7 +41,10 @@ jobs:
|
||||
run: |
|
||||
docker version
|
||||
echo "-----------Docker Login-----------"
|
||||
docker login --username=${{ env.UserName }} --password=${{ secrets.DOCKER_PASSWORD }} ${{env.REGISTRY}}
|
||||
docker login \
|
||||
--username=${{ env.UserName }} \
|
||||
--password=${{ secrets.DOCKER_PASSWORD }} \
|
||||
${{env.REGISTRY}}
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
@@ -54,5 +57,10 @@ jobs:
|
||||
version: 7
|
||||
run_install: true
|
||||
|
||||
- name: Build And Push Docker image
|
||||
run: PROXY_DOMAIN=true pnpm image:faster
|
||||
## 构建,支持domain
|
||||
- name: Build To Dist
|
||||
run: ./scripts/bundle build_proxy
|
||||
|
||||
- name: Push Docker image
|
||||
run: ./scripts/bundle image_faster
|
||||
|
||||
|
||||
7
.github/workflows/esc-deploy.yml
vendored
7
.github/workflows/esc-deploy.yml
vendored
@@ -31,7 +31,10 @@ jobs:
|
||||
run: |
|
||||
docker version
|
||||
echo "-----------Docker Login-----------"
|
||||
docker login --username=${{ env.UserName }} --password=${{ secrets.DOCKER_PASSWORD }} ${{env.REGISTRY}}
|
||||
docker login \
|
||||
--username=${{ env.UserName }} \
|
||||
--password=${{ secrets.DOCKER_PASSWORD }} \
|
||||
${{env.REGISTRY}}
|
||||
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v3
|
||||
@@ -45,7 +48,7 @@ jobs:
|
||||
run_install: true
|
||||
|
||||
- name: Build And Push Docker image
|
||||
run: pnpm faster-image
|
||||
run: ./script/bundle image
|
||||
|
||||
Deploy-ESC:
|
||||
needs: Docker-Image
|
||||
|
||||
3
.github/workflows/gh-deploy.yml
vendored
3
.github/workflows/gh-deploy.yml
vendored
@@ -32,8 +32,7 @@ jobs:
|
||||
|
||||
# 运行构建脚本
|
||||
- name: Build VuePress Site
|
||||
run:
|
||||
PROXY_DOMAIN=true pnpm build
|
||||
run: ./scripts/bundle build_proxy
|
||||
|
||||
- name: Deploy to GitHub Page
|
||||
uses: crazy-max/ghaction-github-pages@v3
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#
|
||||
# 注意:vite构建需要支持node14以上,安装node16较为稳妥
|
||||
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/142vip/node:16.12.0-alpine AS build_base
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/142vip/node:16.20.2-alpine AS build_base
|
||||
ARG CONTAINER_BUILD
|
||||
WORKDIR /apps
|
||||
COPY . .
|
||||
@@ -16,7 +16,7 @@ RUN echo $CONTAINER_BUILD
|
||||
|
||||
## 基于容器自动构建
|
||||
RUN if [ "$CONTAINER_BUILD" = "true" ]; then \
|
||||
npm i pnpm@7 -g && pnpm i -D && pnpm build; \
|
||||
npm i pnpm@7 -g && pnpm i -D && ./scripts/bundle build; \
|
||||
fi;
|
||||
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:1.23.0-alpine
|
||||
|
||||
29
package.json
29
package.json
@@ -13,33 +13,14 @@
|
||||
"url": "https://github.com/142vip"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "husky install && npx husky add .husky/pre-commit \"npm run lintfix\" && chmod +x .husky/pre-commit",
|
||||
"prepare": "husky install && npx husky add .husky/pre-commit \"./scripts/lint --fix\" && chmod +x .husky/pre-commit",
|
||||
"dev": "vuepress dev docs",
|
||||
"build": "vuepress build docs",
|
||||
"build:proxy": "PROXY_DOMAIN=true vuepress build docs",
|
||||
"image": "bash scripts/build_image.sh $npm_package_version",
|
||||
"image:faster": "bash scripts/build_image.sh $npm_package_version faster",
|
||||
"deploy:ali": "bash scripts/deploy.sh ali $npm_package_version",
|
||||
"deploy:github": "bash scripts/deploy.sh github $npm_package_version",
|
||||
"deploy:vercel": "vercel --prod",
|
||||
"release": "./scripts/release",
|
||||
"lint": "./scripts/lint",
|
||||
"lintfix": "./scripts/lint --fix",
|
||||
"clean": "find . -name \"node_modules\" -type d -exec rm -rf '{}' + "
|
||||
},
|
||||
"scripts-info": {
|
||||
"prepare": "安装依赖预执行脚本",
|
||||
"dev": "本地启动项目",
|
||||
"build": "构建、打包",
|
||||
"build:proxy": "构建、打包,支持项目名代理,使用第三方托管平台",
|
||||
"image": "容器打包、构建镜像",
|
||||
"image:faster": "本地build后,快速构建镜像",
|
||||
"deploy:ali": "部署到阿里云服务器",
|
||||
"deploy:github": "部署到github平台,集成ci",
|
||||
"release": "alpha测试版号更新、正式版本发布",
|
||||
"version:patch": "稳定版号更新,基于master分支操作",
|
||||
"lint": "eslint校验代码,指出异常",
|
||||
"lintfix": "格式化代码,自动化处理异常",
|
||||
"clean": "快速删除本地依赖"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -62,10 +43,8 @@
|
||||
"vue": "^3.3.4",
|
||||
"vuepress": "2.0.0-beta.61",
|
||||
"vuepress-plugin-search-pro": "2.0.0-beta.185",
|
||||
"vuepress-theme-hope": "2.0.0-beta.185"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"vuepress-theme-hope": "2.0.0-beta.185",
|
||||
"shelljs": "^0.8.5"
|
||||
}
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
872
pnpm-lock.yaml
generated
872
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 登录阿里云hub
|
||||
docker login --username=mmdapl registry.cn-hangzhou.aliyuncs.com
|
||||
@@ -1,78 +0,0 @@
|
||||
#!/bin/bash
|
||||
## 功能:本地前后端项目构建、打包镜像,上传docker仓库
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 使用示例:bash xxx.sh 版本号 faster[可选]
|
||||
## - bash build_image.sh 0.0.1 faster
|
||||
## 作者:储凡
|
||||
##
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
## 项目名称
|
||||
readonly projectName="408CSFamily"
|
||||
## 仓库地址
|
||||
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
|
||||
## 版本号
|
||||
version=${1}
|
||||
## 是否先本地构建,执行npm run build操作
|
||||
isFaster=${2}
|
||||
## 镜像名称
|
||||
imageTagName=${repoAddress}:${projectName}-${version}
|
||||
|
||||
|
||||
## 参数预检查
|
||||
prepare_check(){
|
||||
if test -z "${version}";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空。参考版本: 0.0.x"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 运行命令
|
||||
run(){
|
||||
echo -e "${successLogger}---------------- shell ${projectName} start ---------------- "
|
||||
|
||||
if [ "${isFaster}" == "faster" ];then
|
||||
## 本地构建、快速制作镜像
|
||||
pnpm build && docker build \
|
||||
--build-arg APP_VERSION="${version}" \
|
||||
--build-arg CONTAINER_BUILD=false \
|
||||
-t "${imageTagName}" .
|
||||
else
|
||||
## ci流程,容器构建打包
|
||||
docker build \
|
||||
--build-arg APP_VERSION="${version}" \
|
||||
--build-arg CONTAINER_BUILD=true \
|
||||
-t "${imageTagName}" .
|
||||
fi
|
||||
|
||||
echo -e "${successLogger}---------------- shell ${projectName} end ---------------- "
|
||||
push_docker_image
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
## 推送镜像
|
||||
push_docker_image(){
|
||||
if [[ "$(docker images -q "${imageTagName}" 2> /dev/null)" != "" ]];
|
||||
then
|
||||
## 推送
|
||||
docker push "${imageTagName}"
|
||||
echo -e "${successLogger}---------------- 上传镜像成功,删除本地镜像 ---------------- "
|
||||
docker rmi "${imageTagName}"
|
||||
else
|
||||
echo -e "${errorLogger}${currentTime}:[镜像] ${imageTagName}不存在"
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
prepare_check
|
||||
run
|
||||
|
||||
|
||||
@@ -23,19 +23,21 @@ const imageName=`${repoAddress}:${projectName}-${packageVersion}`
|
||||
|
||||
/**
|
||||
* 获取构建镜像的脚本
|
||||
* - faster: "faster"
|
||||
* @param containerBuild
|
||||
* @param needProxy
|
||||
*/
|
||||
function getBuildImageScript(faster){
|
||||
// 是否容器构建
|
||||
const isContainerBuild=faster==="faster"
|
||||
|
||||
function getBuildImageScript({containerBuild,needProxy=false}){
|
||||
// 基础构建脚本
|
||||
const baseBuildScript=containerBuild?"":(
|
||||
needProxy?"./scripts/bundle build_proxy":"./scripts/bundle build"
|
||||
)
|
||||
return [
|
||||
// 构建镜像
|
||||
`
|
||||
${isContainerBuild? `./scripts/bundle build && `:""}
|
||||
${baseBuildScript}
|
||||
docker build \
|
||||
--build-arg APP_VERSION=${packageVersion} \
|
||||
--build-arg CONTAINER_BUILD=${!isContainerBuild} \
|
||||
--build-arg CONTAINER_BUILD=${containerBuild} \
|
||||
-t ${imageName} .
|
||||
`,
|
||||
// 推送镜像
|
||||
@@ -61,8 +63,19 @@ function getBuildImageScript(faster){
|
||||
const SupportScripts={
|
||||
build:'vuepress build docs',
|
||||
build_proxy:'PROXY_DOMAIN=true vuepress build docs',
|
||||
image:getBuildImageScript(),
|
||||
image_faster:getBuildImageScript("faster")
|
||||
image:getBuildImageScript({
|
||||
containerBuild:true,
|
||||
needProxy:false
|
||||
}),
|
||||
image_proxy:getBuildImageScript({
|
||||
containerBuild:true,
|
||||
needProxy:true
|
||||
}),
|
||||
// 直接从本地拿dist文件,生成镜像
|
||||
image_faster:getBuildImageScript({
|
||||
containerBuild:false,
|
||||
needProxy:false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +105,11 @@ async function getScriptCommand(){
|
||||
name: SupportScripts.image,
|
||||
value: '#0000ff'
|
||||
},
|
||||
{
|
||||
message: 'build to docker image with proxy',
|
||||
name: SupportScripts.image_proxy,
|
||||
value: '#0000ff'
|
||||
},
|
||||
{
|
||||
message: 'build to docker image faster',
|
||||
name: SupportScripts.image_faster,
|
||||
@@ -111,9 +129,6 @@ async function getScriptCommand(){
|
||||
|
||||
;(async ()=>{
|
||||
const scriptCommand= await getScriptCommand()
|
||||
console.log(`>>>> ${scriptCommand} `)
|
||||
|
||||
// 执行
|
||||
// await execShell(scriptCommand)
|
||||
await execShell(scriptCommand)
|
||||
})()
|
||||
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
#!/bin/bash
|
||||
## 功能:清除容器,删除旧镜像,创建新的容器
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:储凡
|
||||
## 使用示例:bash deploy.sh 部署平台 版本号
|
||||
## - bash deploy.sh ali 0.0.1
|
||||
##
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
|
||||
readonly containerName="408CSFamily"
|
||||
readonly networkName="service_env_net"
|
||||
## 定义参数
|
||||
operationName=${1}
|
||||
version=${2}
|
||||
## 镜像名称
|
||||
imageName="${repoAddress}:${containerName}-${version}"
|
||||
|
||||
|
||||
## 参数预检查
|
||||
prepare_check(){
|
||||
if test -z "${operationName}"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 部署平台不能为空."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -z "${version}"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 版本号不能为空."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
## 判断容器存在即删除
|
||||
## - 一个参数,容器名称
|
||||
delete_container(){
|
||||
docker inspect "${1}" -f '{{.Name}}' > /dev/null
|
||||
if [ $? -eq 0 ] ;then
|
||||
echo -e "${warnLogger}${currentTime}容器:${1} 存在,现进行删除"
|
||||
docker rm -f "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
## 判断镜像存在,即删除
|
||||
## - 一个参数,镜像地址
|
||||
delete_image(){
|
||||
## 判断版本号
|
||||
if test -z "${version}";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 镜像版本号不能为空."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$(docker images -q "${1}" 2> /dev/null)" != "" ]];
|
||||
then
|
||||
echo -e "${warnLogger}${currentTime}镜像:${1}存在,现进行删除"
|
||||
docker rmi "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 环境初始成功
|
||||
run(){
|
||||
if [ "${operationName}" == "gitee" ];then
|
||||
## 查看所有
|
||||
deploy_to_gitee
|
||||
exit 0;
|
||||
elif [ "${operationName}" == "github" ]; then
|
||||
deploy_to_github
|
||||
exit 0;
|
||||
elif [ "${operationName}" == "ali" ]; then
|
||||
## 删除容器
|
||||
delete_container "${containerName}"
|
||||
## 删除镜像
|
||||
delete_image "${imageName}"
|
||||
## 部署
|
||||
deploy_to_ali
|
||||
exit 0;
|
||||
else
|
||||
echo -e "${errorLogger}${currentTime}当前操作不支持,目前只支持:ali/gitee/github"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
## 部署到阿里服务器
|
||||
deploy_to_ali(){
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} ali start ---------------- "
|
||||
|
||||
docker run -d --name "${containerName}" \
|
||||
-p 7000:80 \
|
||||
--network="${networkName}" \
|
||||
--restart=unless-stopped \
|
||||
--ip=172.30.0.100 \
|
||||
"${imageName}"
|
||||
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} ali end ------------------ "
|
||||
docker ps
|
||||
}
|
||||
|
||||
## 部署到github静态资源托管
|
||||
deploy_to_github(){
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} github start ---------------- "
|
||||
|
||||
set -e
|
||||
npm run build-proxy && cd docs/.vuepress/dist
|
||||
git init && git add -A
|
||||
|
||||
## 配置信息
|
||||
git config user.name 'chu fan'
|
||||
git config user.email 'fairy_408@2925.com'
|
||||
git config --list
|
||||
|
||||
git commit -m "release v${version}"
|
||||
|
||||
|
||||
# git push -f https://github.com/mmdapl/408CSFamily.git main
|
||||
## 部署到github pages
|
||||
git push -f https://github.com/mmdapl/408CSFamily.git main:pages/github
|
||||
cd -
|
||||
|
||||
echo -e "${successLogger}---------------- deploy ${containerName} github end ------------------ "
|
||||
}
|
||||
|
||||
|
||||
## 部署到gitee静态资源托管
|
||||
deploy_to_gitee(){
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
prepare_check
|
||||
|
||||
run
|
||||
|
||||
|
||||
10
scripts/dev
Executable file
10
scripts/dev
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
*
|
||||
* 本地启动
|
||||
* 例如:
|
||||
* - ./scripts/dev
|
||||
*/
|
||||
|
||||
const { execShell } = require("./.exec");
|
||||
(async ()=>await execShell('vuepress dev docs'))()
|
||||
125
scripts/docker
125
scripts/docker
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
*
|
||||
* docker cli工具
|
||||
* 例如:
|
||||
* - ./scripts/network create
|
||||
* - ./scripts/network inspect
|
||||
* - ./scripts/network rm
|
||||
* - ./scripts/network ls
|
||||
* - ./scripts/docker container xxx 容器相关
|
||||
* - ./scripts/network image xxx 镜像相关
|
||||
* - ./scripts/docker network xxx 网络相关
|
||||
*/
|
||||
const { execShell, BaseSetting} = require("./.exec");
|
||||
const scriptName=process.argv[2];
|
||||
@@ -24,41 +23,26 @@ const dockerNetworkInfo={
|
||||
gateway:'172.30.0.1',
|
||||
}
|
||||
|
||||
/**
|
||||
* docker containers 容器相关指令
|
||||
*/
|
||||
const SupportScriptsInContainer={
|
||||
run:'',
|
||||
rm:'',
|
||||
ps:'docker ps'
|
||||
}
|
||||
|
||||
function getContainerCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
if(scriptName==='rm')
|
||||
return SupportScriptsInContainer.rm
|
||||
if(scriptName==='run')
|
||||
return SupportScriptsInContainer.run
|
||||
if(scriptName==='ps')
|
||||
return SupportScriptsInContainer.ps
|
||||
return SupportScriptsInContainer.run
|
||||
}
|
||||
|
||||
|
||||
|
||||
const SupportScriptsInImage={
|
||||
rm:'docker rmi **',
|
||||
ps:'docker images'
|
||||
}
|
||||
|
||||
function getContainerCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
if(scriptName==='rm')
|
||||
return SupportScriptsInContainer.rm
|
||||
if(scriptName==='run')
|
||||
return SupportScriptsInContainer.run
|
||||
if(scriptName==='ps')
|
||||
return SupportScriptsInContainer.ps
|
||||
return SupportScriptsInContainer.run
|
||||
/**
|
||||
* docker images 相关脚本指令
|
||||
*/
|
||||
const SupportScriptsInImage = {
|
||||
rm: 'docker rmi **',
|
||||
ps: 'docker images'
|
||||
}
|
||||
|
||||
/**
|
||||
* docker network 相关脚本指令
|
||||
*/
|
||||
const SupportScriptsInNetWork={
|
||||
ls:'docker network ls',
|
||||
create:[
|
||||
@@ -96,28 +80,46 @@ const SupportScriptsInNetWork={
|
||||
`
|
||||
],
|
||||
inspect:
|
||||
`
|
||||
`
|
||||
docker network inspect ${dockerNetworkInfo.defaultName}
|
||||
`
|
||||
}
|
||||
|
||||
function getNetworkCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
|
||||
if(SupportScriptsInNetWork.hasOwnProperty(scriptName)){
|
||||
|
||||
function getContainerCommand(){
|
||||
const name=process.argv[3];
|
||||
|
||||
if(SupportScriptsInContainer.hasOwnProperty(name)){
|
||||
return SupportScriptsInContainer[name]
|
||||
}
|
||||
// 默认查看所有容器
|
||||
return SupportScriptsInContainer.ps
|
||||
}
|
||||
|
||||
function getImageCommand(){
|
||||
const name=process.argv[3];
|
||||
|
||||
if(SupportScriptsInImage.hasOwnProperty(name)){
|
||||
return SupportScriptsInImage[name]
|
||||
}
|
||||
return SupportScriptsInImage.ps
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getNetworkCommand(){
|
||||
const name=process.argv[3];
|
||||
if(SupportScriptsInNetWork.hasOwnProperty(name)){
|
||||
return SupportScriptsInNetWork[scriptName]
|
||||
}
|
||||
if(scriptName==='ls')
|
||||
return SupportScriptsInNetWork.ls
|
||||
if(scriptName==='run')
|
||||
return SupportScriptsInNetWork.create
|
||||
if(scriptName==='ps')
|
||||
return SupportScriptsInNetWork.rm
|
||||
if(scriptName==='inspect')
|
||||
return SupportScriptsInNetWork.inspect
|
||||
return SupportScriptsInNetWork.ls
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 支持的命令
|
||||
const SupportScripts={
|
||||
ls:'docker network ls',
|
||||
@@ -161,38 +163,17 @@ const SupportScripts={
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要执行的shell命令
|
||||
* @param scriptName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getCommand(scriptName){
|
||||
let deployCommand=SupportScripts.ls
|
||||
|
||||
switch (scriptName) {
|
||||
case 'container':
|
||||
return getContainerCommand();
|
||||
function getCommand(){
|
||||
const scriptName=process.argv[3];
|
||||
switch (scriptName){
|
||||
case 'network':
|
||||
break;
|
||||
return getNetworkCommand()
|
||||
case 'container':
|
||||
return getContainerCommand()
|
||||
case 'image':
|
||||
break;
|
||||
return getImageCommand()
|
||||
}
|
||||
|
||||
if(scriptName==='ls'){
|
||||
deployCommand=SupportScripts.ls
|
||||
}
|
||||
|
||||
// 部署到Github
|
||||
if(scriptName==='rm'){
|
||||
deployCommand=SupportScripts.rm
|
||||
}
|
||||
if(scriptName==='create'){
|
||||
deployCommand=SupportScripts.create
|
||||
}
|
||||
if(scriptName==='inspect'){
|
||||
deployCommand=SupportScripts.inspect
|
||||
}
|
||||
return deployCommand
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## 功能:设置docker自定义network,并指定网关、IP范围
|
||||
## 参考:https://blog.csdn.net/Dontla/article/details/125210694
|
||||
## 作者:储凡
|
||||
## 使用示例:bash xxx.sh 容器名称 镜像地址
|
||||
##
|
||||
|
||||
|
||||
## 日志颜色定义
|
||||
readonly successLogger="\033[36m"
|
||||
readonly errorLogger="\033[1;31m"
|
||||
readonly warnLogger="\033[1;33m"
|
||||
## 定义时间
|
||||
readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
operationName=${1}
|
||||
networkName=${2}
|
||||
|
||||
## 网络名称
|
||||
readonly defaultNetworkName="service_env_net"
|
||||
## 子网范围 [/24 子网掩码]
|
||||
readonly subnet="172.30.0.0/24"
|
||||
## 网关
|
||||
readonly gateway="172.30.0.1"
|
||||
|
||||
|
||||
prepare_check(){
|
||||
if test -z "$operationName"
|
||||
then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 操作类型不能为空。脚本执行eg: bash xxx.sh [ls/init/rm]"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
run(){
|
||||
if [ "$operationName" == "ls" ];then
|
||||
## 查看所有
|
||||
echo -e "${successLogger}---------------- shell ls start ---------------- "
|
||||
docker network ls
|
||||
echo -e "${successLogger}---------------- shell ls end ------------------ "
|
||||
exit 0;
|
||||
elif [ "$operationName" == "init" ]; then
|
||||
echo -e "${successLogger}---------------- shell init start ---------------- "
|
||||
## 初始化
|
||||
init_network
|
||||
echo -e "${successLogger}---------------- shell init start ---------------- "
|
||||
exit 0;
|
||||
elif [ "$operationName" == "rm" ]; then
|
||||
## 移除
|
||||
echo -e "${successLogger}---------------- shell rm start ---------------- "
|
||||
remove_network
|
||||
echo -e "${successLogger}---------------- shell rm start ---------------- "
|
||||
exit 0;
|
||||
else
|
||||
echo -e "${errorLogger}当前操作不支持,目前只支持:ls/init/rm"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
## 创建网络
|
||||
init_network(){
|
||||
## 查询network -w【全匹配】
|
||||
docker network ls | grep -w "${defaultNetworkName}"
|
||||
if [ $? -eq 0 ] ;then
|
||||
echo -e "${warnLogger}---------------- 容器:${defaultNetworkName} 已存在,无需创建 ---------------- "
|
||||
docker network ls
|
||||
exit ;
|
||||
else
|
||||
echo -e "${successLogger}---------------- 网络${defaultNetworkName},现进行初始化 ---------------- "
|
||||
docker network ls
|
||||
docker network create \
|
||||
--subnet="${subnet}" \
|
||||
--gateway="${gateway}" \
|
||||
"${defaultNetworkName}"
|
||||
echo -e "${successLogger}---------------- 创建后 ---------------------"
|
||||
docker network ls
|
||||
echo -e "${successLogger}---------------- 网络信息 ---------------------"
|
||||
docker netwrok inspect "${defaultNetworkName}"
|
||||
fi
|
||||
}
|
||||
|
||||
## 删除网络
|
||||
remove_network(){
|
||||
if test -z "$networkName";then
|
||||
echo -e "${errorLogger}${currentTime}:参数错误 网络名称不能为空。脚本执行eg: bash xxx.sh rm 网络名称"
|
||||
exit 0
|
||||
fi
|
||||
## 判断是否存在 -w【全匹配】
|
||||
docker network ls | grep -w "${networkName}"
|
||||
if [ $? -eq 1 ] ;then
|
||||
echo -e "${errorLogger}${currentTime}:容器网络:${networkName} 不存在,删除无效 "
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo -e "${successLogger}----------------删除前---------------------"
|
||||
docker network ls
|
||||
docker network rm "${networkName}"
|
||||
echo -e "${successLogger}----------------删除后---------------------"
|
||||
docker network ls
|
||||
}
|
||||
|
||||
|
||||
prepare_check
|
||||
|
||||
run
|
||||
Reference in New Issue
Block a user