Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
deploy: complete deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ozline committed Aug 27, 2023
1 parent 7c00e85 commit 37ec61c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ cmd/api/tiktok_api
dumped_hertz_remote_config.json

# config
config/config.yaml
config/config.yaml

# Deploy
deploy/config
28 changes: 28 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Deploy

All files in this directory are only used for CI/CD purposes. But you can also manually use these scripts or configurations in the right place.

# Introduction

## docker-entrypoint.sh

only use for docker build, **DO NOT EDIT OR MOVE.**

## restart-service.sh

this shell file is used for start/restart the specific service (**list: api user follow interaction video chat**)

```bash
sh restart-service.sh api # or others
```

- the container use **host** network
- you need to **move config.yaml** to the same dir as this file
- **Before starting the service**, you need to configure the corresponding environment (refer to the configuration in config.yaml).
- The script will **automatically** detect and delete the containers, no manual deletion is required.

## Others

- restart-service-all.sh: no further explanation is needed.
- common.sh: set any constants
- remove-all-containers: common scripts
5 changes: 5 additions & 0 deletions deploy/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

IMAGE_NAME="registry.cn-hangzhou.aliyuncs.com/ozline/tiktok:v1"

DIR=$(cd $(dirname $0); pwd)
18 changes: 18 additions & 0 deletions deploy/remove-all-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
source common.sh

containers_to_stop=$(docker ps -aq --filter "ancestor=$IMAGE_NAME")

for container_id in $containers_to_stop; do
container_status=$(docker inspect -f '{{.State.Status}}' "$container_id")
if [ "$container_status" == "running" ]; then
echo "Stopping container $container_id..."
docker stop "$container_id"
elif [ "$container_status" == "paused" ]; then
echo "Unpausing and then stopping container $container_id..."
docker unpause "$container_id"
docker stop "$container_id"
fi
echo "Remove container $container_id..."
docker rm "$container_id"
done
15 changes: 15 additions & 0 deletions deploy/restart-service-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
source remove-all-containers.sh

echo "Pulling the latest image..."
docker pull "$IMAGE_NAME"

echo "Launch all services"
for service in api user chat follow interaction video; do
echo "Starting container for $service..."
docker run -d --name "tiktok-$service" \
-e service=$service \
--net=host \
-v $DIR/config:/app/config \
"$IMAGE_NAME"
done
11 changes: 11 additions & 0 deletions deploy/restart-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
source remove-all-containers.sh

SERVICE_TO_START=${1:-api} # get specific service

echo "Starting container for $SERVICE_TO_START..."
docker run -d --name "tiktok-$SERVICE_TO_START" \
-e service=$SERVICE_TO_START \
--net=host \
-v $DIR/config:/app/config \
"$IMAGE_NAME"

0 comments on commit 37ec61c

Please sign in to comment.