From b108d93f99e19c1b0ea5859189794c443a3b17f4 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Wed, 14 Aug 2019 09:54:16 +0200 Subject: [PATCH 1/7] Better certificate generation --- .gitignore | 3 + README.md | 7 ++- build/build.sh | 5 ++ build/helper/Dockerfile | 5 ++ config/openssl.cnf | 2 - containers/.env.example | 4 +- containers/docker-compose.yml | 2 +- etc/.gitkeep | 0 scripts/env.sh | 13 ++++ scripts/generate-certificates.sh | 28 +++------ .../helper/docker-generate-certificates.sh | 59 +++++++++++++++++++ scripts/install-cert-macos.sh | 19 ++++++ scripts/pontsun | 43 ++++++++++++++ 13 files changed, 163 insertions(+), 27 deletions(-) create mode 100755 build/build.sh create mode 100644 build/helper/Dockerfile create mode 100644 etc/.gitkeep create mode 100644 scripts/env.sh create mode 100755 scripts/helper/docker-generate-certificates.sh create mode 100755 scripts/install-cert-macos.sh create mode 100755 scripts/pontsun diff --git a/.gitignore b/.gitignore index 68f590c..ccc4242 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ # Local .env + + +etc/ \ No newline at end of file diff --git a/README.md b/README.md index 0fcf2f0..07101ff 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,11 @@ Create certificates for HTTPS ```bash -chmod u+x ./scripts/generate-certificates.sh -./scripts/generate-certificates.sh +./scripts/pontsun generate-cert +``` +You need to add the generated certificate `etc/certificates/docker.rootCA.crt` to your browser authorities and trust related websites. +On OS X, this was automatically added to your keychain if the command above worked correctly. No need to do anything else. ``` -You need to add the generated certificate `certificates/docker.rootCA.crt` to your browser authorities and trust related websites. Start Traefik and Portainer ```bash diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..bd42e76 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd $DIR +docker build -t liip/pontsun-helper:latest helper diff --git a/build/helper/Dockerfile b/build/helper/Dockerfile new file mode 100644 index 0000000..bb45979 --- /dev/null +++ b/build/helper/Dockerfile @@ -0,0 +1,5 @@ +FROM debian:stable-slim + +RUN apt-get update + +RUN apt-get install -y openssl gnutls-bin \ No newline at end of file diff --git a/config/openssl.cnf b/config/openssl.cnf index 5302f87..543dde8 100644 --- a/config/openssl.cnf +++ b/config/openssl.cnf @@ -11,5 +11,3 @@ keyUsage = nonRepudiation, digitalSignature, keyEncipherment subjectAltName = @alt_names [ alt_names ] -DNS.1 = ${ENV::PROJECT_NAME}.${ENV::PROJECT_EXTENSION} -DNS.2 = *.${ENV::PROJECT_NAME}.${ENV::PROJECT_EXTENSION} diff --git a/containers/.env.example b/containers/.env.example index 6727809..12adba8 100644 --- a/containers/.env.example +++ b/containers/.env.example @@ -1,5 +1,4 @@ ### Project settings - COMPOSE_PROJECT_NAME=traefik PROJECT_NAME=pontsun PROJECT_EXTENSION=test @@ -12,6 +11,9 @@ PONTSUN_HTTPS_PORT=443 # name of the docker network used for pontsun PONTSUN_NETWORK=pontsun +# Where to store local config files, could also be ~/.pontsun +PONTSUN_DIR_ETC=../etc + ### Images tags PORTAINER_TAG=1.19.2 TRAEFIK_TAG=1.7.2-alpine diff --git a/containers/docker-compose.yml b/containers/docker-compose.yml index c779d32..9ed5ca1 100644 --- a/containers/docker-compose.yml +++ b/containers/docker-compose.yml @@ -22,7 +22,7 @@ services: - '${PONTSUN_HTTP_PORT}:80' - '${PONTSUN_HTTPS_PORT}:443' volumes: - - ../certificates/:/certs/ + - ${PONTSUN_DIR_ETC:-../etc/}/certificates/:/certs/ - /var/run/docker.sock:/var/run/docker.sock labels: - 'traefik.enable=true' diff --git a/etc/.gitkeep b/etc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100644 index 0000000..eb6b348 --- /dev/null +++ b/scripts/env.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +export PONTSUN_DIR=${PONTSUN_DIR:-$DIR/../} +export PONTSUN_DIR_ETC=${PONTSUN_DIR_ETC:-$PONTSUN_DIR/etc/} + +# Load env file +set -a +# load env variables but only if not set already +test -f $PONTSUN_DIR/containers/.env && source <(grep -v '^\s*#' $PONTSUN_DIR/containers/.env | sed -E 's|^ *([^=]+)=(.*)$|: ${\1=\2}; export \1|g') + diff --git a/scripts/generate-certificates.sh b/scripts/generate-certificates.sh index d864843..a3ffacf 100755 --- a/scripts/generate-certificates.sh +++ b/scripts/generate-certificates.sh @@ -1,25 +1,13 @@ -#!/bin/bash -set -e +#!/usr/bin/env bash -# Load env file -set -a -test -f $(dirname $0)/../containers/.env && source $(dirname $0)/../containers/.env -set +a -cd $(dirname $0)/../certificates +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if [ -f $PROJECT_NAME.crt ]; then - echo "Certificate already exists." -else - subj="/C=CH/ST=FR/L=Fribourg/O=Liip/OU=Pontsun/CN=$PROJECT_NAME.$PROJECT_EXTENSION" +. $DIR/env.sh - openssl genrsa -out $PROJECT_NAME.rootCA.key 4096 - openssl req -x509 -new -nodes -key $PROJECT_NAME.rootCA.key -sha256 -days 1024 -out $PROJECT_NAME.rootCA.crt -subj "$subj" +mkdir -p $PONTSUN_DIR_ETC/certificates/ - openssl genrsa -out $PROJECT_NAME.key 4096 - openssl req -new -sha256 -subj "$subj" -key $PROJECT_NAME.key -out $PROJECT_NAME.csr -config ../config/openssl.cnf - openssl x509 -req -in $PROJECT_NAME.csr -CA $PROJECT_NAME.rootCA.crt -CAkey $PROJECT_NAME.rootCA.key -CAcreateserial -out $PROJECT_NAME.crt -days 365 -extensions v3_req -extfile ../config/openssl.cnf - - cat $PROJECT_NAME.crt $PROJECT_NAME.key > $PROJECT_NAME.pem - chmod 600 $PROJECT_NAME.key $PROJECT_NAME.pem -fi +docker run --rm -v $DIR/../:/generate/ -v $PONTSUN_DIR_ETC/certificates/:/certs/ -it liip/pontsun-helper:latest /generate/scripts/helper/docker-generate-certificates.sh $1 +if [[ "$OSTYPE" == "darwin"* ]]; then + $DIR/install-cert-macos.sh $PONTSUN_DIR_ETC/certificates/$PROJECT_NAME.rootCA.crt +fi \ No newline at end of file diff --git a/scripts/helper/docker-generate-certificates.sh b/scripts/helper/docker-generate-certificates.sh new file mode 100755 index 0000000..903c571 --- /dev/null +++ b/scripts/helper/docker-generate-certificates.sh @@ -0,0 +1,59 @@ +#!/bin/bash +set -e + +# Load env file +set -a +test -f $(dirname $0)/../../containers/.env && source $(dirname $0)/../../containers/.env +set +a + +# check if there are certs in the local directory +cd /certs/ +if [ -f $PROJECT_NAME.crt ] && [ -z $1 ]; then + echo "Certificate already exists in local certificates directory." +else + if [ -f $PROJECT_NAME.crt ]; then + # get existing alt names from the current cert, so that we can reuse them + EXISTING_ALT_NAMES=$(certtool -i < /certs/$PROJECT_NAME.crt | grep DNSname | cut -f 2 -d ":" | sed -e 's/^[[:space:]]*//') + ALT_NAMES=${EXISTING_ALT_NAMES} + else + ALT_NAMES=$PROJECT_NAME.$PROJECT_EXTENSION + ALT_NAMES=${ALT_NAMES}$'\n'*.$PROJECT_NAME.$PROJECT_EXTENSION + fi + # add additional altnames + if [[ ! -z $1 ]]; then + ALT_NAMES=${ALT_NAMES}$'\n'$1 + ALT_NAMES=${ALT_NAMES}$'\n'*.$1 + fi + + # sort them and make them uniq to avoid duplicates + ALT_NAMES=$(echo $"${ALT_NAMES}" | sort | uniq) + EXISTING_ALT_NAMES=$(echo $"${EXISTING_ALT_NAMES}" | sort | uniq) + + if [[ $ALT_NAMES == $EXISTING_ALT_NAMES ]]; then + echo "Certificate wouldn't change, don't generate a new one." + exit 0; + fi + + I=1 + #write the correct config lines + while read -r line; do + if [[ ! -z $line ]]; then + ALT_NAMES_CONFIG=$ALT_NAMES_CONFIG$'\n'"DNS.$I = $line" + ((I++)) + fi + done <<< "$ALT_NAMES" + + subj="/C=CH/ST=FR/L=Fribourg/O=Liip/CN=$PROJECT_NAME.$PROJECT_EXTENSION" + # don't regenerate rootCA, if it already exists + if [ ! -f $PROJECT_NAME.rootCA.key ]; then + openssl genrsa -out $PROJECT_NAME.rootCA.key 4096 + openssl req -x509 -new -nodes -key $PROJECT_NAME.rootCA.key -sha256 -days 1024 -out $PROJECT_NAME.rootCA.crt -subj "$subj" + fi + openssl genrsa -out $PROJECT_NAME.key 4096 + openssl req -new -sha256 -subj "$subj" -key $PROJECT_NAME.key -out $PROJECT_NAME.csr -config <(cat /generate/config/openssl.cnf <(printf "$ALT_NAMES_CONFIG")) + openssl x509 -req -in $PROJECT_NAME.csr -CA $PROJECT_NAME.rootCA.crt -CAkey $PROJECT_NAME.rootCA.key -CAcreateserial -out $PROJECT_NAME.crt -days 365 -extensions v3_req -extfile <(cat /generate/config/openssl.cnf <(printf "$ALT_NAMES_CONFIG")) + + cat $PROJECT_NAME.crt $PROJECT_NAME.key > $PROJECT_NAME.pem + chmod 600 $PROJECT_NAME.key $PROJECT_NAME.pem +fi + diff --git a/scripts/install-cert-macos.sh b/scripts/install-cert-macos.sh new file mode 100755 index 0000000..6d62009 --- /dev/null +++ b/scripts/install-cert-macos.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# base from https://gist.github.com/koop/84254d5214495e6fc49db3284c9b7772 +# Usage +# $ ./install-cert-macos.sh "/path/to/cert" + +CERT_PATH=$1 + + + +# First, grab the SHA-1 from the provided SSL cert. +CERT_SHA1=$(openssl x509 -in "$CERT_PATH" -sha1 -noout -fingerprint | cut -d "=" -f2 | sed "s/://g") + +# Next, grab the SHA-1s of any standard.dev certs in the keychain. +# Don't return an error code if nothing is found. +EXISTING_CERT_SHAS=$(security find-certificate -a -c "$PROJECT_NAME.$PROJECT_EXTENSION" -Z /Library/Keychains/System.keychain | grep "SHA-1") || true +echo "$EXISTING_CERT_SHAS" | grep -q "$CERT_SHA1" || { + echo "Installing $CERT_PATH into your Keychain" + sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$CERT_PATH" +} \ No newline at end of file diff --git a/scripts/pontsun b/scripts/pontsun new file mode 100755 index 0000000..837356b --- /dev/null +++ b/scripts/pontsun @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +show_help() { + echo "Usage: pontsun [options] []" + echo + echo " -h Print this help." + echo + echo "Common commands:" + echo " generate-cert [host] Generates needed ssl certificates" +} + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +OPTIND=1 # Reset in case getopts has been used previously in the shell. + +while getopts "hv" opt; do + case "$opt" in + h*) + show_help + exit 0 + ;; + esac +done + +shift $((OPTIND-1)) + +[ "${1:-}" = "--" ] && shift + +if [ -z $1 ]; then + show_help + exit 0 +fi + +case "$1" in + generate-cert) + $DIR/generate-certificates.sh $2 + ;; + *) + echo "No such command: $1" + show_help + ;; +esac + + From afaa2b64faa360e7facd0ee4fd0f4d2af85488f1 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Wed, 14 Aug 2019 11:29:26 +0200 Subject: [PATCH 2/7] Fix some stuff from PR feedback --- .gitignore | 4 ++-- build/build.sh | 2 ++ build/helper/Dockerfile | 2 +- scripts/env.sh | 2 +- scripts/generate-certificates.sh | 2 +- scripts/helper/docker-generate-certificates.sh | 2 +- scripts/install-cert-macos.sh | 6 +++--- scripts/pontsun | 2 ++ 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index ccc4242..94b6bcc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,8 @@ *.pem *.srl -# Local +# Local .env configuration .env - +# Here are the local configurations like certificates and more later etc/ \ No newline at end of file diff --git a/build/build.sh b/build/build.sh index bd42e76..55fa51f 100755 --- a/build/build.sh +++ b/build/build.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -e + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR diff --git a/build/helper/Dockerfile b/build/helper/Dockerfile index bb45979..5526dd2 100644 --- a/build/helper/Dockerfile +++ b/build/helper/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:stable-slim +FROM debian:buster-slim RUN apt-get update diff --git a/scripts/env.sh b/scripts/env.sh index eb6b348..fb00757 100644 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" diff --git a/scripts/generate-certificates.sh b/scripts/generate-certificates.sh index a3ffacf..b2f3ffb 100755 --- a/scripts/generate-certificates.sh +++ b/scripts/generate-certificates.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" diff --git a/scripts/helper/docker-generate-certificates.sh b/scripts/helper/docker-generate-certificates.sh index 903c571..becdeda 100755 --- a/scripts/helper/docker-generate-certificates.sh +++ b/scripts/helper/docker-generate-certificates.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # Load env file diff --git a/scripts/install-cert-macos.sh b/scripts/install-cert-macos.sh index 6d62009..f4b2e73 100755 --- a/scripts/install-cert-macos.sh +++ b/scripts/install-cert-macos.sh @@ -1,12 +1,12 @@ -#!/bin/bash +#!/bin/sh +set -e + # base from https://gist.github.com/koop/84254d5214495e6fc49db3284c9b7772 # Usage # $ ./install-cert-macos.sh "/path/to/cert" CERT_PATH=$1 - - # First, grab the SHA-1 from the provided SSL cert. CERT_SHA1=$(openssl x509 -in "$CERT_PATH" -sha1 -noout -fingerprint | cut -d "=" -f2 | sed "s/://g") diff --git a/scripts/pontsun b/scripts/pontsun index 837356b..8a71e55 100755 --- a/scripts/pontsun +++ b/scripts/pontsun @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -e + show_help() { echo "Usage: pontsun [options] []" echo From a6922980e208e2b6421d78521c0cc33a8cacce0a Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Wed, 14 Aug 2019 14:44:15 +0200 Subject: [PATCH 3/7] make helper image smaller --- build/helper/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build/helper/Dockerfile b/build/helper/Dockerfile index 5526dd2..faf0dce 100644 --- a/build/helper/Dockerfile +++ b/build/helper/Dockerfile @@ -1,5 +1,3 @@ FROM debian:buster-slim -RUN apt-get update - -RUN apt-get install -y openssl gnutls-bin \ No newline at end of file +RUN apt-get update && apt-get install -y openssl gnutls-bin && rm -rf /var/lib/apt/lists/* \ No newline at end of file From 5dc1244a403074584d1a9ea2f6da9ba2f5e9aa0a Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Mon, 19 Aug 2019 09:30:22 +0200 Subject: [PATCH 4/7] check for .env, move helper scripts to scripts/helper --- README.md | 2 +- scripts/env.sh | 13 ------------ scripts/generate-certificates.sh | 6 +++--- scripts/helper/env.sh | 24 ++++++++++++++++++++++ scripts/{ => helper}/install-cert-macos.sh | 0 5 files changed, 28 insertions(+), 17 deletions(-) delete mode 100644 scripts/env.sh create mode 100644 scripts/helper/env.sh rename scripts/{ => helper}/install-cert-macos.sh (100%) diff --git a/README.md b/README.md index 07101ff..4e411eb 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Create certificates for HTTPS ```bash ./scripts/pontsun generate-cert ``` -You need to add the generated certificate `etc/certificates/docker.rootCA.crt` to your browser authorities and trust related websites. +You need to add the generated certificate `etc/certificates/pontsun.rootCA.crt` to your browser authorities and trust related websites. On OS X, this was automatically added to your keychain if the command above worked correctly. No need to do anything else. ``` diff --git a/scripts/env.sh b/scripts/env.sh deleted file mode 100644 index fb00757..0000000 --- a/scripts/env.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -export PONTSUN_DIR=${PONTSUN_DIR:-$DIR/../} -export PONTSUN_DIR_ETC=${PONTSUN_DIR_ETC:-$PONTSUN_DIR/etc/} - -# Load env file -set -a -# load env variables but only if not set already -test -f $PONTSUN_DIR/containers/.env && source <(grep -v '^\s*#' $PONTSUN_DIR/containers/.env | sed -E 's|^ *([^=]+)=(.*)$|: ${\1=\2}; export \1|g') - diff --git a/scripts/generate-certificates.sh b/scripts/generate-certificates.sh index b2f3ffb..e5f7c1a 100755 --- a/scripts/generate-certificates.sh +++ b/scripts/generate-certificates.sh @@ -3,11 +3,11 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -. $DIR/env.sh +. $DIR/helper/env.sh mkdir -p $PONTSUN_DIR_ETC/certificates/ -docker run --rm -v $DIR/../:/generate/ -v $PONTSUN_DIR_ETC/certificates/:/certs/ -it liip/pontsun-helper:latest /generate/scripts/helper/docker-generate-certificates.sh $1 +docker run --rm -v $PONTSUN_DIR/:/generate/ -v $PONTSUN_DIR_ETC/certificates/:/certs/ -it liip/pontsun-helper:latest /generate/scripts/helper/docker-generate-certificates.sh $1 if [[ "$OSTYPE" == "darwin"* ]]; then - $DIR/install-cert-macos.sh $PONTSUN_DIR_ETC/certificates/$PROJECT_NAME.rootCA.crt + $PONTSUN_DIR/scripts/helper/install-cert-macos.sh $PONTSUN_DIR_ETC/certificates/$PROJECT_NAME.rootCA.crt fi \ No newline at end of file diff --git a/scripts/helper/env.sh b/scripts/helper/env.sh new file mode 100644 index 0000000..76ffe8f --- /dev/null +++ b/scripts/helper/env.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +PONTSUN_DIR_REL=${PONTSUN_DIR:-$DIR/../../} +PONTSUN_DIR="$( cd ${PONTSUN_DIR_REL} && pwd )" +PONTSUN_DIR_ETC=${PONTSUN_DIR_ETC:-$PONTSUN_DIR/etc/} + +# Load env file +set -a +# load env variables but only if not set already + +if [[ ! -f $PONTSUN_DIR/containers/.env ]]; then + RED='\033[0;31m' + NC='\033[0m' # No Color + + printf "${RED}${PONTSUN_DIR}/containers/.env does not exist!${NC}\nPlease copy it with:\n" + printf "cp ${PONTSUN_DIR}/containers/.env.example ${PONTSUN_DIR}/containers/.env\n" + printf "and adjust it.\n" + exit 1 +fi +test -f $PONTSUN_DIR/containers/.env && source <(grep -v '^\s*#' $PONTSUN_DIR/containers/.env | sed -E 's|^ *([^=]+)=(.*)$|: ${\1=\2}; export \1|g') + diff --git a/scripts/install-cert-macos.sh b/scripts/helper/install-cert-macos.sh similarity index 100% rename from scripts/install-cert-macos.sh rename to scripts/helper/install-cert-macos.sh From 9a0d76d7659730f017ba259576a95338c24975bb Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Mon, 19 Aug 2019 09:34:54 +0200 Subject: [PATCH 5/7] add about .env file --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4e411eb..7709207 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,34 @@ ## Installation +### .env file + +Copy and adjust `containers/.env.example` to `containers/.env` + +``` +cp containers/.env.example containers/.env +``` + +### Generate SSL certificate + Create certificates for HTTPS ```bash ./scripts/pontsun generate-cert ``` You need to add the generated certificate `etc/certificates/pontsun.rootCA.crt` to your browser authorities and trust related websites. On OS X, this was automatically added to your keychain if the command above worked correctly. No need to do anything else. -``` -Start Traefik and Portainer +### Setup local DNS + +See + +- [Docker installation for Mac](docs/docker-installation-for-mac.md) +- [Docker installation for Ubuntu](docs/docker-installation-for-ubuntu.md) + +for now. + +### Start pontsun with traefik and portainer + ```bash cd containers docker-compose up -d From e9fefaab87a2f56b7fee620597589befa36e7460 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Mon, 19 Aug 2019 09:43:51 +0200 Subject: [PATCH 6/7] use alpine instead of buster --- build/helper/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/helper/Dockerfile b/build/helper/Dockerfile index faf0dce..aa3837b 100644 --- a/build/helper/Dockerfile +++ b/build/helper/Dockerfile @@ -1,3 +1,5 @@ -FROM debian:buster-slim +FROM alpine:3.10 -RUN apt-get update && apt-get install -y openssl gnutls-bin && rm -rf /var/lib/apt/lists/* \ No newline at end of file +RUN set -ex; \ + # Install Bash and OpenSSL + apk add --no-cache bash openssl \ No newline at end of file From fd8b7dab65a98fb560e327238f61f2e271fa53f5 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Wed, 14 Aug 2019 12:57:18 +0200 Subject: [PATCH 7/7] Add up and down command/scripts and make portainer optional # Conflicts: # containers/.env.example --- README.md | 6 ++++++ containers/.env.example | 3 +++ scripts/down.sh | 9 +++++++++ scripts/pontsun | 8 ++++++++ scripts/up.sh | 21 +++++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100755 scripts/down.sh create mode 100755 scripts/up.sh diff --git a/README.md b/README.md index 7709207..a2167c1 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,12 @@ for now. ### Start pontsun with traefik and portainer +```bash +./scripts/pontsun up +``` + +or + ```bash cd containers docker-compose up -d diff --git a/containers/.env.example b/containers/.env.example index 12adba8..ec4f2c9 100644 --- a/containers/.env.example +++ b/containers/.env.example @@ -4,6 +4,9 @@ PROJECT_NAME=pontsun PROJECT_EXTENSION=test PROJECT_DOMAIN=pontsun.test +# services +PONTSUN_PORTAINER=yes + # Used ports for traeffik PONTSUN_HTTP_PORT=80 PONTSUN_HTTPS_PORT=443 diff --git a/scripts/down.sh b/scripts/down.sh new file mode 100755 index 0000000..6098c2e --- /dev/null +++ b/scripts/down.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. $DIR/helper/env.sh + +cd $PONTSUN_DIR/containers/ + +docker-compose down diff --git a/scripts/pontsun b/scripts/pontsun index 8a71e55..e998687 100755 --- a/scripts/pontsun +++ b/scripts/pontsun @@ -7,6 +7,8 @@ show_help() { echo " -h Print this help." echo echo "Common commands:" + echo " up Starts pontsun services" + echo " down Stops pontsun services" echo " generate-cert [host] Generates needed ssl certificates" } @@ -33,6 +35,12 @@ if [ -z $1 ]; then fi case "$1" in + up) + $DIR/up.sh + ;; + down) + $DIR/down.sh + ;; generate-cert) $DIR/generate-certificates.sh $2 ;; diff --git a/scripts/up.sh b/scripts/up.sh new file mode 100755 index 0000000..beadf34 --- /dev/null +++ b/scripts/up.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. $DIR/helper/env.sh + +cd $PONTSUN_DIR/containers/ + +SERVICES="traefik" + +if [[ "$PONTSUN_PORTAINER" != "no" ]]; then + SERVICES="$SERVICES portainer" +fi + +echo "Starting pontsun services: $SERVICES" + +docker-compose up -d $SERVICES + +if ! ping -c 1 -t 2 traefik.$PROJECT_DOMAIN > /dev/null 2>&1 ; then + echo >&2 "!!!! traefik.$PROJECT_DOMAIN could not be resolved. You should fix this !!!!" +fi \ No newline at end of file