mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
Merge github.com:gogf/gf into personal/hailaz
This commit is contained in:
43
.github/workflows/ci-main.yml
vendored
43
.github/workflows/ci-main.yml
vendored
@ -20,6 +20,13 @@ on:
|
||||
- feature/**
|
||||
- enhance/**
|
||||
- fix/**
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
debug:
|
||||
type: boolean
|
||||
description: 'Enable tmate Debug'
|
||||
required: false
|
||||
default: false
|
||||
|
||||
# This allows a subsequently queued workflow run to interrupt previous runs
|
||||
concurrency:
|
||||
@ -47,7 +54,7 @@ jobs:
|
||||
# Service containers to run with `code-test`
|
||||
services:
|
||||
# Etcd service.
|
||||
# docker run -d --name etcd -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes bitnamilegacy/etcd:3.4.24
|
||||
# docker run -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes bitnamilegacy/etcd:3.4.24
|
||||
etcd:
|
||||
image: bitnamilegacy/etcd:3.4.24
|
||||
env:
|
||||
@ -68,7 +75,7 @@ jobs:
|
||||
- 6379:6379
|
||||
|
||||
# MySQL backend server.
|
||||
# docker run -d --name mysql \
|
||||
# docker run \
|
||||
# -p 3306:3306 \
|
||||
# -e MYSQL_DATABASE=test \
|
||||
# -e MYSQL_ROOT_PASSWORD=12345678 \
|
||||
@ -82,7 +89,7 @@ jobs:
|
||||
- 3306:3306
|
||||
|
||||
# MariaDb backend server.
|
||||
# docker run -d --name mariadb \
|
||||
# docker run \
|
||||
# -p 3307:3306 \
|
||||
# -e MYSQL_DATABASE=test \
|
||||
# -e MYSQL_ROOT_PASSWORD=12345678 \
|
||||
@ -96,7 +103,7 @@ jobs:
|
||||
- 3307:3306
|
||||
|
||||
# PostgreSQL backend server.
|
||||
# docker run -d --name postgres \
|
||||
# docker run \
|
||||
# -p 5432:5432 \
|
||||
# -e POSTGRES_PASSWORD=12345678 \
|
||||
# -e POSTGRES_USER=postgres \
|
||||
@ -143,7 +150,7 @@ jobs:
|
||||
--health-retries 10
|
||||
|
||||
# ClickHouse backend server.
|
||||
# docker run -d --name clickhouse \
|
||||
# docker run \
|
||||
# -p 9000:9000 -p 8123:8123 -p 9001:9001 \
|
||||
# clickhouse/clickhouse-server:24.11.1.2557-alpine
|
||||
clickhouse-server:
|
||||
@ -154,7 +161,7 @@ jobs:
|
||||
- 9001:9001
|
||||
|
||||
# Polaris backend server.
|
||||
# docker run -d --name polaris \
|
||||
# docker run \
|
||||
# -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091 \
|
||||
# polarismesh/polaris-standalone:v1.17.2
|
||||
polaris:
|
||||
@ -191,6 +198,17 @@ jobs:
|
||||
ports:
|
||||
- 5236:5236
|
||||
|
||||
# openGauss server
|
||||
# docker run --privileged=true -e GS_PASSWORD=UTpass@1234 -p 9950:5432 opengauss/opengauss:7.0.0-RC1.B023
|
||||
gaussdb:
|
||||
image: opengauss/opengauss:7.0.0-RC1.B023
|
||||
env:
|
||||
GS_PASSWORD: UTpass@1234
|
||||
TZ: Asia/Shanghai
|
||||
ports:
|
||||
- 9950:5432
|
||||
|
||||
|
||||
zookeeper:
|
||||
image: zookeeper:3.8
|
||||
ports:
|
||||
@ -207,6 +225,19 @@ jobs:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Setup tmate Session
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug }}
|
||||
with:
|
||||
detached: true
|
||||
limit-access-to-actor: false
|
||||
|
||||
- name: Free Disk Space
|
||||
run: |
|
||||
df -h /
|
||||
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/hostedtoolcache/CodeQL /opt/hostedtoolcache/Python || true
|
||||
df -h /
|
||||
|
||||
- name: Start Apollo Containers
|
||||
run: docker compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build
|
||||
|
||||
|
||||
5
.github/workflows/release.yml
vendored
5
.github/workflows/release.yml
vendored
@ -17,11 +17,12 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout Github Code
|
||||
uses: actions/checkout@v5
|
||||
|
||||
|
||||
- name: Set Up Golang Environment
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.25
|
||||
cache: false
|
||||
|
||||
- name: Build CLI Binary
|
||||
run: |
|
||||
@ -34,7 +35,7 @@ jobs:
|
||||
- name: Build CLI Binary For All Platform
|
||||
run: |
|
||||
cd cmd/gf
|
||||
gf build main.go -n gf -a all -s all -p temp
|
||||
gf build main.go -n gf -a all -s linux,windows,darwin,freebsd,netbsd,openbsd -p temp
|
||||
|
||||
- name: Move Files Before Release
|
||||
run: |
|
||||
|
||||
0
.github/workflows/scripts/before_script.sh
vendored
Normal file → Executable file
0
.github/workflows/scripts/before_script.sh
vendored
Normal file → Executable file
250
.github/workflows/scripts/ci-main-clean.sh
vendored
Executable file
250
.github/workflows/scripts/ci-main-clean.sh
vendored
Executable file
@ -0,0 +1,250 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
dirpath=$1
|
||||
|
||||
# Extract the base directory name for pattern matching
|
||||
if [ -n "$dirpath" ]; then
|
||||
dirname=$(basename "$dirpath")
|
||||
echo "Cleaning Docker resources for path: $dirpath (pattern: $dirname)"
|
||||
df -h /
|
||||
|
||||
# Process containers and images based on the directory
|
||||
case "$dirname" in
|
||||
# "mysql")
|
||||
# echo "Cleaning mysql resources..."
|
||||
# containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
# if [ -n "$containers" ]; then
|
||||
# echo "Stopping and removing mysql containers..."
|
||||
# docker stop $containers 2>/dev/null || true
|
||||
# docker rm -f $containers 2>/dev/null || true
|
||||
# fi
|
||||
# docker rmi -f $(docker images -q mysql 2>/dev/null) 2>/dev/null || true
|
||||
# ;;
|
||||
"mssql")
|
||||
echo "Cleaning mssql resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing mssql containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q mcr.microsoft.com/mssql/server 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
"pgsql")
|
||||
echo "Cleaning postgres resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing postgres containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q postgres 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
"oracle")
|
||||
echo "Cleaning oracle resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing oracle containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q loads/oracle-xe-11g-r2 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
"dm")
|
||||
echo "Cleaning dm resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing dm containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q loads/dm 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
"clickhouse")
|
||||
echo "Cleaning clickhouse resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing clickhouse containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q clickhouse/clickhouse-server 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
# "redis")
|
||||
# echo "Cleaning redis resources..."
|
||||
# containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
# if [ -n "$containers" ]; then
|
||||
# echo "Stopping and removing redis containers..."
|
||||
# docker stop $containers 2>/dev/null || true
|
||||
# docker rm -f $containers 2>/dev/null || true
|
||||
# fi
|
||||
# docker rmi -f $(docker images -q redis loads/redis loads/redis-sentinel 2>/dev/null) 2>/dev/null || true
|
||||
# ;;
|
||||
"etcd")
|
||||
echo "Cleaning etcd resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing etcd containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q bitnamilegacy/etcd 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
# "consul")
|
||||
# echo "Cleaning consul resources..."
|
||||
# containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
# if [ -n "$containers" ]; then
|
||||
# echo "Stopping and removing consul containers..."
|
||||
# docker stop $containers 2>/dev/null || true
|
||||
# docker rm -f $containers 2>/dev/null || true
|
||||
# fi
|
||||
# docker rmi -f $(docker images -q consul 2>/dev/null) 2>/dev/null || true
|
||||
# ;;
|
||||
# "nacos")
|
||||
# echo "Cleaning nacos resources..."
|
||||
# containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
# if [ -n "$containers" ]; then
|
||||
# echo "Stopping and removing nacos containers..."
|
||||
# docker stop $containers 2>/dev/null || true
|
||||
# docker rm -f $containers 2>/dev/null || true
|
||||
# fi
|
||||
# docker rmi -f $(docker images -q nacos/nacos-server 2>/dev/null) 2>/dev/null || true
|
||||
# ;;
|
||||
# "polaris")
|
||||
# echo "Cleaning polaris resources..."
|
||||
# containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
# if [ -n "$containers" ]; then
|
||||
# echo "Stopping and removing polaris containers..."
|
||||
# docker stop $containers 2>/dev/null || true
|
||||
# docker rm -f $containers 2>/dev/null || true
|
||||
# fi
|
||||
# docker rmi -f $(docker images -q polarismesh/polaris-standalone 2>/dev/null) 2>/dev/null || true
|
||||
# ;;
|
||||
"zookeeper")
|
||||
echo "Cleaning zookeeper resources..."
|
||||
containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
if [ -n "$containers" ]; then
|
||||
echo "Stopping and removing zookeeper containers..."
|
||||
docker stop $containers 2>/dev/null || true
|
||||
docker rm -f $containers 2>/dev/null || true
|
||||
fi
|
||||
docker rmi -f $(docker images -q zookeeper 2>/dev/null) 2>/dev/null || true
|
||||
;;
|
||||
# "apollo")
|
||||
# echo "Cleaning apollo resources..."
|
||||
# containers=$(docker ps -aq --filter "name=$dirname" 2>/dev/null)
|
||||
# if [ -n "$containers" ]; then
|
||||
# echo "Stopping and removing apollo containers..."
|
||||
# docker stop $containers 2>/dev/null || true
|
||||
# docker rm -f $containers 2>/dev/null || true
|
||||
# fi
|
||||
# docker rmi -f $(docker images -q loads/apollo-quick-start 2>/dev/null) 2>/dev/null || true
|
||||
# ;;
|
||||
*)
|
||||
# No matching pattern, skip cleanup
|
||||
echo "No specific Docker cleanup rule for '$dirname', skipping cleanup"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Remove dangling images and volumes to free up space
|
||||
echo "Removing dangling images and unused volumes..."
|
||||
docker image prune -f 2>/dev/null || true
|
||||
docker volume prune -f 2>/dev/null || true
|
||||
|
||||
echo "Docker cleanup completed for $dirname"
|
||||
docker system df
|
||||
df -h /
|
||||
fi
|
||||
|
||||
# df -h /
|
||||
# Filesystem Size Used Avail Use% Mounted on
|
||||
# /dev/root 72G 67G 5.4G 93% /
|
||||
# tmpfs 7.9G 84K 7.9G 1% /dev/shm
|
||||
# tmpfs 3.2G 2.6M 3.2G 1% /run
|
||||
# tmpfs 5.0M 0 5.0M 0% /run/lock
|
||||
# /dev/sdb16 881M 62M 758M 8% /boot
|
||||
# /dev/sdb15 105M 6.2M 99M 6% /boot/efi
|
||||
# /dev/sda1 74G 4.1G 66G 6% /mnt
|
||||
# tmpfs 1.6G 12K 1.6G 1% /run/user/1001
|
||||
|
||||
# runner@runnervmg1sw1:~/work/gf/gf$ docker system df
|
||||
# TYPE TOTAL ACTIVE SIZE RECLAIMABLE
|
||||
# Images 18 11 8.326GB 1.644GB (19%)
|
||||
# Containers 11 11 2.692GB 0B (0%)
|
||||
# Local Volumes 11 8 665.7MB 211.9MB (31%)
|
||||
# Build Cache 0 0 0B 0B
|
||||
|
||||
# runner@runnervmg1sw1:~/work/gf/gf$ docker images
|
||||
# REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
# alpine/curl latest 99fd43792a61 2 days ago 13.5MB
|
||||
# postgres 17-alpine b6bf692a8125 9 days ago 278MB
|
||||
# zookeeper 3.8 2f26c02b94ca 10 days ago 306MB
|
||||
# mariadb 11.4 063fb6684f96 10 days ago 332MB
|
||||
# mcr.microsoft.com/mssql/server 2022-latest a2fbff321505 4 weeks ago 1.61GB
|
||||
# clickhouse/clickhouse-server 24.11.1.2557-alpine 2eee9fd3ae74 12 months ago 539MB
|
||||
# redis 7.0 7705dd2858c1 18 months ago 109MB
|
||||
# consul 1.15 686495461132 20 months ago 155MB
|
||||
# mysql 5.7 5107333e08a8 23 months ago 501MB
|
||||
# polarismesh/polaris-standalone v1.17.2 b7a8cf0a8438 2 years ago 545MB
|
||||
# bitnamilegacy/etcd 3.4.24 74ae5e205ac5 2 years ago 134MB
|
||||
# nacos/nacos-server v2.1.2 a978644d9246 2 years ago 1.06GB
|
||||
# loads/redis 7.0-sentinel 6f12d40540ba 3 years ago 114MB
|
||||
# loads/dm v8.1.2.128_ent_x86_64_ctm_pack4 ccb727ce9dce 3 years ago 432MB
|
||||
# loads/redis-sentinel 7.0 6818c626f5ca 3 years ago 104MB
|
||||
# loads/apollo-quick-start latest 8490de672148 3 years ago 190MB
|
||||
# alpine 3.8 c8bccc0af957 5 years ago 4.41MB
|
||||
# loads/oracle-xe-11g-r2 11.2.0 0d19fd2e072e 6 years ago 2.1GB
|
||||
|
||||
# runner@runnervmg1sw1:~/work/gf/gf$ docker ps -s
|
||||
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
|
||||
# 8214f83420c6 zookeeper:3.8 "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, [::]:2181->2181/tcp, 8080/tcp d66bac92ae9646f688f70ed4b5176f14_zookeeper38_3a22ef 33kB (virtual 306MB)
|
||||
# 8938d73842e8 loads/dm:v8.1.2.128_ent_x86_64_ctm_pack4 "/bin/bash /opt/star…" 6 minutes ago Up 6 minutes 0.0.0.0:5236->5236/tcp, [::]:5236->5236/tcp ca280fbdb86f40c2acf86d7d526c6285_loadsdmv812128_ent_x86_64_ctm_pack4_770a59 844MB (virtual 1.28GB)
|
||||
# 0d3a653fe1f2 loads/oracle-xe-11g-r2:11.2.0 "/bin/sh -c '/usr/sb…" 6 minutes ago Up 6 minutes 22/tcp, 8080/tcp, 0.0.0.0:1521->1521/tcp, [::]:1521->1521/tcp 2048856d428c4967b1c35193eb8c9192_loadsoraclexe11gr21120_295d54 1.3GB (virtual 3.4GB)
|
||||
# ca3936189166 polarismesh/polaris-standalone:v1.17.2 "/bin/bash run.sh" 6 minutes ago Up 6 minutes 0.0.0.0:8090-8091->8090-8091/tcp, [::]:8090-8091->8090-8091/tcp, 8080/tcp, 8100-8101/tcp, 0.0.0.0:8093->8093/tcp, [::]:8093->8093/tcp, 8761/tcp, 15010/tcp, 0.0.0.0:9090-9091->9090-9091/tcp, [::]:9090-9091->9090-9091/tcp cbd43dceef754e2d8aab507e33167be7_polarismeshpolarisstandalonev1172_ca40b6 299MB (virtual 844MB)
|
||||
# 26169dad485e clickhouse/clickhouse-server:24.11.1.2557-alpine "/entrypoint.sh" 6 minutes ago Up 6 minutes 0.0.0.0:8123->8123/tcp, [::]:8123->8123/tcp, 0.0.0.0:9000-9001->9000-9001/tcp, [::]:9000-9001->9000-9001/tcp, 9009/tcp f1c7766fbe36401792a6f735d7acf123_clickhouseclickhouseserver241112557alpine_cfc034 338kB (virtual 539MB)
|
||||
# 04689a1d581f mcr.microsoft.com/mssql/server:2022-latest "/opt/mssql/bin/laun…" 6 minutes ago Up 6 minutes (healthy) 0.0.0.0:1433->1433/tcp, [::]:1433->1433/tcp 41d685349a7640b28230db8d0f60efe7_mcrmicrosoftcommssqlserver2022latest_fe29fb 108MB (virtual 1.72GB)
|
||||
# d5fbc5f811af postgres:17-alpine "docker-entrypoint.s…" 6 minutes ago Up 6 minutes (healthy) 0.0.0.0:5432->5432/tcp, [::]:5432->5432/tcp 2783be71b5ce417ab9a31428e7b4d8f2_postgres17alpine_c60840 63B (virtual 278MB)
|
||||
# da96a7ad7a01 mariadb:11.4 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:3307->3306/tcp, [::]:3307->3306/tcp 45eed646fa6c4a698893ee11cda95a4c_mariadb114_3a9cd6 2B (virtual 332MB)
|
||||
# 27ba1904ba3a mysql:5.7 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp, 33060/tcp ea6d7a4c207d427a95b5ae0db91fdf56_mysql57_c21053 4B (virtual 501MB)
|
||||
# 518e785d1bb6 redis:7.0 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes (healthy) 0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp af6044fc849e441bbc6c48f7a5ec5fec_redis70_b11994 0B (virtual 109MB)
|
||||
# 7495ec2cd8e3 bitnamilegacy/etcd:3.4.24 "/opt/bitnami/script…" 7 minutes ago Up 7 minutes 0.0.0.0:2379->2379/tcp, [::]:2379->2379/tcp, 2380/tcp 49f2a2a6bf3a4fae842cc950bbc3658a_bitnamilegacyetcd3424_1265e1 145MB (virtual 279MB)
|
||||
|
||||
# runner@runnervmg1sw1:~/work/gf/gf$ du -ah --max-depth=1 /usr | sort -n
|
||||
# 4.0K /usr/games
|
||||
# 4.0K /usr/lib64
|
||||
# 6.6G /usr/lib
|
||||
# 9.3G /usr/share
|
||||
# 15M /usr/lib32
|
||||
# 24G /usr/local
|
||||
# 41G /usr
|
||||
# 95M /usr/sbin
|
||||
# 156M /usr/include
|
||||
# 158M /usr/src
|
||||
# 402M /usr/libexec
|
||||
# 841M /usr/bin
|
||||
|
||||
# runner@runnervmg1sw1:~/work/gf/gf$ du -ah --max-depth=1 /opt | sort -n
|
||||
# 4.0K /opt/pipx_bin
|
||||
# 5.8G /opt/hostedtoolcache
|
||||
# 8.5G /opt
|
||||
# 12K /opt/containerd
|
||||
# 14M /opt/hca
|
||||
# 16K /opt/post-generation
|
||||
# 217M /opt/runner-cache
|
||||
# 243M /opt/actionarchivecache
|
||||
# 374M /opt/google
|
||||
# 515M /opt/pipx
|
||||
# 655M /opt/az
|
||||
# 783M /opt/microsoft
|
||||
|
||||
# runner@runnervmg1sw1:~/work/gf/gf$ du -ah --max-depth=1 /opt/hostedtoolcache/ | sort -n
|
||||
# 1.1G /opt/hostedtoolcache/go
|
||||
# 1.6G /opt/hostedtoolcache/CodeQL
|
||||
# 1.9G /opt/hostedtoolcache/Python
|
||||
# 5.8G /opt/hostedtoolcache/
|
||||
# 9.9M /opt/hostedtoolcache/protoc
|
||||
# 24K /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk
|
||||
# 217M /opt/hostedtoolcache/Ruby
|
||||
# 520M /opt/hostedtoolcache/PyPy
|
||||
# 574M /opt/hostedtoolcache/node
|
||||
|
||||
73
.github/workflows/scripts/ci-main.sh
vendored
Normal file → Executable file
73
.github/workflows/scripts/ci-main.sh
vendored
Normal file → Executable file
@ -2,65 +2,58 @@
|
||||
|
||||
coverage=$1
|
||||
|
||||
# update code of submodules
|
||||
git clone https://github.com/gogf/examples
|
||||
|
||||
# update go.mod in examples directory to replace github.com/gogf/gf packages with local directory
|
||||
bash .github/workflows/scripts/replace_examples_gomod.sh
|
||||
|
||||
# find all path that contains go.mod.
|
||||
for file in `find . -name go.mod`; do
|
||||
dirpath=$(dirname $file)
|
||||
echo $dirpath
|
||||
|
||||
# ignore mssql tests as its docker service failed
|
||||
# TODO remove this ignoring codes after the mssql docker service OK
|
||||
if [ "mssql" = $(basename $dirpath) ]; then
|
||||
continue 1
|
||||
fi
|
||||
|
||||
|
||||
# package kubecm was moved to sub ci procedure.
|
||||
if [ "kubecm" = $(basename $dirpath) ]; then
|
||||
continue 1
|
||||
fi
|
||||
|
||||
# Check if it's a contrib directory or examples directory
|
||||
if [[ $dirpath =~ "/contrib/" ]] || [[ $dirpath =~ "/examples/" ]]; then
|
||||
# Check if go version meets the requirement
|
||||
if ! go version | grep -qE "go${LATEST_GO_VERSION}"; then
|
||||
echo "ignore path $dirpath as go version is not ${LATEST_GO_VERSION}: $(go version)"
|
||||
continue 1
|
||||
fi
|
||||
# If it's examples directory, only build without tests
|
||||
if [[ $dirpath =~ "/examples/" ]]; then
|
||||
echo "the examples directory only needs to be built, not unit tests and coverage tests."
|
||||
cd $dirpath
|
||||
go mod tidy
|
||||
go build ./...
|
||||
cd -
|
||||
continue 1
|
||||
fi
|
||||
|
||||
# examples directory was moved to sub ci procedure.
|
||||
if [[ $dirpath =~ "/examples/" ]]; then
|
||||
continue 1
|
||||
fi
|
||||
|
||||
|
||||
if [[ $file =~ "/testdata/" ]]; then
|
||||
echo "ignore testdata path $file"
|
||||
continue 1
|
||||
fi
|
||||
|
||||
|
||||
# Check if it's a contrib directory
|
||||
if [[ $dirpath =~ "/contrib/" ]]; then
|
||||
# Check if go version meets the requirement
|
||||
if ! go version | grep -qE "go${LATEST_GO_VERSION}"; then
|
||||
echo "ignore path $dirpath as go version is not ${LATEST_GO_VERSION}: $(go version)"
|
||||
# clean docker containers and images to free disk space
|
||||
# bash .github/workflows/scripts/ci-main-clean.sh "$dirpath"
|
||||
continue 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# if [[ $dirpath = "." ]]; then
|
||||
# # No space left on device error sometimes occurs in CI pipelines, so clean the cache before tests.
|
||||
# go clean -cache
|
||||
# fi
|
||||
|
||||
cd $dirpath
|
||||
go mod tidy
|
||||
go build ./...
|
||||
|
||||
|
||||
# test with coverage
|
||||
if [ "${coverage}" = "coverage" ]; then
|
||||
go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1
|
||||
|
||||
if grep -q "/gogf/gf/.*/v2" go.mod; then
|
||||
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out
|
||||
fi
|
||||
go test ./... -count=1 -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1
|
||||
|
||||
if grep -q "/gogf/gf/.*/v2" go.mod; then
|
||||
sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out
|
||||
fi
|
||||
else
|
||||
go test ./... -race || exit 1
|
||||
go test ./... -count=1 -race || exit 1
|
||||
fi
|
||||
|
||||
|
||||
cd -
|
||||
# clean docker containers and images to free disk space
|
||||
# bash .github/workflows/scripts/ci-main-clean.sh "$dirpath"
|
||||
done
|
||||
|
||||
20
.github/workflows/scripts/ci-sub.sh
vendored
Normal file → Executable file
20
.github/workflows/scripts/ci-sub.sh
vendored
Normal file → Executable file
@ -2,6 +2,12 @@
|
||||
|
||||
coverage=$1
|
||||
|
||||
# update code of submodules
|
||||
git clone https://github.com/gogf/examples
|
||||
|
||||
# update go.mod in examples directory to replace github.com/gogf/gf packages with local directory
|
||||
bash .github/workflows/scripts/replace_examples_gomod.sh
|
||||
|
||||
# Function to compare version numbers
|
||||
version_compare() {
|
||||
local ver1=$1
|
||||
@ -35,7 +41,19 @@ for file in `find . -name go.mod`; do
|
||||
dirpath=$(dirname $file)
|
||||
echo "Processing: $dirpath"
|
||||
|
||||
# Only process kubecm directory, skip others
|
||||
# Only process examples and kubecm directories
|
||||
|
||||
# Process examples directory (only build, no tests)
|
||||
if [[ $dirpath =~ "/examples/" ]]; then
|
||||
echo " the examples directory only needs to be built, not unit tests."
|
||||
cd $dirpath
|
||||
go mod tidy
|
||||
go build ./...
|
||||
cd -
|
||||
continue 1
|
||||
fi
|
||||
|
||||
# Process kubecm directory
|
||||
if [ "kubecm" != $(basename $dirpath) ]; then
|
||||
echo " Skipping: not kubecm directory"
|
||||
continue
|
||||
|
||||
785
.github/workflows/scripts/docker-services.sh
vendored
Executable file
785
.github/workflows/scripts/docker-services.sh
vendored
Executable file
@ -0,0 +1,785 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# GoFrame Docker Services Manager
|
||||
# For managing Docker services used in local development and testing
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
# Container name prefix
|
||||
PREFIX="goframe"
|
||||
|
||||
# Color definitions
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Service definitions
|
||||
declare -A SERVICES
|
||||
declare -A SERVICE_PORTS
|
||||
declare -A SERVICE_ENVS
|
||||
declare -A SERVICE_OPTS
|
||||
|
||||
# Basic services
|
||||
SERVICES["etcd"]="bitnamilegacy/etcd:3.4.24"
|
||||
SERVICE_PORTS["etcd"]="2379:2379"
|
||||
SERVICE_ENVS["etcd"]="-e ALLOW_NONE_AUTHENTICATION=yes"
|
||||
|
||||
SERVICES["redis"]="redis:7.0"
|
||||
SERVICE_PORTS["redis"]="6379:6379"
|
||||
SERVICE_OPTS["redis"]="--health-cmd 'redis-cli ping' --health-interval 10s --health-timeout 5s --health-retries 5"
|
||||
|
||||
SERVICES["mysql"]="mysql:5.7"
|
||||
SERVICE_PORTS["mysql"]="3306:3306"
|
||||
SERVICE_ENVS["mysql"]="-e MYSQL_DATABASE=test -e MYSQL_ROOT_PASSWORD=12345678"
|
||||
|
||||
SERVICES["mariadb"]="mariadb:11.4"
|
||||
SERVICE_PORTS["mariadb"]="3307:3306"
|
||||
SERVICE_ENVS["mariadb"]="-e MARIADB_DATABASE=test -e MARIADB_ROOT_PASSWORD=12345678"
|
||||
|
||||
SERVICES["postgres"]="postgres:17-alpine"
|
||||
SERVICE_PORTS["postgres"]="5432:5432"
|
||||
SERVICE_ENVS["postgres"]="-e POSTGRES_PASSWORD=12345678 -e POSTGRES_USER=postgres -e POSTGRES_DB=test -e TZ=Asia/Shanghai"
|
||||
SERVICE_OPTS["postgres"]="--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5"
|
||||
|
||||
SERVICES["mssql"]="mcr.microsoft.com/mssql/server:2022-latest"
|
||||
SERVICE_PORTS["mssql"]="1433:1433"
|
||||
SERVICE_ENVS["mssql"]="-e TZ=Asia/Shanghai -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=LoremIpsum86"
|
||||
|
||||
SERVICES["clickhouse"]="clickhouse/clickhouse-server:24.11.1.2557-alpine"
|
||||
SERVICE_PORTS["clickhouse"]="9000:9000 -p 8123:8123 -p 9001:9001"
|
||||
|
||||
SERVICES["polaris"]="polarismesh/polaris-standalone:v1.17.2"
|
||||
SERVICE_PORTS["polaris"]="8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091"
|
||||
|
||||
SERVICES["oracle"]="loads/oracle-xe-11g-r2:11.2.0"
|
||||
SERVICE_PORTS["oracle"]="1521:1521"
|
||||
SERVICE_ENVS["oracle"]="-e ORACLE_ALLOW_REMOTE=true -e ORACLE_SID=XE -e ORACLE_DB_USER_NAME=system -e ORACLE_DB_PASSWORD=oracle"
|
||||
|
||||
SERVICES["dm"]="loads/dm:v8.1.2.128_ent_x86_64_ctm_pack4"
|
||||
SERVICE_PORTS["dm"]="5236:5236"
|
||||
|
||||
SERVICES["gaussdb"]="opengauss/opengauss:7.0.0-RC1.B023"
|
||||
SERVICE_PORTS["gaussdb"]="9950:5432"
|
||||
SERVICE_ENVS["gaussdb"]="-e GS_PASSWORD=UTpass@1234 -e TZ=Asia/Shanghai"
|
||||
SERVICE_OPTS["gaussdb"]="--privileged=true"
|
||||
|
||||
SERVICES["zookeeper"]="zookeeper:3.8"
|
||||
SERVICE_PORTS["zookeeper"]="2181:2181"
|
||||
|
||||
# Service groups
|
||||
GROUP_DB="mysql mariadb postgres mssql oracle dm gaussdb clickhouse"
|
||||
GROUP_CACHE="redis etcd"
|
||||
GROUP_REGISTRY="polaris zookeeper"
|
||||
GROUP_ALL="etcd redis mysql mariadb postgres mssql clickhouse polaris oracle dm gaussdb zookeeper"
|
||||
|
||||
# Working directories
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
WORKFLOW_DIR="$PROJECT_ROOT/.github/workflows"
|
||||
|
||||
# Print colored messages
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[OK]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if Docker is available
|
||||
check_docker() {
|
||||
if ! command -v docker &> /dev/null; then
|
||||
print_error "Docker is not installed or not in PATH"
|
||||
exit 1
|
||||
fi
|
||||
if ! docker info &> /dev/null; then
|
||||
print_error "Docker service is not running"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get container name
|
||||
get_container_name() {
|
||||
echo "${PREFIX}-$1"
|
||||
}
|
||||
|
||||
# Start a single service
|
||||
start_service() {
|
||||
local service=$1
|
||||
local container_name=$(get_container_name "$service")
|
||||
local image="${SERVICES[$service]}"
|
||||
local ports="${SERVICE_PORTS[$service]}"
|
||||
local envs="${SERVICE_ENVS[$service]}"
|
||||
local opts="${SERVICE_OPTS[$service]}"
|
||||
|
||||
if [ -z "$image" ]; then
|
||||
print_error "Unknown service: $service"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if container already exists
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
print_warning "$service is already running"
|
||||
return 0
|
||||
else
|
||||
print_info "Starting existing container $service..."
|
||||
docker start "$container_name" > /dev/null
|
||||
print_success "$service started"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_info "Starting $service..."
|
||||
|
||||
# Build docker run command
|
||||
local cmd="docker run -d --name $container_name"
|
||||
|
||||
# Add port mappings
|
||||
for port in $ports; do
|
||||
cmd="$cmd -p $port"
|
||||
done
|
||||
|
||||
# Add environment variables
|
||||
if [ -n "$envs" ]; then
|
||||
cmd="$cmd $envs"
|
||||
fi
|
||||
|
||||
# Add other options
|
||||
if [ -n "$opts" ]; then
|
||||
cmd="$cmd $opts"
|
||||
fi
|
||||
|
||||
cmd="$cmd $image"
|
||||
|
||||
if eval "$cmd" > /dev/null 2>&1; then
|
||||
print_success "$service started (container: $container_name)"
|
||||
else
|
||||
print_error "Failed to start $service"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop a single service
|
||||
stop_service() {
|
||||
local service=$1
|
||||
local container_name=$(get_container_name "$service")
|
||||
|
||||
if docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
print_info "Stopping $service..."
|
||||
docker stop "$container_name" > /dev/null
|
||||
print_success "$service stopped"
|
||||
else
|
||||
print_warning "$service is not running"
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove a single service
|
||||
remove_service() {
|
||||
local service=$1
|
||||
local container_name=$(get_container_name "$service")
|
||||
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
print_info "Removing $service..."
|
||||
docker rm -f "$container_name" > /dev/null
|
||||
print_success "$service removed"
|
||||
else
|
||||
print_warning "$service container does not exist"
|
||||
fi
|
||||
}
|
||||
|
||||
# View service logs
|
||||
logs_service() {
|
||||
local service=$1
|
||||
local container_name=$(get_container_name "$service")
|
||||
local lines=${2:-100}
|
||||
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
docker logs --tail "$lines" -f "$container_name"
|
||||
else
|
||||
print_error "$service container does not exist"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Start docker-compose service
|
||||
start_compose_service() {
|
||||
local service=$1
|
||||
local compose_file=""
|
||||
|
||||
case $service in
|
||||
apollo)
|
||||
compose_file="$WORKFLOW_DIR/apollo/docker-compose.yml"
|
||||
;;
|
||||
nacos)
|
||||
compose_file="$WORKFLOW_DIR/nacos/docker-compose.yml"
|
||||
;;
|
||||
redis-cluster)
|
||||
compose_file="$WORKFLOW_DIR/redis/docker-compose.yml"
|
||||
;;
|
||||
consul)
|
||||
compose_file="$WORKFLOW_DIR/consul/docker-compose.yml"
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown compose service: $service"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -f "$compose_file" ]; then
|
||||
print_info "Starting $service (docker-compose)..."
|
||||
docker compose -f "$compose_file" up -d
|
||||
print_success "$service started"
|
||||
else
|
||||
print_error "Compose file does not exist: $compose_file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Stop docker-compose service
|
||||
stop_compose_service() {
|
||||
local service=$1
|
||||
local compose_file=""
|
||||
|
||||
case $service in
|
||||
apollo)
|
||||
compose_file="$WORKFLOW_DIR/apollo/docker-compose.yml"
|
||||
;;
|
||||
nacos)
|
||||
compose_file="$WORKFLOW_DIR/nacos/docker-compose.yml"
|
||||
;;
|
||||
redis-cluster)
|
||||
compose_file="$WORKFLOW_DIR/redis/docker-compose.yml"
|
||||
;;
|
||||
consul)
|
||||
compose_file="$WORKFLOW_DIR/consul/docker-compose.yml"
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown compose service: $service"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -f "$compose_file" ]; then
|
||||
print_info "Stopping $service (docker-compose)..."
|
||||
docker compose -f "$compose_file" down
|
||||
print_success "$service stopped"
|
||||
else
|
||||
print_error "Compose file does not exist: $compose_file"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Show service status
|
||||
show_status() {
|
||||
echo ""
|
||||
echo -e "${CYAN}========== GoFrame Docker Services Status ==========${NC}"
|
||||
echo ""
|
||||
printf "%-15s %-12s %-30s %s\n" "SERVICE" "STATUS" "CONTAINER" "PORTS"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
|
||||
for service in $GROUP_ALL; do
|
||||
local container_name=$(get_container_name "$service")
|
||||
local status="stopped"
|
||||
local ports="-"
|
||||
|
||||
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^${container_name}$"; then
|
||||
status="${GREEN}running${NC}"
|
||||
ports=$(docker port "$container_name" 2>/dev/null | tr '\n' ' ' || echo "-")
|
||||
elif docker ps -a --format '{{.Names}}' 2>/dev/null | grep -q "^${container_name}$"; then
|
||||
status="${YELLOW}stopped${NC}"
|
||||
else
|
||||
status="${RED}not created${NC}"
|
||||
fi
|
||||
|
||||
printf "%-15s %-22b %-30s %s\n" "$service" "$status" "$container_name" "$ports"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}========== Compose Services ==========${NC}"
|
||||
echo ""
|
||||
|
||||
for compose_svc in apollo nacos redis-cluster consul; do
|
||||
local running=0
|
||||
case $compose_svc in
|
||||
apollo)
|
||||
running=$(docker ps --filter "name=apollo" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
nacos)
|
||||
running=$(docker ps --filter "name=nacos" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
redis-cluster)
|
||||
running=$(docker ps --filter "name=redis-" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
consul)
|
||||
running=$(docker ps --filter "name=consul" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$running" -gt 0 ]; then
|
||||
printf "%-15s ${GREEN}running${NC} (%d containers)\n" "$compose_svc" "$running"
|
||||
else
|
||||
printf "%-15s ${RED}stopped${NC}\n" "$compose_svc"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Show service information
|
||||
show_service_info() {
|
||||
echo ""
|
||||
echo -e "${CYAN}========== Available Services ==========${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Basic Services (standalone containers):${NC}"
|
||||
echo ""
|
||||
printf "%-15s %-50s %s\n" "SERVICE" "IMAGE" "PORTS"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
|
||||
for service in $GROUP_ALL; do
|
||||
printf "%-15s %-50s %s\n" "$service" "${SERVICES[$service]}" "${SERVICE_PORTS[$service]}"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}Compose Services (multi-container):${NC}"
|
||||
echo " apollo - Apollo Config Center (8080, 8070, 8060, 13306)"
|
||||
echo " nacos - Nacos Registry (8848, 9848, 9555)"
|
||||
echo " redis-cluster - Redis Primary-Replica + Sentinel Cluster (6380-6382, 26379-26381)"
|
||||
echo " consul - Consul Service Discovery (8500, 8600)"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Service Groups:${NC}"
|
||||
echo " db - Databases: $GROUP_DB"
|
||||
echo " cache - Cache: $GROUP_CACHE"
|
||||
echo " registry - Registry: $GROUP_REGISTRY"
|
||||
echo " all - All basic services"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Show help
|
||||
show_help() {
|
||||
echo ""
|
||||
echo -e "${CYAN}GoFrame Docker Services Manager${NC}"
|
||||
echo ""
|
||||
echo "Usage: $0 <command> [service|group] [options]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " start <service|group> Start service or service group"
|
||||
echo " stop <service|group> Stop service or service group"
|
||||
echo " restart <service|group> Restart service or service group"
|
||||
echo " remove <service|group> Remove service container"
|
||||
echo " logs <service> [lines] View service logs (default 100 lines)"
|
||||
echo " status Show all service status"
|
||||
echo " info Show available service information"
|
||||
echo " clean Remove all goframe containers"
|
||||
echo " pull [service] Pull images"
|
||||
echo ""
|
||||
echo "Services:"
|
||||
echo " Basic: etcd, redis, mysql, mariadb, postgres, mssql,"
|
||||
echo " clickhouse, polaris, oracle, dm, gaussdb, zookeeper"
|
||||
echo " Compose: apollo, nacos, redis-cluster, consul"
|
||||
echo ""
|
||||
echo "Service Groups:"
|
||||
echo " db - All database services"
|
||||
echo " cache - Cache services (redis, etcd)"
|
||||
echo " registry - Registry services (polaris, zookeeper)"
|
||||
echo " all - All basic services"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 start mysql # Start MySQL"
|
||||
echo " $0 start db # Start all databases"
|
||||
echo " $0 start all # Start all basic services"
|
||||
echo " $0 start apollo # Start Apollo (compose)"
|
||||
echo " $0 stop all # Stop all basic services"
|
||||
echo " $0 logs mysql 50 # View last 50 lines of MySQL logs"
|
||||
echo " $0 status # View service status"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Parse service groups
|
||||
parse_services() {
|
||||
local input=$1
|
||||
case $input in
|
||||
db)
|
||||
echo "$GROUP_DB"
|
||||
;;
|
||||
cache)
|
||||
echo "$GROUP_CACHE"
|
||||
;;
|
||||
registry)
|
||||
echo "$GROUP_REGISTRY"
|
||||
;;
|
||||
all)
|
||||
echo "$GROUP_ALL"
|
||||
;;
|
||||
*)
|
||||
echo "$input"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check if it's a compose service
|
||||
is_compose_service() {
|
||||
local service=$1
|
||||
case $service in
|
||||
apollo|nacos|redis-cluster|consul)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Pull images
|
||||
pull_images() {
|
||||
local services=$1
|
||||
|
||||
if [ -z "$services" ]; then
|
||||
services="$GROUP_ALL"
|
||||
fi
|
||||
|
||||
for service in $services; do
|
||||
if [ -n "${SERVICES[$service]}" ]; then
|
||||
print_info "Pulling image: ${SERVICES[$service]}"
|
||||
docker pull "${SERVICES[$service]}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Clean all goframe containers
|
||||
clean_all() {
|
||||
print_info "Removing all $PREFIX containers..."
|
||||
local containers=$(docker ps -a --filter "name=$PREFIX" --format '{{.Names}}')
|
||||
|
||||
if [ -n "$containers" ]; then
|
||||
for container in $containers; do
|
||||
docker rm -f "$container" > /dev/null
|
||||
print_success "Removed: $container"
|
||||
done
|
||||
else
|
||||
print_info "No $PREFIX containers found"
|
||||
fi
|
||||
}
|
||||
|
||||
# Get service status mark
|
||||
get_service_status_mark() {
|
||||
local service=$1
|
||||
local container_name=$(get_container_name "$service")
|
||||
|
||||
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "^${container_name}$"; then
|
||||
echo -e "${GREEN}*${NC}"
|
||||
else
|
||||
echo " "
|
||||
fi
|
||||
}
|
||||
|
||||
# Get compose service status mark
|
||||
get_compose_status_mark() {
|
||||
local service=$1
|
||||
local running=0
|
||||
|
||||
case $service in
|
||||
apollo)
|
||||
running=$(docker ps --filter "name=apollo" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
nacos)
|
||||
running=$(docker ps --filter "name=nacos" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
redis-cluster)
|
||||
running=$(docker ps --filter "name=redis-" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
consul)
|
||||
running=$(docker ps --filter "name=consul" --format '{{.Names}}' 2>/dev/null | wc -l)
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$running" -gt 0 ]; then
|
||||
echo -e "${GREEN}*${NC}"
|
||||
else
|
||||
echo " "
|
||||
fi
|
||||
}
|
||||
|
||||
# Service selection menu
|
||||
select_service_menu() {
|
||||
local action=$1
|
||||
local action_name=$2
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}========== Select Service to ${action_name} ==========${NC}"
|
||||
|
||||
# Show running status for stop/restart/logs operations
|
||||
if [[ "$action" == "stop" || "$action" == "restart" || "$action" == "logs" ]]; then
|
||||
echo -e " (${GREEN}*${NC} indicates running)"
|
||||
fi
|
||||
echo ""
|
||||
echo -e "${YELLOW}Basic Services:${NC}"
|
||||
printf " %b1) etcd %b2) redis %b3) mysql\n" \
|
||||
"$(get_service_status_mark etcd)" "$(get_service_status_mark redis)" "$(get_service_status_mark mysql)"
|
||||
printf " %b4) mariadb %b5) postgres %b6) mssql\n" \
|
||||
"$(get_service_status_mark mariadb)" "$(get_service_status_mark postgres)" "$(get_service_status_mark mssql)"
|
||||
printf " %b7) clickhouse %b8) polaris %b9) oracle\n" \
|
||||
"$(get_service_status_mark clickhouse)" "$(get_service_status_mark polaris)" "$(get_service_status_mark oracle)"
|
||||
printf " %b10) dm %b11) gaussdb %b12) zookeeper\n" \
|
||||
"$(get_service_status_mark dm)" "$(get_service_status_mark gaussdb)" "$(get_service_status_mark zookeeper)"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Compose Services:${NC}"
|
||||
printf " %b13) apollo %b14) nacos %b15) redis-cluster\n" \
|
||||
"$(get_compose_status_mark apollo)" "$(get_compose_status_mark nacos)" "$(get_compose_status_mark redis-cluster)"
|
||||
printf " %b16) consul\n" "$(get_compose_status_mark consul)"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Service Groups:${NC}"
|
||||
echo " 17) db (all databases) 18) cache (cache services)"
|
||||
echo " 19) registry (registry services) 20) all (all basic services)"
|
||||
echo ""
|
||||
echo " 0) Back to main menu"
|
||||
echo ""
|
||||
read -p "Select [0-20]: " svc_choice
|
||||
|
||||
local svc=""
|
||||
case $svc_choice in
|
||||
1) svc="etcd" ;;
|
||||
2) svc="redis" ;;
|
||||
3) svc="mysql" ;;
|
||||
4) svc="mariadb" ;;
|
||||
5) svc="postgres" ;;
|
||||
6) svc="mssql" ;;
|
||||
7) svc="clickhouse" ;;
|
||||
8) svc="polaris" ;;
|
||||
9) svc="oracle" ;;
|
||||
10) svc="dm" ;;
|
||||
11) svc="gaussdb" ;;
|
||||
12) svc="zookeeper" ;;
|
||||
13) svc="apollo" ;;
|
||||
14) svc="nacos" ;;
|
||||
15) svc="redis-cluster" ;;
|
||||
16) svc="consul" ;;
|
||||
17) svc="db" ;;
|
||||
18) svc="cache" ;;
|
||||
19) svc="registry" ;;
|
||||
20) svc="all" ;;
|
||||
0) return ;;
|
||||
*)
|
||||
print_error "Invalid selection"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
case $action in
|
||||
start)
|
||||
if is_compose_service "$svc"; then
|
||||
start_compose_service "$svc"
|
||||
else
|
||||
for s in $(parse_services "$svc"); do
|
||||
start_service "$s"
|
||||
done
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if is_compose_service "$svc"; then
|
||||
stop_compose_service "$svc"
|
||||
else
|
||||
for s in $(parse_services "$svc"); do
|
||||
stop_service "$s"
|
||||
done
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
if is_compose_service "$svc"; then
|
||||
stop_compose_service "$svc"
|
||||
start_compose_service "$svc"
|
||||
else
|
||||
for s in $(parse_services "$svc"); do
|
||||
stop_service "$s"
|
||||
start_service "$s"
|
||||
done
|
||||
fi
|
||||
;;
|
||||
remove)
|
||||
for s in $(parse_services "$svc"); do
|
||||
remove_service "$s"
|
||||
done
|
||||
;;
|
||||
logs)
|
||||
if is_compose_service "$svc"; then
|
||||
print_error "For Compose services, please use 'docker compose logs'"
|
||||
else
|
||||
read -p "Number of lines (default 100): " lines
|
||||
lines=${lines:-100}
|
||||
logs_service "$svc" "$lines"
|
||||
fi
|
||||
;;
|
||||
pull)
|
||||
pull_images "$(parse_services "$svc")"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Interactive menu
|
||||
interactive_menu() {
|
||||
while true; do
|
||||
echo ""
|
||||
echo -e "${CYAN}========== GoFrame Docker Services Manager ==========${NC}"
|
||||
echo ""
|
||||
echo " 1) Start Service"
|
||||
echo " 2) Stop Service"
|
||||
echo " 3) Restart Service"
|
||||
echo " 4) Remove Service"
|
||||
echo " 5) View Logs"
|
||||
echo " 6) View Status"
|
||||
echo " 7) Service Info"
|
||||
echo " 8) Clean All Containers"
|
||||
echo " 9) Pull Images"
|
||||
echo " 0) Exit"
|
||||
echo ""
|
||||
read -p "Select operation [0-9]: " choice
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
select_service_menu "start" "Start"
|
||||
;;
|
||||
2)
|
||||
select_service_menu "stop" "Stop"
|
||||
;;
|
||||
3)
|
||||
select_service_menu "restart" "Restart"
|
||||
;;
|
||||
4)
|
||||
select_service_menu "remove" "Remove"
|
||||
;;
|
||||
5)
|
||||
select_service_menu "logs" "View Logs"
|
||||
;;
|
||||
6)
|
||||
show_status
|
||||
;;
|
||||
7)
|
||||
show_service_info
|
||||
;;
|
||||
8)
|
||||
read -p "Confirm removing all goframe containers? [y/N]: " confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
clean_all
|
||||
fi
|
||||
;;
|
||||
9)
|
||||
select_service_menu "pull" "Pull Images"
|
||||
;;
|
||||
0)
|
||||
echo "Goodbye!"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid selection"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
check_docker
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
interactive_menu
|
||||
exit 0
|
||||
fi
|
||||
|
||||
local command=$1
|
||||
local target=$2
|
||||
local extra=$3
|
||||
|
||||
case $command in
|
||||
start)
|
||||
if [ -z "$target" ]; then
|
||||
print_error "Please specify service name or service group"
|
||||
exit 1
|
||||
fi
|
||||
if is_compose_service "$target"; then
|
||||
start_compose_service "$target"
|
||||
else
|
||||
for service in $(parse_services "$target"); do
|
||||
start_service "$service"
|
||||
done
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if [ -z "$target" ]; then
|
||||
print_error "Please specify service name or service group"
|
||||
exit 1
|
||||
fi
|
||||
if is_compose_service "$target"; then
|
||||
stop_compose_service "$target"
|
||||
else
|
||||
for service in $(parse_services "$target"); do
|
||||
stop_service "$service"
|
||||
done
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
if [ -z "$target" ]; then
|
||||
print_error "Please specify service name or service group"
|
||||
exit 1
|
||||
fi
|
||||
if is_compose_service "$target"; then
|
||||
stop_compose_service "$target"
|
||||
start_compose_service "$target"
|
||||
else
|
||||
for service in $(parse_services "$target"); do
|
||||
stop_service "$service"
|
||||
start_service "$service"
|
||||
done
|
||||
fi
|
||||
;;
|
||||
remove|rm)
|
||||
if [ -z "$target" ]; then
|
||||
print_error "Please specify service name or service group"
|
||||
exit 1
|
||||
fi
|
||||
for service in $(parse_services "$target"); do
|
||||
remove_service "$service"
|
||||
done
|
||||
;;
|
||||
logs)
|
||||
if [ -z "$target" ]; then
|
||||
print_error "Please specify service name"
|
||||
exit 1
|
||||
fi
|
||||
logs_service "$target" "${extra:-100}"
|
||||
;;
|
||||
status|ps)
|
||||
show_status
|
||||
;;
|
||||
info|list)
|
||||
show_service_info
|
||||
;;
|
||||
clean)
|
||||
clean_all
|
||||
;;
|
||||
pull)
|
||||
pull_images "$target"
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown command: $command"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user