diff --git a/.devcontainer/README.md b/.devcontainer/README.md index 9c1bb45a..f247d92f 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -13,11 +13,8 @@ > The following instrstuctions are for macOS environment ```sh -# set up hostname -./scripts/setup-host.sh - -# set up TLS certificates -./scripts/setup-tls.sh +# set up TLS certs and hosts in Host +./init.sh auth.dev.local # run the Dev Containers docker compose up -d diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 9e7717ea..3e03230a 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -25,11 +25,11 @@ services: KC_HOSTNAME: auth.dev.local KC_HTTP_ENABLED: 'true' KC_HTTPS_PORT: 443 - KC_HTTPS_CERTIFICATE_FILE: /opt/keycloak/tls/cert.pem - KC_HTTPS_CERTIFICATE_KEY_FILE: /opt/keycloak/tls/key.pem + KC_HTTPS_CERTIFICATE_FILE: /opt/keycloak/certs/cert.pem + KC_HTTPS_CERTIFICATE_KEY_FILE: /opt/keycloak/certs/key.pem volumes: - keycloak-data:/opt/keycloak/data - - ./keycloak/tls:/opt/keycloak/tls + - ./certs:/opt/keycloak/certs - ./keycloak/export:/opt/keycloak/data/export - ./keycloak/import:/opt/keycloak/data/import command: start --optimized --import-realm diff --git a/.devcontainer/init.sh b/.devcontainer/init.sh new file mode 100755 index 00000000..1dea1aa7 --- /dev/null +++ b/.devcontainer/init.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [ $# -le 0 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then + echo "Usage: $0 [...]" + exit 1 +fi + +for host in "$@"; do + if ! grep -q "${host}" /etc/hosts; then + echo "127.0.0.1 ${host}" | sudo tee -a /etc/hosts + fi +done + +CURRENTDIR=$(dirname "$0") +CERT_FILE="${CURRENTDIR}/certs/cert.pem" +KEY_FILE="${CURRENTDIR}/certs/key.pem" + +if [ -e "${KEY_FILE}" ] && [ -e "${CERT_FILE}" ]; then + echo "Certificate already exists" + exit 0 +fi + +if [ -z "$(command -v mkcert)" ]; then + echo "mkcert is not installed, try 'brew install mkcert'" + exit 1 +fi + +mkcert -install +mkdir -vp $(dirname "$CERT_FILE") +mkcert -cert-file "$CERT_FILE" -key-file "$KEY_FILE" $@ \ No newline at end of file diff --git a/.devcontainer/scripts/setup-hosts.sh b/.devcontainer/scripts/setup-hosts.sh deleted file mode 100755 index 5f61e6ee..00000000 --- a/.devcontainer/scripts/setup-hosts.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -declare -a hosts=("auth.dev.local") - -for host in "${hosts[@]}"; do - if ! grep -q "${host}" /etc/hosts; then - echo "127.0.0.1 ${host}" | sudo tee -a /etc/hosts - fi -done \ No newline at end of file diff --git a/.devcontainer/scripts/setup-tls.sh b/.devcontainer/scripts/setup-tls.sh deleted file mode 100755 index 160315f2..00000000 --- a/.devcontainer/scripts/setup-tls.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -CURRENTDIR=$(dirname "$0") - -CERT_FILE="${CURRENTDIR}/../keycloak/tls/cert.pem" -KEY_FILE="${CURRENTDIR}/../keycloak/tls/key.pem" - -if [ -e "${KEY_FILE}" ] && [ -e "${CERT_FILE}" ]; then - echo "Certificate already exists" - exit 0 -fi - -if [ -z "$(command -v mkcert)" ]; then - echo "mkcert is not installed, try 'brew install mkcert'" - exit 1 -fi - -mkcert -install -mkdir -vp $(dirname "$CERT_FILE") -mkcert -cert-file "$CERT_FILE" -key-file "$KEY_FILE" '*.dev.local' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 85685e33..9311469d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ log.txt # development containers /.devcontainer/keycloak/export/ -/.devcontainer/keycloak/tls/*.pem +/.devcontainer/**/*.pem ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons.