Skip to content

Commit

Permalink
Add bash and entrypoint script, update network name
Browse files Browse the repository at this point in the history
  • Loading branch information
haonxsenprints committed Jan 24, 2024
1 parent e1db9b9 commit f8e3e94
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FROM docker

# RUN apt install -y docker-compose-plugin
RUN apk add --no-cache docker-compose
RUN apk add --no-cache bash

WORKDIR /app
RUN mkdir -p /app
Expand All @@ -16,6 +17,7 @@ COPY get-tunnel.sh /app/get-tunnel.sh
COPY get-exist-tunnel.sh /app/get-exist-tunnel.sh
COPY start-tunnel.sh /app/start-tunnel.sh
COPY docker-compose.yml /app/docker-compose.yml
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/*.sh

ENTRYPOINT [ "/bin/sh", "/app/get-tunnel.sh" ]
ENTRYPOINT [ "/bin/bash", "/app/entrypoint.sh" ]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ services:
- network1
networks:
network1:
name: ${NETWORK:-tryc}
name: ${NETWORK:-tryc}_default
external: true
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

set -xeo pipefail
bash /app/get-tunnel.sh "$1" "$2" "$3" 2>/tmp/get-tunnel.log
11 changes: 7 additions & 4 deletions get-tunnel.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
set -e -o pipefail
set -xeo pipefail
args=("$@")
echo "args: ${args[@]}" >&2
project_name="$1"
docker_compose_file=$2
NETWORK="$3"
Expand All @@ -12,11 +14,12 @@ fi
if [ -z "$NETWORK" ]; then
NETWORK="tryc"
fi
echo "Network: $NETWORK" >&2
export NETWORK
export CONTAINER_NAME="$project_name-$NETWORK-"$(echo "$project_name-$NETWORK-$ADDRESS" | md5sum | tr -d '=' | tr -d '\n' | tr -d '\r' | cut -c1-5)
docker network inspect $NETWORK >/tmp/tunnel.log || docker network create $NETWORK >/tmp/tunnel.log
docker network inspect $NETWORK >&2 || docker network create $NETWORK >&2
while true; do
sh start-tunnel.sh "$docker_compose_file" "$project_name-$NETWORK" 2>/tmp/tunnel.log
sh get-exist-tunnel.sh "$docker_compose_file" "$project_name-$NETWORK" 2>/tmp/tunnel.log && break || true
sh start-tunnel.sh "$docker_compose_file" "$NETWORK" 2>&2
sh get-exist-tunnel.sh "$docker_compose_file" "$NETWORK" 2>&2 && break || true
sleep 6
done

0 comments on commit f8e3e94

Please sign in to comment.