This commit is contained in:
hhftechnologies 2024-10-02 14:03:07 +05:30
parent 3281207dd0
commit 45b0fbaadc
12 changed files with 217 additions and 168 deletions

7
.codenvy.dockerfile Normal file
View file

@ -0,0 +1,7 @@
FROM codenvy/ubuntu_jdk8
# Install Ngrok
ADD https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip /ngrok.zip
RUN set -x \
&& sudo unzip -o /ngrok.zip -d /bin \
&& sudo rm -f /ngrok.zip

12
.editorconfig Normal file
View file

@ -0,0 +1,12 @@
# top-most EditorConfig file
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.{sh}]
indent_size = 4

View file

@ -1,32 +1,53 @@
FROM alpine as ngrok
FROM alpine:3.12
RUN apk add --no-cache --virtual .bootstrap-deps ca-certificates && \
wget -O /tmp/ngrok.zip https://git.hhf.technology/hhf/docker-ngrok/src/commit/3a379e0aa43c372c5cbeb3690e110d483ab06a18/ngrok-stable-linux-amd64.zip && \
unzip -o /tmp/ngrok.zip -d / && \
apk del .bootstrap-deps && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/*
FROM busybox:glibc
LABEL org.opencontainers.image.description="Ngrok" \
LABEL org.opencontainers.image.description="Docker-Ngrok" \
org.opencontainers.image.authors="HHF Technology (https://forum.hhf.technology/)" \
org.opencontainers.image.url="https://git.hhf.technology/hhf/docker-ngrok" \
org.opencontainers.image.documentation="https://git.hhf.technology/hhf/docker-ngrok" \
org.opencontainers.image.source="https://git.hhf.technology/hhf/docker-ngrok"
COPY --from=ngrok /ngrok /bin/ngrok
COPY start.sh /
RUN mkdir -p /home/ngrok /home/ngrok/.ngrok2 && \
printf 'web_addr: 0.0.0.0:4551' > /home/ngrok/.ngrok2/ngrok.yml && \
addgroup -g 4551 -S ngrok && \
adduser -u 4551 -S ngrok -G ngrok -h /home/ngrok -s /bin/ash && \
chown -R ngrok:ngrok /home/ngrok && \
chmod +x /start.sh
# https://github.com/sgerrand/alpine-pkg-glibc
ARG GLIBC_VERSION=2.31-r0
USER ngrok:ngrok
RUN set -x \
&& apk add --no-cache -t .deps ca-certificates \
# Install glibc on Alpine (required by docker-compose)
# See also https://github.com/gliderlabs/docker-alpine/issues/11
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \
&& apk add glibc-${GLIBC_VERSION}.apk \
&& rm glibc-${GLIBC_VERSION}.apk \
&& apk del --purge .deps
EXPOSE 4551
RUN set -x \
# Install ngrok (latest official stable from https://ngrok.com/download).
&& apk add --no-cache curl \
&& APKARCH="$(apk --print-arch)" \
&& case "$APKARCH" in \
armhf) NGROKARCH="arm" ;; \
armv7) NGROKARCH="arm" ;; \
armel) NGROKARCH="arm" ;; \
x86) NGROKARCH="386" ;; \
x86_64) NGROKARCH="amd64" ;; \
esac \
&& curl -Lo /ngrok.tgz https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-$NGROKARCH.tgz \
&& tar -xzf /ngrok.tgz \
&& mv /ngrok /bin \
&& chmod 755 /bin/ngrok \
&& rm -f /ngrok.tgz \
# Create non-root user.
&& adduser -h /home/ngrok -D -u 6737 ngrok
ENTRYPOINT ["/start.sh"]
# Add config script.
COPY --chown=ngrok ngrok.yml /home/ngrok/.ngrok2/
COPY entrypoint.sh /
USER ngrok
ENV USER=ngrok
# Basic sanity check.
RUN ngrok --version
EXPOSE 4040
CMD ["/entrypoint.sh"]

35
Dockerfile.armhf Normal file
View file

@ -0,0 +1,35 @@
FROM resin/raspberrypi3-alpine
LABEL org.opencontainers.image.description="Docker-Ngrok" \
org.opencontainers.image.authors="HHF Technology (https://forum.hhf.technology/)" \
org.opencontainers.image.url="https://git.hhf.technology/hhf/docker-ngrok" \
org.opencontainers.image.documentation="https://git.hhf.technology/hhf/docker-ngrok" \
org.opencontainers.image.source="https://git.hhf.technology/hhf/docker-ngrok"
RUN [ "cross-build-start" ]
RUN set -x \
# Install ngrok (latest official stable from https://ngrok.com/download).
&& apk add --no-cache curl \
&& curl -Lo /ngrok.zip https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip \
&& unzip -o /ngrok.zip -d /bin \
&& rm -f /ngrok.zip \
# Create non-root user.
&& adduser -h /home/ngrok -D -u 6737 ngrok
# Add config script.
COPY --chown=ngrok ngrok.yml /home/ngrok/.ngrok2/
COPY entrypoint.sh /
# Basic sanity check.
RUN su ngrok -c 'ngrok --version'
RUN [ "cross-build-end" ]
USER ngrok
ENV USER=ngrok
EXPOSE 4040
CMD ["/entrypoint.sh"]

View file

@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)
Copyright (c) 2019 Dmitry Shkoliar
Copyright (c) 2015 Werner Beroux
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,90 +0,0 @@
# Docker Ngrok
A Docker image for [ngrok](https://ngrok.com) service to expose a local docker environment or any other local server to the public internet over secure tunnels. The image is built using official [busybox:glibc](https://hub.docker.com/_/busybox) docker image, so no third party libraries are used, only official busybox and ngrok binary.
## Usage
### Command-line
**Example**
The example below assumes that you have running web server docker container named `dev_web_1` with exposed port `80`.
```bash
docker run --rm -it --link dev_web_1 hhftechnologies/ngrok http dev_web_1:80
```
With command line usage, ngrok session is active until it won't be terminated by `Ctrl+C` combination.
#### Command details
**Using ngrok parameters**
```bash
docker run --rm -it --link <web-container-name> [--net <default-netowrk-name>] hhftechnologies/ngrok <ngrok-parameters> <web-container-name>:<port>
```
For information about ngrok parameters, please refer to [ngrok documentation](https://ngrok.com/docs).
**Passing parameters to ngrok via env variables**
```bash
docker run --rm -it --link <web-container-name> [--net <default-netowrk-name>] --env DOMAIN=<web-container-name> --env PORT=<port> hhftechnologies/ngrok
```
Available env variables can be found below, at [environment variables](#environment-variables) section.
#### Troubleshooting
_If you are getting an error like_
```bash
docker: Error response from daemon: Cannot link to /dev_web_1, as it does not belong to the default network.
```
_You need to specify default docker network, for example_
```bash
docker run --rm -it --link dev_web_1 --net dev_default hhftechnologies/ngrok http dev_web_1:80
```
### As part of docker-compose.yml file
```yaml
ngrok:
image: hhftechnologies/ngrok:latest
ports:
- 4551:4551
links:
- web
environment:
- DOMAIN=web
- PORT=80
```
Where `web` in example above is a web server service name of this docker-compose.yml file.
If ngrok container is created as part of docker-compose.yml file, ngrok session is active while container is running. To restart or stop session, you will need to restart or stop container respectively.
Ngrok web interface available at `http://localhost:4551`.
## Environment variables
List of available environment variables to configure ngrok in command line usage or as part of docker-compose.yml file.
| Name | Values | Default | Information |
| :---------- | :------------------------- | :-------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PROTOCOL | http, tls, tcp | http | Ngrok tunneling protocol. |
| DOMAIN | \* | localhost | Hostname or docker container, service name which is referred to by ngrok. |
| PORT | \* | 80 | Port which is referred to by ngrok. |
| REGION | us, eu, ap, au, sa, jp, in | us | Region where the ngrok client will connect to host its tunnels. |
| HOST_HEADER | \* | | Optional, rewrite incoming HTTP requests with a modified Host header. e.g. `HOST_HEADER=localdev.test` |
| BIND_TLS | true, false | | Optional, forward only HTTP or HTTPS traffic, but not both. By default, when ngrok runs an HTTP tunnel, it opens endpoints for both HTTP and HTTPS traffic. |
| SUBDOMAIN | \* | | Optional, specifies the subdomain to use with ngrok, if unspecified ngrok with generate a unique subdomain on each start. |
| AUTH_TOKEN | \* | | Optional, token used to authorise your subdomain with ngrok. |
| DEBUG | true | | Optional, write logs to stdout. |
| PARAMS | \* | | Pass all ngrok parameters by one string. When specified, any other env variables are skipped (Except AUTH_TOKEN).|
For more information about ngrok parameters, please refer to [ngrok documentation](https://ngrok.com/docs).
## License
[MIT](../../blob/master/LICENSE)

3
docker-compose.test.yml Normal file
View file

@ -0,0 +1,3 @@
sut:
build: .
command: sh -c '(ngrok http 8080 &) && sleep 5 && curl --connect-timeout 5 --silent --show-error --fail http://localhost:4040'

12
docker-compose.yml Normal file
View file

@ -0,0 +1,12 @@
version: '3'
services:
latest:
image: hhftechnologies/docker-ngrok:latest
build:
context: .
# armhf:
# image: hhftechnologies/docker-ngrok:armhf
# build:
# context: .
# dockerfile: Dockerfile.armhf

98
entrypoint.sh Normal file
View file

@ -0,0 +1,98 @@
#!/bin/sh -e
if [ -n "$@" ]; then
exec "$@"
fi
# Legacy compatible:
if [ -z "$NGROK_PORT" ]; then
if [ -n "$HTTPS_PORT" ]; then
NGROK_PORT="$HTTPS_PORT"
elif [ -n "$HTTPS_PORT" ]; then
NGROK_PORT="$HTTP_PORT"
elif [ -n "$APP_PORT" ]; then
NGROK_PORT="$APP_PORT"
fi
fi
ARGS="ngrok"
# Set the protocol.
if [ "$NGROK_PROTOCOL" = "TCP" ]; then
ARGS="$ARGS tcp"
elif [ "$NGROK_PROTOCOL" = "TLS" ]; then
ARGS="$ARGS tls"
NGROK_PORT="${NGROK_PORT:-443}"
else
ARGS="$ARGS http"
NGROK_PORT="${NGROK_PORT:-80}"
fi
# Set the TLS binding flag
if [ -n "$NGROK_BINDTLS" ]; then
ARGS="$ARGS -bind-tls=$NGROK_BINDTLS "
fi
# Set the authorization token.
if [ -n "$NGROK_AUTH" ]; then
echo -e "\nauthtoken: $NGROK_AUTH" >> $HOME/.ngrok2/ngrok.yml
fi
# Set the subdomain or hostname, depending on which is set
if [ -n "$NGROK_HOSTNAME" ] && [ -n "$NGROK_AUTH" ]; then
ARGS="$ARGS -hostname=$NGROK_HOSTNAME "
elif [ -n "$NGROK_SUBDOMAIN" ] && [ -n "$NGROK_AUTH" ]; then
ARGS="$ARGS -subdomain=$NGROK_SUBDOMAIN "
elif [ -n "$NGROK_HOSTNAME" ] || [ -n "$NGROK_SUBDOMAIN" ]; then
if [ -z "$NGROK_AUTH" ]; then
echo "You must specify an authentication token after registering at https://ngrok.com to use custom domains."
exit 1
fi
fi
# Set the remote-addr if specified
if [ -n "$NGROK_REMOTE_ADDR" ]; then
if [ -z "$NGROK_AUTH" ]; then
echo "You must specify an authentication token after registering at https://ngrok.com to use reserved ip addresses."
exit 1
fi
ARGS="$ARGS -remote-addr=$NGROK_REMOTE_ADDR "
fi
# Set a custom region
if [ -n "$NGROK_REGION" ]; then
ARGS="$ARGS -region=$NGROK_REGION "
fi
if [ -n "$NGROK_HEADER" ]; then
ARGS="$ARGS -host-header=$NGROK_HEADER "
fi
if [ -n "$NGROK_USERNAME" ] && [ -n "$NGROK_PASSWORD" ] && [ -n "$NGROK_AUTH" ]; then
ARGS="$ARGS -auth=$NGROK_USERNAME:$NGROK_PASSWORD "
elif [ -n "$NGROK_USERNAME" ] || [ -n "$NGROK_PASSWORD" ]; then
if [ -z "$NGROK_AUTH" ]; then
echo "You must specify a username, password, and Ngrok authentication token to use the custom HTTP authentication."
echo "Sign up for an authentication token at https://ngrok.com"
exit 1
fi
fi
if [ -n "$NGROK_DEBUG" ]; then
ARGS="$ARGS -log stdout"
fi
# Set the port.
if [ -z "$NGROK_PORT" ]; then
echo "You must specify a NGROK_PORT to expose."
exit 1
fi
if [ -n "$NGROK_LOOK_DOMAIN" ]; then
ARGS="$ARGS `echo $NGROK_LOOK_DOMAIN:$NGROK_PORT | sed 's|^tcp://||'`"
else
ARGS="$ARGS `echo $NGROK_PORT | sed 's|^tcp://||'`"
fi
exec $ARGS

Binary file not shown.

3
ngrok.yml Normal file
View file

@ -0,0 +1,3 @@
web_addr: 0.0.0.0:4040
version: "2"
region: us

View file

@ -1,53 +0,0 @@
#!/bin/sh -e
CMD="ngrok"
$CMD authtoken ${AUTH_TOKEN:-''} > /dev/null
PARAMS=${PARAMS:-$(echo $@)}
if [[ -n "$PARAMS" ]]; then
if [[ "$PARAMS" == "$CMD "* ]]; then
CMD="$PARAMS"
else
CMD="$CMD $PARAMS"
fi
else
PROTOCOL=${PROTOCOL:-http}
PORT=${PORT:-80}
CMD="$CMD $PROTOCOL"
if [[ -n "$REGION" ]]; then
CMD="$CMD -region=$REGION"
fi
if [[ -n "$HOST_HEADER" ]]; then
CMD="$CMD -host-header=$HOST_HEADER"
fi
if [[ -n "$BIND_TLS" ]]; then
CMD="$CMD -bind-tls=$BIND_TLS"
fi
if [[ -n "$SUBDOMAIN" ]]; then
CMD="$CMD -subdomain=$SUBDOMAIN"
fi
if [[ -n "$BASICAUTH" ]]; then
CMD="$CMD --auth=$BASICAUTH"
fi
if [[ -n "$DEBUG" ]]; then
CMD="$CMD -log stdout"
fi
if [[ -n "$DOMAIN" ]]; then
CMD="$CMD $DOMAIN:$PORT"
else
CMD="$CMD $PORT"
fi
fi
set -x
exec $CMD