Skip to content

Commit

Permalink
Merge pull request #143 from wayofdev/ci/e2e-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp authored Jun 10, 2024
2 parents 3707f03 + bf7e00d commit c3d098d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ override-create: ## Generate override file from dist
.PHONY: override-create

cert-install: ## Run mkcert to install CA into system storage and generate default certs for traefik
mkcert -install
bash mkcert.sh
.PHONY: cert-install

Expand Down
66 changes: 54 additions & 12 deletions mkcert.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
#!/usr/bin/env bash

if [ ! -f .env ]
then
echo "[Warning] .env file not found. Please generate it using make env command!"
exit 1;
else
set -a
source <(cat .env | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
set +a
TLS_DOMAINS=${TLS_DOMAINS%\"}
# Function to check if mkcert is installed
check_mkcert_installed() {
if ! command -v mkcert &> /dev/null; then
echo "[Error] mkcert is not installed. Please install mkcert first."
exit 1
fi
}

# Function to install mkcert CA
install_mkcert_ca() {
echo "[Info] Installing mkcert CA..."
mkcert -install
}

# Function to load environment variables from .env file
load_env() {
if [ ! -f .env ]; then
echo "[Warning] .env file not found. Please generate it using make env command!"
exit 1
else
set -a
# shellcheck disable=SC2002
source <(cat .env | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
set +a
fi
}

# Function to display domains to be loaded
display_domains() {
local DOMAINS
local DOMAIN

DOMAINS=$(echo "$TLS_DOMAINS" | sed -e 's/^"//' -e 's/"$//')

echo "[Info] Domains to load:"
for DOMAIN in ${TLS_DOMAINS#\"}; do
for DOMAIN in $DOMAINS; do
echo " - ${DOMAIN}"
done
fi
}

# Function to generate certificates
generate_certs() {
local DOMAINS
DOMAINS=$(echo "$TLS_DOMAINS" | sed -e 's/^"//' -e 's/"$//')
# shellcheck disable=SC2086
mkcert -key-file traefik/certs/key.pem -cert-file traefik/certs/cert.pem $DOMAINS
}

# Main script execution
main() {
check_mkcert_installed
install_mkcert_ca
load_env
display_domains
generate_certs
}

mkcert -key-file traefik/certs/key.pem -cert-file traefik/certs/cert.pem ${TLS_DOMAINS#\"}
main

0 comments on commit c3d098d

Please sign in to comment.