Skip to content

Commit

Permalink
Merge pull request #1 from devilbox/release-0.1
Browse files Browse the repository at this point in the history
Initial Release
  • Loading branch information
cytopia authored Mar 5, 2019
2 parents 3952c43 + 7fae27a commit 6d51ddf
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 1 deletion.
86 changes: 86 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Note:
# To effectively apply the changes you will have
# to re-index the git index (if there are already
# commited files)
#
# $ git rm -r --cached .
# $ git add .
# $ git commit -m ".gitignore index rebuild"
#


######################################
# CUSTOM
######################################


######################################
# GENERIC
######################################

###### std ######
.lock
*.log

###### patches/diffs ######
*.patch
*.diff
*.orig
*.rej


######################################
# Operating Systems
######################################

###### OSX ######
._*
.DS*
.Spotlight-V100
.Trashes

###### Windows ######
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.lnk
*.shortcut

######################################
# Editors
######################################

###### Sublime ######
*.sublime-workspace
*.sublime-project

###### Eclipse ######
.classpath
.buildpath
.project
.settings/

###### Netbeans ######
/nbproject/

###### Intellij IDE ######
.idea/
.idea_modules/

###### vim ######
*.swp
*.swo
*.swn
*.swm
*~

###### TextMate ######
.tm_properties
*.tmproj

###### BBEdit ######
*.bbprojectd
*.bbproject

.vagrant
70 changes: 70 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
###
### Enable sudo (required for docker service)
###
sudo: required


###
### Language
###
language: python


###
### Add services
###
services:
- docker


###
### Build Matrix definition
###
env:
global:
# travis encrypt DOCKER_USERNAME=user
# travis encrypt DOCKER_PASSWORD=pass
# Must be regenerated when repository name/owner changes
# DOCKER_USERNAME
- secure: "iQ9JT1Nz7tgTlaG4iQG8PrI96Asge/rLpBaIlIRBRgKE9OSjfPDwdUQEQTOm0XstdompqUWtTdx2ffmcF7B5eEoYCBZR+I+UDmlRxPdCygo/um3SQKHXPYJs2Jb6XfQKgsNnp8PTrbvg95Ol8bjxBEM1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TcyJ2t4mt/OuXFbPFDoB3S3H8M85/8afZJHVG9Qlzb31gvyBYsHHkVYDFhyybaB4XGHC6cCBLS0YnTX6tUMt7RVoTEeXiliXOZQtgCc4nrGFx5cdbXLzPJsnGKdQPsQvb+DZfLilUihu0X7ArtpEr+KY="


###
### Global for all stages
###
install:
# Get newer docker version
- max=100; i=0; while [ $i -lt $max ]; do if sudo apt-get update; then break; else i=$((i+1)); fi done
- max=100; i=0; while [ $i -lt $max ]; do if sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce; then break; else i=$((i+1)); fi done
- docker version


###
### Build and test
###
before_script:
- make build
- make test


###
### Push to Dockerhub
###
script:
# Push to docker hub on success
- if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then
make login USER="${DOCKER_USERNAME}" PASS="${DOCKER_PASSWORD}";
if [ -n "${TRAVIS_TAG}" ]; then
make push TAG="${TRAVIS_TAG}";
elif [ "${TRAVIS_BRANCH}" == "master" ]; then
make push;
elif [[ ${TRAVIS_BRANCH} =~ ^(release-[.0-9]+)$ ]]; then
make push TAG="${TRAVIS_BRANCH}";
else
echo "Skipping branch ${TRAVIS_BRANCH}";
fi
else
echo "Skipping push on PR";
fi
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM debian:stretch-slim
MAINTAINER "cytopia" <[email protected]>

RUN set -x \
&& DEBIAN_FRONTEND=noninteractive apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -qq -y --no-install-recommends --no-install-suggests \
curl \
ca-certificates \
unzip \
&& DEBIAN_FRONTEND=noninteractive apt-get purge -qq -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false apt-utils \
&& rm -rf /var/lib/apt/lists/* \
\
&& URL="$( curl -sS https://ngrok.com/download | grep -Eo "href=\".+ngrok-stable-linux-amd64\.zip\"" | awk -F'\"' '{print $2}' )" \
&& curl -sS -o /tmp/ngrok.zip ${URL} \
&& unzip /tmp/ngrok.zip \
&& rm /tmp/ngrok.zip \
&& mv ngrok /usr/local/bin \
&& ngrok version | grep -E '^ngrok.+[.0-9]+$' \
\
&& DEBIAN_FRONTEND=noninteractive apt-get purge -qq -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
curl \
ca-certificates \
unzip \
&& rm -rf /var/lib/apt/lists/*

RUN set -x \
&& useradd -m -U -u 6737 -s /bin/bash ngrok \
&& mkdir /home/ngrok/.ngrok2 \
&& chown ngrok:ngrok /home/ngrok/.ngrok2

COPY data/docker-entrypoint.sh /docker-entrypoint.sh
COPY data/ngrok.yml /home/ngrok/.ngrok2/ngrok.yml

RUN set -x \
&& chown ngrok:ngrok /home/ngrok/.ngrok2/ngrok.yml

USER ngrok
ENV user=ngrok

CMD ["/docker-entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 cytopia <https://github.com/cytopia>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
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.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
DIR = .
FILE = Dockerfile
IMAGE = devilbox/ngrok
TAG = latest

.PHONY: build rebuild test tag pull login push enter

build:
docker build -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

rebuild: pull
docker build --no-cache -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

test:
./tests/test.sh $(IMAGE)

tag:
docker tag $(IMAGE) $(IMAGE):$(TAG)

pull:
docker pull $(shell grep FROM Dockerfile | sed 's/^FROM//g';)

login:
yes | docker login --username $(USER) --password $(PASS)

push:
@$(MAKE) tag TAG=$(TAG)
docker push $(IMAGE):$(TAG)

enter:
docker run --rm --name $(subst /,-,$(IMAGE)) -it --entrypoint=bash $(ARG) $(IMAGE)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ngrok

[![Build Status](https://travis-ci.org/devilbox/docker-ngrok.svg?branch=master)](https://travis-ci.org/devilbox/docker-ngrok)
[![Build Status](https://travis-ci.com/devilbox/docker-ngrok.svg?branch=master)](https://travis-ci.com/devilbox/docker-ngrok)
[![Tag](https://img.shields.io/github/tag/devilbox/docker-ngrok.svg)](https://github.com/devilbox/docker-ngrok/releases)
[![Gitter](https://badges.gitter.im/devilbox/Lobby.svg)](https://gitter.im/devilbox/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Discourse](https://img.shields.io/discourse/https/devilbox.discourse.group/status.svg?colorB=%234CB697)](https://devilbox.discourse.group)
Expand Down
87 changes: 87 additions & 0 deletions data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

CONFIG_FILE="/home/ngrok/.ngrok2/ngrok.yml"


# -------------------------------------------------------------------------------------------------
# REQUIRED ENV VARIABLES
# -------------------------------------------------------------------------------------------------

if ! env | grep -q '^HTTP_TUNNELS='; then
>&2 echo "[ERROR] HTTP_TUNNELS is not defined, but required to create a tunnel"
exit 1
fi


# -------------------------------------------------------------------------------------------------
# SPECIFY AUTH TOKEN
# -------------------------------------------------------------------------------------------------

if ! env | grep -q '^AUTHTOKEN='; then
>&2 echo "[WARN] No AUTHTOKEN specified, limited functionality only"
else
AUTHTOKEN="$( env env | grep '^AUTHTOKEN=' | awk -F'=' '{print $2}' | xargs )"
AUTHTOKEN="${AUTHTOKEN##*( )}" # Trim leading whitespaces
AUTHTOKEN="${AUTHTOKEN%%*( )}" # Trim trailing whitespaces

if [ -z "${AUTHTOKEN}" ]; then
>&2 echo "[WARN] AUTHTOKEN specified, but empty, limited functionality only"
else
echo "[INFO] Using authtoken as specified in AUTHTOKEN"
echo "authtoken: ${AUTHTOKEN}" >> "${CONFIG_FILE}"
fi
fi


# -------------------------------------------------------------------------------------------------
# SPECIFY HTTP TUNNELS
# -------------------------------------------------------------------------------------------------

HTTP_TUNNELS="$( env | grep '^HTTP_TUNNELS=' | awk -F'=' '{print $2}' )"
HTTP_TUNNELS="$( echo "${HTTP_TUNNELS}" | xargs )" # Trim lwhitespaces
HTTP_TUNNELS="${HTTP_TUNNELS##*( )}" # Trim leading whitespaces
HTTP_TUNNELS="${HTTP_TUNNELS%%*( )}" # Trim trailing whitespaces

if [ -z "${HTTP_TUNNELS}" ]; then
>&2 echo "[ERROR] HTTP_TUNNELS is empty."
>&2 echo "[ERROR] Expected: '<domain>:<backend_addr>:<backend_port>[,<domain>:<backend_addr>:<backend_port>]'";
exit 1
fi

i=0
IFS=','
echo "tunnels:" >> "${CONFIG_FILE}"
for tunnel in ${HTTP_TUNNELS}; do
i=$((i+1))
# Ensure each tunnel line has the correct format: <string>:<string>:<string>
if [ "$( echo "${tunnel}" | sed 's/:/:\n/g' | grep -c ':' )" -ne "2" ]; then
>&2 echo "[ERROR] Wrong format in tunnel line: '${tunnel}'"
>&2 echo "[ERROR] Should be: <domain>:<backend_addr>:<backend_port>"
exit 1
fi
domain_name="$( echo "${tunnel}" | awk -F':' '{print $1}' )"
backend_addr="$( echo "${tunnel}" | awk -F':' '{print $2}' )"
backend_port="$( echo "${tunnel}" | awk -F':' '{print $3}' )"

# Append to ngrok config
{
echo " tunnel_${i}:"
echo " addr: ${backend_addr}:${backend_port}"
echo " host_header: \"${domain_name}\""
echo " proto: http"

} >> "${CONFIG_FILE}"

done

cat ${CONFIG_FILE}

# -------------------------------------------------------------------------------------------------
# START NGROK
# -------------------------------------------------------------------------------------------------

exec ngrok start --all
16 changes: 16 additions & 0 deletions data/ngrok.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#authtoken: 3FqC8NZYFm3FCTnq31YP_4PVTJD76Ugzejfn5Eq49A
#region: us
#console_ui: true
#http_proxy: false
#inspect_db_size: 50000000
log_level: info
log_format: json
#log: /var/log/ngrok.log
log: stdout
#metadata: '{"serial": "00012xa-33rUtz9", "comment": "For customer [email protected]"}'
#root_cas: trusted
#socks5_proxy: "socks5://localhost:9150"
#update: false
#update_channel: stable
web_addr: 0.0.0.0:4040
tunnels:
9 changes: 9 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

IMAGE="${1}"

docker run --rm --entrypoint=ngrok "${IMAGE}" version | grep -E '^ngrok\s+(version\s*)?[.0-9]+'

0 comments on commit 6d51ddf

Please sign in to comment.