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

deploy: complete deploy scripts #93

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/push-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
uses: docker/login-action@v1
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.ACCESSKEYID }}
password: ${{ secrets.ACCESSKEYSECRET }}
username: ${{ secrets.ALIYUNDOCKERLOGINUSERNAME }}
password: ${{ secrets.ALIYUNDOCKERLOGINPASSWORD }}

- name: Build and push
id: docker_build
Expand Down
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ ENV service api
WORKDIR /app
COPY --from=builder /app/output /app/output
COPY --from=builder /app/config /app/config
COPY --from=builder /app/docker /app
COPY --from=builder /app/deploy /app

CMD ["sh", "./entrypoint.sh"]
CMD ["sh", "./docker-entrypoint.sh"]
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)
File renamed without changes.
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"
Loading