Skip to content

Commit

Permalink
Merge setup-*.sh into init.sh
Browse files Browse the repository at this point in the history
- Tuning TLS certs files location
  • Loading branch information
akunzai committed Nov 20, 2023
1 parent e7758b4 commit b8d9a79
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 41 deletions.
7 changes: 2 additions & 5 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions .devcontainer/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -euo pipefail

if [ $# -le 0 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "Usage: $0 <host> [<host>...]"
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" $@
11 changes: 0 additions & 11 deletions .devcontainer/scripts/setup-hosts.sh

This file was deleted.

21 changes: 0 additions & 21 deletions .devcontainer/scripts/setup-tls.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b8d9a79

Please sign in to comment.