From 1add2a49f49a993d132f99c53439eeaaa4dfb39b Mon Sep 17 00:00:00 2001 From: gyurix Date: Thu, 1 Sep 2022 14:56:33 +0000 Subject: [PATCH] Added files for building deploy image --- Dockerfile | 9 +++++++++ config | 8 ++++++++ deploy.sh | 27 ++++++++++++++++----------- entrypoint.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 Dockerfile create mode 100644 config create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..54c05b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:latest + +RUN apk --update --no-cache add git openssh-client jq + +COPY config /root/.ssh/ +COPY entrypoint.sh /entrypoint.sh +COPY deploy.sh /deploy.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/config b/config new file mode 100644 index 0000000..fdbc490 --- /dev/null +++ b/config @@ -0,0 +1,8 @@ +Host GIT_REPOSITORY + User git + Port PORT + Hostname HOST + PreferredAuthentications publickey + IdentityFile /root/.ssh/id_rsa + IdentitiesOnly yes + StrictHostKeyChecking no diff --git a/deploy.sh b/deploy.sh index ae793ee..732a980 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,14 +4,17 @@ toUpperCase() { echo "$*" | tr '[:lower:]' '[:upper:]'; } GIT_REPO=$GIT_REPO -ORGANIZTAION=$ORGANIZATION +ORGANIZATION=$ORGANIZATION + +if [ "$ORGANIZATION" == "" ]; then + ORGANIZATION=format +fi PUBLIC_PROXY=$(toUpperCase $PUBLIC_PROXY) SMARTHOST_PROXY=$(toUpperCase $SMARTHOST_PROXY) WIREGUARD=$(toUpperCase $WIREGUARD) OPENVPN=$(toUpperCase $OPENVPN) -DEPLOY_KEY=$DEPLOY_KEY SERVICE_DIR=$SERVICE_DIR PROXY_DIR=$PROXY_DIR PROXY_LOG_DIR=$PROXY_LOG_DIR @@ -31,7 +34,7 @@ fi for i in $(echo $PROXY_TYPE); do # Clone source files from git repository - git clone $GIT_REPO/$ORGANIZATION/$i.git + git clone ssh://$GIT_REPO/$ORGANIZATION/$i.git /tmp/ #if [ "$i" == "public-proxy" ] ; then @@ -42,20 +45,21 @@ for i in $(echo $PROXY_TYPE); do if [ "$SERVICE_DIR" == "" ] ; then SERVICE_DIR="/etc/user/config/services"; + mkdir -p $SERVICE_DIR; fi - cp -av /tmp/$REPOSITORY/$i/service_files/ $SERVICE_DIR/ + cp -av /tmp/$REPOSITORY/$i/*.json $SERVICE_DIR/ # CREATE FILESYSTEM ACCESS FOR SERVICES if [ "$PROXY_DIR" == "" ] ; then - $PUBLIC_PROXY_DIR="/etc/system/config/$i"; + $PROXY_DIR="/etc/system/config/$i"; else - $PUBLIC_PROXY_DIR="$PROXY_DIR/$i" + $PROXY_DIR="$PROXY_DIR/$i" fi - mkdir -p $PUBLIC_PROXY_DIR/loadbalancer; - mkdir -p $PUBLIC_PROXY_DIR/backend; + mkdir -p $PROXY_DIR/loadbalancer; + mkdir -p PROXY_DIR/backend; if [ "$PROXY_LOG_DIR" == "" ] ; then $PROXY_LOG_DIR="/etc/system/log/$i" ; @@ -70,8 +74,8 @@ for i in $(echo $PROXY_TYPE); do # CREATE PROXY SCHEDULER SERVICE - # CHECK proxy.json exists - SOURCE=$(cat /tmp/$REPOSITORY/$i/proxy.json); + # CHECK prox config file exists + SOURCE=$(cat /tmp/$REPOSITORY/$i/proxy_config); TARGET=$(cat $PUBLIC_PROXY_DIR/proxy.json | tail -n+2); TMP_FILE=/tmp/proxy.json { @@ -101,7 +105,7 @@ for i in $(echo $PROXY_TYPE); do # COPY PROXY DNS FILES - git clone $GIT_REPO/$ORGANIZATION/proxy-dns.git + git clone ssh://$GIT_REPO/$ORGANIZATION/proxy-dns.git if [ "$DNS_DIR" == "" ] ; then $DNS_DIR="/etc/system/data/proxy-dns"; @@ -112,3 +116,4 @@ for i in $(echo $PROXY_TYPE); do fi fi +done diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..ba70578 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +GIT_REPOSITORY=$GIT_REPOSITORY +HOST=$HOST +PORT=$PORT +cd /root + +if [ "$PORT" == "" ]; then + PORT=20202 +fi + +if [ "$GIT_REPOSITORY" == "" ]; then + GIT_REPOSITORY=git.format.hu +fi + +if [ "$HOST" == "" ]; then + HOST=git.format.hu +fi + +sed -i "s/GIT_REPOSITORY/$GIT_REPOSITORY/g" /root/.ssh/config; +sed -i "s/HOST/$HOST/g" /root/.ssh/config; +sed -i "s/PORT/$PORT/g" /root/.ssh/config; + +# Check git repository permissions" + +if [[ "$PUBLIC_PROXY" == "YES" || "$PUBLIC_PROXY" == "TRUE" ]]; then + PROXY_TYPE=public-proxy; +fi + +if [[ "$SMARTHOST_PROXY" == "YES" || "$SMARTHOST_PROXY" == "TRUE" ]]; then + PROXY_TYPE=smarthost-proxy" "$PROXY_TYPE; +fi + +if [ "$PROXY_TYPE" == "" ] ; then + echo "No proxy type deployment defined, exiting." + exit; +fi + +sh /deploy.sh + +echo "Successfully deployed $PUBLIC_PROXY $SMARTHOST_PROXY"