.env
COMPOSE_PROJECT_NAME=projectname
VOLUME_PATH=/volume/projectname/app
deploy.sh
#!/bin/bash
usage () {
echo " Usage: launcher COMMAND [--docker-args STRING]"
echo " Commands:"
echo " create: Initialize the container"
echo " start: Start container"
echo " stop: Stop a running container"
echo " restart: Restart the container"
echo " destroy: Stop and remove the container"
echo " bootstrap: Bootstrap the image"
echo " reload: Destroy->Bootstrap->Start"
echo " download: download images"
echo " publish: publish deploy to ? server "
exit 1
}
LAUNCHER_DIR=${0%/*}
set -e
set -o pipefail
loginfo() {
if [[ -t 1 ]]; then
>&2 printf "[$(date +'%Y-%m-%d %H:%M:%S')] \033[32m%s\033[m\n" "$1"
else
>&2 echo "[$(date +'%Y-%m-%d %H:%M:%S')] " "$1"
fi
}
err_and_quit () {
if [[ -t 1 ]]; then
>&2 printf "\n\n\033[33mError: %s\033[m\n\n" "$1"
else
>&2 echo "$1"
fi
exit 1
}
_bootstrap () {
local path
path=`pwd`
if [ -d images ];then
cd $LAUNCHER_DIR/images
for image in `ls *.tar`
do
docker load -i $image
done
fi
cd $path
}
simple_cmd () {
local path
path=`pwd`
cd $LAUNCHER_DIR
docker-compose --compatibility $@
cd $path
}
_create () {
simple_cmd create
}
_start () {
simple_cmd up -d
}
_stop () {
simple_cmd stop
}
_restart () {
simple_cmd restart
}
_destroy () {
simple_cmd stop
simple_cmd rm -v -f
}
_reload () {
_destroy
_bootstrap
_start
}
_read_docker_compose(){
indx=0
sed -i 's/\r//' docker-compose.yml
DOWNLOAD_ARR=()
while read LINE; do
pos=`echo "$LINE" | awk -F ''image:'' '{printf "%d", length($0)-length($NF)}'`
if [[ $pos -ne 0 ]]; then
echo ${LINE:$pos+1};
DOWNLOAD_ARR[$indx]=${LINE:$pos+1};
indx=$indx+1;
fi
done < ./docker-compose.yml
#echo ${DOWNLOAD_ARR[*]}
}
_strindex(){
x="${1%%$2*}"
[[ $x = $1 ]] && echo -1 || echo ${#x}
}
_download(){
cd $LAUNCHER_DIR
#if [ -d images ];then
#rm -rf images
#fi
if [ ! -d images ];then
mkdir images
fi
#if [ ! -d images ];then
#mkdir images
_read_docker_compose
#else
DW_IMAGE=()
DW_INDEX=0
for down in ${DOWNLOAD_ARR[*]};do
imgfilename=${down.}
imgfilename=${imgfilename//:/.}
echo "检查images文件夹中是否已下载此版本文件" $down
match="false"
if [ -d images ];then
for image in `ls ./images/*.tar`
do
if [ "./images/${imgfilename}.tar" = $image ];then
match="true";
break;
fi
done
fi
echo $match
if [ ${match} = "true" ];then
echo "版本文件已存在,无需下载" $down
continue;
fi
#删除旧版本文件 下载新版本
if [ -d images ];then
for image in `ls ./images/*.tar`
do
pos=`echo "$down" | awk -F '':'' '{printf "%d", length($0)-length($NF)}'`
tmp=${down:0:pos-1}
tmp=${tmp.}
x="${image%%$tmp*}"
if [ $x != $image ];then
rm -rf $image
fi
done
fi
echo "开始下载image文件:" $down
docker pull $down
echo "开始保存image文件:" "./images/${imgfilename}.tar"
docker save $down -o "./images/${imgfilename}.tar"
DW_IMAGE[$DW_INDEX]="./images/${imgfilename}.tar"
DW_INDEX=$DW_INDEX+1
done
#fi
chmod 777 ./images/*
if [ -e images/update.txt ];then
rm ./images/update.txt
fi
touch ./images/update.txt
for str in ${DW_IMAGE[*]};do
echo $str >> ./images/update.txt
done
}
_publish(){
cd $LAUNCHER_DIR
sed -i 's/\r//' ./images/update.txt
while read LINE; do
echo $LINE
sshpass -v -p fsy@2021 scp -r -P 6605 $LINE fsy@61.163.1.42:/home/fsy/2205_RELEASE/deploy/images
sshpass -v -p Fsyjk012345 scp -r -P 9082 $LINE fsyjk@110.185.165.236:/data/2205/deploy/images
#scp -r -P 6605 $LINE fsy@61.163.1.42:/home/fsy/2205_RELEASE/deploy/images
done < ./images/update.txt
}
if [[ $# -gt 0 ]]; then
case "$1" in
bootstrap|create|start|stop|restart|destroy|reload|download|publish)
_$1; exit 1;;
-h|--help) usage;;
*) err_and_quit "Argument error. Please see help." ;;
esac
fi
compose文件
version: "3"
services:
portainer:
image: reg.ji.com/portainer/portainer:1.21.0
restart: always
ports:
- 9000:9000
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "$VOLUME_PATH/portainer/data:/data"
postgres:
image: reg.ji.com/postgres-timescaledb-postgis-pg_cron:pg12-2.0.0-1.3
restart: always
environment:
#- POSTGRES_DB=prest
- POSTGRES_PASSWORD=@Junction-info.com
- TZ=PRC
- PGTZ=PRC
ports:
- 5432:5432
volumes:
- "$VOLUME_PATH/postgresql_timescaledb_postgis/data:/var/lib/postgresql/data"
- "$VOLUME_PATH/postgresql_timescaledb_postgis/init//:/docker-entrypoint-initdb.d/"
pgadmin4:
image: reg.ji.com/pgadmin4:5.6
ports:
- 5433:80
user: root
privileged: true
environment:
- PGADMIN_DEFAULT_EMAIL=admin@junction-info.com
- PGADMIN_DEFAULT_PASSWORD=@Junction-info.com
volumes:
- "$VOLUME_PATH/pgadmin:/var/lib/pgadmin"
redis:
image: reg.ji.com/redis:5.0.5-alpine
restart: always
ports:
- 6379:6379
influxdb:
image: reg.ji.com/influxdb:1.7.7-alpine
restart: always
volumes:
- "$VOLUME_PATH/influxdb:/var/lib/influxdb"
ports:
- 8086:8086
entrypoint:
- /entrypoint.sh
command: sh -c "sleep 10 && influx -execute \"create database mydb;CREATE RETENTION POLICY one_month ON mydb DURATION 30d REPLICATION 1 DEFAULT;\" & influxd "
redisredisinsight:
image: reg.ji.com/redisinsight:1.10.1
restart: always
user: root
privileged: true
ports:
- 8001:8001
volumes:
- "$VOLUME_PATH/redisinsight/db:/db"
pulsar:
image: reg.ji.com/apache_pulsar:2.8.0
restart: always
entrypoint: sh -c " bin/pulsar standalone > pulsar.log 2>&1 & sleep 60 && bin/pulsar-admin clusters update standalone --url http://10.10.11.192:8081 --broker-url pulsar://10.10.11.192:6650 & tail -F pulsar.log"
ports:
- 6650:6650
- 8081:8080
volumes:
- "$VOLUME_PATH/pulsar/data:/pulsar/data"
- "$VOLUME_PATH/pulsar/conf:/pulsar/conf"
pulsar_manager:
image: reg.ji.com/apache_pulsar_manager:0.2.0
restart: always
user: root
privileged: true
environment:
- SPRING_CONFIGURATION_FILE=/pulsar-manager/pulsar-manager/application.properties
- REDIRECT_HOST=http://192.168.99.100
- REDIRECT_PORT=9527
- DRIVER_CLASS_NAME=org.postgresql.Driver
- URL=jdbc:postgresql://postgres:5432/pulsar_manager
- USERNAME=postgres
- PASSWORD=@Junction-info.com
- LOG_LEVEL=INFO
#- JWT_TOKEN=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJteS10ZXN0In0.hE_uDehkv92VS2b1PPkDvkSK48NUZhv2jTG7MiKqdpY
#- SECRET_KEY=data:base64,67r9KG04WWEpzIJ3pxFO3gO76/fzaOnh8ywADBDCcIs=
ports:
- 7750:7750
- 9527:9527
depends_on:
- pulsar
- postgres
links:
- pulsar
#volumes:
#- "$VOLUME_PATH/pulsar-manager/application.properties:/pulsar-manager/pulsar-manager/application.properties"
#- "$VOLUME_PATH/pulsar-manager/my-secret.key:/pulsar-manager/pulsar-manager/my-secret.key"
#- "$VOLUME_PATH/pulsar-manager/bkvm.conf:/pulsar-manager/pulsar-manager/bkvm.conf"
minio:
image: reg.ji.com/minio:2021-05-27
hostname: minio
volumes:
- "$VOLUME_PATH/minio/data:/data"
- "$VOLUME_PATH/minio/config:/root/.minio"
expose:
- "9000"
ports:
- 9001:9000
environment:
- MINIO_ROOT_USER=minio
- MINIO_ROOT_PASSWORD=minio123
- MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
- MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- MINIO_NOTIFY_WEBHOOK_ENABLE=ON
- MINIO_NOTIFY_WEBHOOK_ENDPOINT=http://192.168.0.8:8091/webhooks
#- MINIO_IDENTITY_OPENID_CONFIG_URL=http://10.10.11.190:8081/auth/realms/demo/.well-known/openid-configuration
#- MINIO_IDENTITY_OPENID_CLINET_ID=minio
#- MINIO_IDENTITY_OPENID_SCOPES=openid,profile,email
#- MINIO_ROOT_USER_FILE=access_key
#- MINIO_ROOT_PASSWORD_FILE=secret_key
#- MINIO_KMS_SECRET_KEY_FILE=kms_master_key
#- MINIO_UPDATE_MINISIGN_PUBKEY=RWTx5Zr1tiHQLwG9keckT0c45M3AGeHD6IvimQHpyRywVWGbP1aVSGav
command: server /data
healthcheck:
test: ["CMD", "curl", "-f", "http://minio:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
minio_mc:
image: reg.ji.com/minio_mc:2021-05-26
depends_on:
- minio
entrypoint: >
/bin/sh -c "
/usr/bin/mc config host add minio http://minio:9000 ;"
minio_console:
image: reg.ji.com/minio_console:0.9.6
depends_on:
- minio
ports:
- 9090:9090
environment:
- CONSOLE_MINIO_SERVER=http://minio:9000
entrypoint: /console server
traefik:
image: reg.ji.com/traefik:2.4.5
restart: always
security_opt:
- no-new-privileges:true
ports:
- 80:80
- 8080:8080
command:
- "--log.level=DEBUG"
- "--log.format=json"
- "--api=true"
- "--api.insecure=true"
- "--api.dashboard=true"
- "--entrypoints.web2.address=:80"
- "--providers.docker=true"
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
- "--providers.docker.exposedbydefault=false"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.enable=true"
- "traefik.docker.network=2101_default"
- "traefik.http.middlewares.add-traefik.addprefix.prefix=/2101"
- "traefik.frontend.backend=2101"