update
This commit is contained in:
64
tomcat/ADD/ccmd
Executable file
64
tomcat/ADD/ccmd
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Mount dir #
|
||||
# - /opt/tomcat/webapps #
|
||||
# - /opt/tomcat/logs #
|
||||
# ENV #
|
||||
# - JAVA_OPTS #
|
||||
##################################################
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
PIDS=
|
||||
GOT_SIGTERM=
|
||||
export JAVA_OPTS="-server -Djava.security.egd=file:/dev/./urandom -Duser.timezone=GMT+08 ${JAVA_OPTS:-}"
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
[ '-f' = "$1" ] && file=$2 && shift && shift
|
||||
date +"[%F %T] $*" | tee -a $file
|
||||
}
|
||||
|
||||
function Quit {
|
||||
Print killing java ...
|
||||
while :; do
|
||||
pkill -f java && Print killing java ... || break
|
||||
sleep 1
|
||||
done
|
||||
Print Container stopped.
|
||||
test -n "$GOT_SIGTERM"
|
||||
}
|
||||
|
||||
function RestoreConf {
|
||||
if [ -z "$(ls conf/)" ]; then
|
||||
Print Restore default config files and quit ...
|
||||
tar zxf conf.tgz
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Start tomcat ...
|
||||
./bin/catalina.sh run &> /dev/null &
|
||||
PIDS="$PIDS $!"
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
cd /opt/tomcat
|
||||
RestoreConf
|
||||
StartProc
|
||||
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
|
||||
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
|
||||
for pid in $PIDS; do
|
||||
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
16
tomcat/Demo/SingleNode/README.md
Normal file
16
tomcat/Demo/SingleNode/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# 部署 tomcat
|
||||
|
||||
- 根据实际环境修改
|
||||
- docker-compose.yml
|
||||
|
||||
- 创建目录
|
||||
```
|
||||
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
|
||||
```
|
||||
|
||||
- 上传需要的 war 包到 tomcat/webapps/ 下
|
||||
- 启动
|
||||
```
|
||||
docker-compose up -d
|
||||
```
|
||||
|
18
tomcat/Demo/SingleNode/docker-compose.yml
Normal file
18
tomcat/Demo/SingleNode/docker-compose.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
tomcat:
|
||||
image: harbor.colben.cn/general/tomcat:8
|
||||
container_name: tomcat
|
||||
restart: "on-failure"
|
||||
stop_grace_period: 1m
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./tomcat/webapps
|
||||
target: /opt/tomcat/webapps
|
||||
- type: bind
|
||||
source: ./tomcat/logs
|
||||
target: /opt/tomcat/logs
|
||||
|
17
tomcat/Dockerfile
Normal file
17
tomcat/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
ARG ARCH
|
||||
FROM harbor.colben.cn/general/jdk$ARCH:8
|
||||
MAINTAINER Colben colbenlee@gmail.com
|
||||
ARG VERSION
|
||||
ADD --chown=root:root /ADD/ /opt/
|
||||
RUN tdnf makecache \
|
||||
&& tdnf -y install apache-tomcat-native \
|
||||
&& curl -LO https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v$VERSION/bin/apache-tomcat-$VERSION.tar.gz \
|
||||
&& tar zxf apache-tomcat-$VERSION.tar.gz \
|
||||
&& rm -rf /var/cache/tdnf apache-tomcat-$VERSION.tar.gz \
|
||||
&& mv apache-tomcat-$VERSION /opt/tomcat \
|
||||
&& cd /opt/tomcat \
|
||||
&& sed -i '69s/protocol.*$/protocol="org.apache.coyote.http11.Http11AprProtocol"/' conf/server.xml \
|
||||
&& tar zcf conf.tgz conf \
|
||||
&& rm -rf conf/* webapps/* bin/*.gz bin/*.bat BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt
|
||||
CMD ["/opt/ccmd"]
|
||||
|
16
tomcat/README.md
Normal file
16
tomcat/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# 构建 tomcat 镜像
|
||||
|
||||
## 定制
|
||||
- 安装 apache-tomcat-native
|
||||
- 开启 apr
|
||||
|
||||
## 外挂目录和文件
|
||||
- /opt/tomcat/webapps: 应用 war 包目录
|
||||
- /opt/tomcat/logs: 日志目录
|
||||
|
||||
## 引入环境变量
|
||||
- JAVA_OPTS: jvm 参数
|
||||
|
||||
## 案例
|
||||
- [Demo/SingleNode/](Demo/SingleNode/): 部署 tomcat
|
||||
|
68
tomcat/tomcat.sh
Executable file
68
tomcat/tomcat.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
#=========================================
|
||||
# Author : colben
|
||||
#=========================================
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
trap Quit EXIT
|
||||
|
||||
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
|
||||
ROOT_DIR="$(cd $(dirname $0) && pwd)"
|
||||
VERSION=$1
|
||||
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:${VERSION%%.*}"
|
||||
|
||||
if [ -t 0 ]; then
|
||||
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
|
||||
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
|
||||
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
|
||||
else
|
||||
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
|
||||
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
|
||||
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
|
||||
fi
|
||||
|
||||
function Quit {
|
||||
local exitCode=$?
|
||||
[ 0 -ne $exitCode ] && Error Failed to build or push image!
|
||||
[ -z "${END:-}" ] && echo && Error Interrupted manually!
|
||||
Print Succeeded to build and push image.
|
||||
}
|
||||
|
||||
function YesOrNo {
|
||||
Warn $*
|
||||
local sw=
|
||||
while :; do
|
||||
read -p '(Yes/No/Quit) ' -n1 sw
|
||||
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
|
||||
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
|
||||
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
|
||||
[ -n "$sw" ] && echo
|
||||
done
|
||||
}
|
||||
|
||||
function Update {
|
||||
:
|
||||
}
|
||||
|
||||
function Build {
|
||||
local yn
|
||||
cd $ROOT_DIR
|
||||
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
|
||||
&& Warn Removing image $IMAGE ... \
|
||||
&& docker rmi $IMAGE
|
||||
Warn Building image: $IMAGE ...
|
||||
docker build --force-rm --build-arg ARCH="$ARCH" --build-arg VERSION="$VERSION" -t $IMAGE .
|
||||
YesOrNo Push image: $IMAGE? && docker push $IMAGE
|
||||
}
|
||||
|
||||
function Main {
|
||||
Update
|
||||
Build
|
||||
END=1
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
Reference in New Issue
Block a user