From 29182b3285a186d9c4107f25faccf5b07222b4df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=91=E5=B9=B4=E6=A2=A6=E4=B8=8E=E7=A0=96?=
<2847127106@qq.com>
Date: Mon, 29 Jul 2024 09:46:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 1 +
src/main/resources/deploy.sh | 44 ++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 src/main/resources/deploy.sh
diff --git a/pom.xml b/pom.xml
index f28bdf0..c8890e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,6 +9,7 @@
4.0.0
cloud-gateway
+
1.0.0
diff --git a/src/main/resources/deploy.sh b/src/main/resources/deploy.sh
new file mode 100644
index 0000000..39ca108
--- /dev/null
+++ b/src/main/resources/deploy.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# 初始化变量
+export imageName
+export imageTag
+
+while getopts "n:t:" opt
+do
+ case $opt in
+ n)
+ imageName=$OPTARG;;
+ t)
+ imageTag=$OPTARG;;
+ ?)
+ echo "未知参数"
+ exit 1;;
+ esac
+done
+
+# 检查是否成功设置了imagesName和imageTag(理论上这一步在这里是多余的,因为我们已经在上面检查了参数数量)
+if [ -z "$imageName" ]; then
+ echo "镜像名称未设置,请检查!"
+ exit 1
+fi
+if [ -z "$imageTag" ]; then
+ echo "镜像标签未设置,请检查!"
+ exit 1
+fi
+
+
+if docker ps -a -f "name=$imageName" | grep "$imageName"; then
+ echo "容器 $imageName 已存在,开始删除!"
+ docker rm -f $imageName
+else
+ echo "容器 $imageName 不存在,开始创建!"
+fi
+
+export image=$imageName:$imageTag
+
+docker run -d \
+ --name $imageName \
+ --network dev-cloud \
+ -v /home/images/deploy/logs/$imageName:/home/logs/$imageName \
+ $image