All checks were successful
build-deploy / build-deploy (push) Successful in 1m59s
55 lines
2.0 KiB
YAML
55 lines
2.0 KiB
YAML
name: build-deploy
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
build-deploy:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Build & push muyu services
|
||
run: |
|
||
set -eo pipefail
|
||
REG=localhost:3000/kaezhou
|
||
BR=docker.io/library # muyu Dockerfile: FROM ${BASE_REGISTRY}/img
|
||
TAG=dev-$(echo "${{ github.sha }}" | cut -c1-8)
|
||
|
||
# host 模式无 Node,用 git clone 代替 actions/checkout
|
||
workdir=$(mktemp -d)
|
||
git clone "http://kaezhou:${{ secrets.REGISTRY_TOKEN }}@localhost:3000/kaezhou/muyu-apiserver.git" "$workdir"
|
||
cd "$workdir"
|
||
git checkout "${{ github.sha }}"
|
||
|
||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login localhost:3000 -u kaezhou --password-stdin
|
||
|
||
for pair in \
|
||
"muyu-gateway:deploy/Dockerfile.gateway" \
|
||
"muyu-system-rpc:deploy/Dockerfile.system" \
|
||
"muyu-inventory-rpc:deploy/Dockerfile.inventory" \
|
||
"muyu-purchase-rpc:deploy/Dockerfile.purchase" \
|
||
"muyu-production-rpc:deploy/Dockerfile.production"; do
|
||
name="${pair%%:*}"; df="${pair##*:}"
|
||
echo "::group::build $name ($df)"
|
||
docker build --build-arg BASE_REGISTRY="$BR" -f "$df" \
|
||
-t "$REG/$name:$TAG" -t "$REG/$name:latest" .
|
||
docker push "$REG/$name:$TAG"
|
||
docker push "$REG/$name:latest"
|
||
echo "::endgroup::"
|
||
done
|
||
|
||
rm -rf "$workdir"
|
||
echo "done: pushed 5 muyu images at tag $TAG + latest"
|
||
|
||
- name: Deploy to dev-chiba
|
||
run: |
|
||
set -eo pipefail
|
||
app="$HOME/apps/muyu"
|
||
[ -d "$app" ] || { echo "!! $app 未部署,跳过(首次需手动 compose up)"; exit 0; }
|
||
cd "$app"
|
||
svcs="system-rpc inventory-rpc purchase-rpc production-rpc gateway"
|
||
docker compose pull $svcs
|
||
docker compose up -d $svcs
|
||
docker compose ps --format "table {{.Name}}\t{{.Status}}"
|
||
echo "deployed: $svcs"
|