Skip to content

Commit e03a27e

Browse files
committed
added ngrok support
1 parent 9905eba commit e03a27e

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

bin/docker

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ function dockerbuild {
7272
$docker_compose_bin build $args
7373
}
7474

75+
function share {
76+
if [[ $(dockerps web) != 1 ]]; then
77+
echo "Il container web non è attivo. Avviare prima con bin/docker start"
78+
exit 1
79+
fi
80+
81+
if [[ -f "$root_dir/docker/.env" ]]; then
82+
export $(grep -v '^#' "$root_dir/docker/.env" | xargs)
83+
fi
84+
85+
if [[ -z "$NGROK_AUTHTOKEN" ]]; then
86+
echo "NGROK_AUTHTOKEN is missing. Update .env file with your ngrok authtoken."
87+
exit 1
88+
fi
89+
90+
echo "Starting ngrok container..."
91+
$docker_compose_bin --profile share up -d ngrok
92+
93+
sleep 2
94+
NGROK_URL=$(dockerexec ngrok curl --silent http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')
95+
echo "ngrok public URL: $NGROK_URL"
96+
echo "Monitor ngrok on http://localhost:4040"
97+
}
98+
99+
function unshare {
100+
echo "Stopping ngrok..."
101+
dockerstop ngrok
102+
}
103+
75104
if ! [ -e $docker_bin ]; then
76105
echo "This script should be run from the root dir"
77106
exit
@@ -184,6 +213,12 @@ case "$1" in
184213
echo "container php-fpm is down"
185214
fi
186215
;;
216+
share)
217+
share
218+
;;
219+
unshare)
220+
unshare
221+
;;
187222
launch|l)
188223
if [[ $(dockerps php-fpm) = 1 ]]; then
189224
shift

docker/.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ MYSQL_DATABASE=sitebase
66
MYSQL_USER=myuser
77
MYSQL_PASSWORD=secret
88
MYSQL_ROOT_PASSWORD=docker
9+
NGROK_AUTHTOKEN=

docker/docker-compose.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ services:
9292
restart: unless-stopped
9393
ports:
9494
- 9001:9001 # supervisor
95+
ngrok:
96+
build:
97+
context: ./ngrok
98+
profiles: ["share"]
99+
depends_on:
100+
- web
101+
env_file:
102+
- ./.env
103+
networks:
104+
sitebasenet:
105+
ipv4_address: ${IPV4_CLASS}.0.9
106+
stdin_open: true
107+
tty: true
108+
# restart: unless-stopped
95109
mailhog:
96110
image: mailhog/mailhog
97111
logging:
@@ -121,4 +135,4 @@ services:
121135
ipv4_address: ${IPV4_CLASS}.0.7
122136
env_file:
123137
- ./.env
124-
restart: unless-stopped
138+
restart: unless-stopped

docker/ngrok/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# --- Dockerfile ngrok ---
2+
FROM alpine:latest
3+
4+
# Install utilities
5+
RUN apk add --no-cache curl bash jq unzip
6+
7+
ARG NGROK_VERSION="3.7.0"
8+
RUN curl -sL https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v${NGROK_VERSION}-linux-amd64.tgz -o /tmp/ngrok.tgz \
9+
&& tar -xzf /tmp/ngrok.tgz -C /usr/local/bin \
10+
&& chmod +x /usr/local/bin/ngrok \
11+
&& rm /tmp/ngrok.tgz
12+
13+
EXPOSE 4040
14+
15+
ENTRYPOINT ["sh", "-c", "ngrok config add-authtoken $NGROK_AUTHTOKEN && ngrok http web:80 --log=stdout"]
16+

docker/ngrok/ngrok.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# docker/ngrok/ngrok.yml
2+
authtoken: ${NGROK_AUTHTOKEN}
3+
tunnels:
4+
web:
5+
proto: http
6+
addr: web:80

0 commit comments

Comments
 (0)