Skip to content

Commit

Permalink
feat: support create container without docker-compose (#915)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <majinjing3@gmail.com>
  • Loading branch information
jim3ma committed Dec 10, 2021
1 parent f9c2a82 commit 5b502aa
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bin/
# Dependency directories (remove the comment below to include it)
vendor/
.idea
.vscode
.cache
*.DS_Store
target/
Expand Down
24 changes: 22 additions & 2 deletions deploy/docker-compose/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
# Deploying Dragonfly with Docker Compose
# Deploying Dragonfly with Container Directly

> Currently, docker compose deploying is tested just in single host, no HA support.
## Deploy
## Deploy with Docker Compose

The `run.sh` script will generate config and deploy all components with `docker-compose`.

Just run:

```shell
export IP=<host ip>
./run.sh
```

## Deploy without Docker Compose

Just run:

```shell
export IP=<host ip>
./run.sh container
```

## Deploy with Other Container Runtime

Just run:

```shell
export IP=<host ip>
export RUNTIME=pouch
./run.sh container
```
75 changes: 63 additions & 12 deletions deploy/docker-compose/run.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,71 @@
#!/bin/sh

set -xe
set -e

mkdir -p config
REPO=${REPO:-d7yio}
TAG=${TAG:-latest}

cat template/cdn.template.json > config/cdn.json
cat template/cdn.template.yaml > config/cdn.yaml
cat template/dfget.template.yaml > config/dfget.yaml
DIR=$(cd "$(dirname "$0")" && pwd)
cd $DIR

ip=$(hostname -i)
hostname=$(hostname)
prepare(){
mkdir -p config

sed -i "s,__IP__,$ip," config/cdn.json
sed -i "s,__IP__,$ip," config/dfget.yaml
sed -i "s,__IP__,$ip," config/cdn.yaml
cat template/cdn.template.json > config/cdn.json
cat template/cdn.template.yaml > config/cdn.yaml
cat template/dfget.template.yaml > config/dfget.yaml

sed -i "s,__HOSTNAME__,$hostname," config/cdn.json
ip=${IP:-$(hostname -i)}
hostname=$(hostname)

docker-compose up -d
sed -i "s,__IP__,$ip," config/cdn.json
sed -i "s,__IP__,$ip," config/dfget.yaml
sed -i "s,__IP__,$ip," config/cdn.yaml

sed -i "s,__HOSTNAME__,$hostname," config/cdn.json
}

run_container(){
RUNTIME=${RUNTIME:-docker}
echo use container runtime: ${RUNTIME}

echo try to clean old containers
${RUNTIME} rm -f dragonfly-cdn dragonfly-scheduler dragonfly-dfdaemon

printf "create dragonfly-cdn "
${RUNTIME} run -d --name dragonfly-cdn --net=host \
-v /tmp/log/dragonfly:/var/log/dragonfly \
-v ${DIR}/config/cdn.yaml:/etc/dragonfly/cdn.yaml \
-v ${DIR}/config/nginx.conf:/etc/nginx/nginx.conf \
${REPO}/cdn:${TAG}

printf "create dragonfly-scheduler "
${RUNTIME} run -d --name dragonfly-scheduler --net=host \
-v /tmp/log/dragonfly:/var/log/dragonfly \
-v ${DIR}/config/scheduler.yaml:/etc/dragonfly/scheduler.yaml \
-v ${DIR}/config/cdn.json:/opt/dragonfly/scheduler-cdn/cdn.json \
${REPO}/scheduler:${TAG}

printf "create dragonfly-dfdaemon "
${RUNTIME} run -d --name dragonfly-dfdaemon --net=host \
-v /tmp/log/dragonfly:/var/log/dragonfly \
-v ${DIR}/config/dfget.yaml:/etc/dragonfly/dfget.yaml \
${REPO}/dfdaemon:${TAG}
}

prepare

case "$1" in
container)
run_container
;;

*)
if [ -z "$1" ]; then
docker-compose up -d
exit 0
fi
echo "unknown argument: $1"
exit 1
;;
esac

0 comments on commit 5b502aa

Please sign in to comment.