|
| 1 | +#!/usr/bin/bash |
| 2 | +config="debug" |
| 3 | + |
| 4 | +# Getting the bash script executing path. See: https://stackoverflow.com/a/630387 |
| 5 | +base_dir="$(dirname -- "${BASH_SOURCE[0]}")" # relative |
| 6 | +base_dir="$(cd -- "$base_dir" && pwd)" # absolutized and normalized |
| 7 | + |
| 8 | +if [[ -z "$base_dir" ]]; then |
| 9 | + echo "the path is not accessible" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +source_dir="$base_dir/src" |
| 14 | +build_dir="$base_dir/build" |
| 15 | +result_dir="$build_dir/results" |
| 16 | + |
| 17 | +# Calling options |
| 18 | +case $1 in |
| 19 | +"clean") |
| 20 | + clean |
| 21 | + echo "All cleaned" |
| 22 | + ;; |
| 23 | +"compile") |
| 24 | + compile |
| 25 | + echo "All compiled" |
| 26 | + ;; |
| 27 | +"dockerBuild") |
| 28 | + dockerBuild |
| 29 | + echo "Docker images builded" |
| 30 | + ;; |
| 31 | +"dockerUp") |
| 32 | + dockerUp |
| 33 | + echo "Docker containers running" |
| 34 | + ;; |
| 35 | +"dockerDown") |
| 36 | + dockerDown |
| 37 | + echo "Docker containers deleted" |
| 38 | + ;; |
| 39 | +"dockerStart") |
| 40 | + dockerStart |
| 41 | + echo "Docker containers started" |
| 42 | + ;; |
| 43 | +"dockerStop") |
| 44 | + dockerStop |
| 45 | + echo "Docker containers stopped" |
| 46 | + ;; |
| 47 | +"fetchSubComponent") |
| 48 | + fetchSubComponent |
| 49 | + echo "Submodules updated" |
| 50 | + ;; |
| 51 | +*) |
| 52 | + help |
| 53 | + ;; |
| 54 | +esac |
| 55 | + |
| 56 | +# Config profile |
| 57 | +if [[ -n $2 ]]; then |
| 58 | + config=$2 |
| 59 | +fi |
| 60 | + |
| 61 | +function getDockerVersion() { |
| 62 | + local docker_version='local' |
| 63 | + |
| 64 | + if [[ $DOCKER_VERSION != '' ]]; then |
| 65 | + docker_version=$DOCKER_VERSION |
| 66 | + fi |
| 67 | + |
| 68 | + echo "$docker_version" |
| 69 | +} |
| 70 | + |
| 71 | +function fetchSubComponent() { |
| 72 | + git -C "$base_dir" submodule update --init --recursive |
| 73 | +} |
| 74 | + |
| 75 | +function clean() { |
| 76 | + fetchSubComponent |
| 77 | + |
| 78 | + rm "$build_dir" -r -f |
| 79 | +} |
| 80 | + |
| 81 | +function compile() { |
| 82 | + clean |
| 83 | + |
| 84 | + dotnet build "$base_dir/json-ld.net/JsonLD.sln" -c "$config" --nologo |
| 85 | + dotnet build "$base_dir/SimpleIdServer.IdServer.Host.sln" -c "$config" --nologo |
| 86 | + dotnet build "$base_dir/SimpleIdServer.Scim.Host.sln" -c "$config" --nologo |
| 87 | + dotnet build "$base_dir/SimpleIdServer.Did.sln" -c "$config" --nologo |
| 88 | + dotnet build "$base_dir/SimpleIdServer.CredentialIssuer.Host.sln" -c "$config" --nologo |
| 89 | +} |
| 90 | + |
| 91 | +function setDockerTag() { |
| 92 | + local docker_version |
| 93 | + docker_version=$(getDockerVersion) |
| 94 | + |
| 95 | + export TAG=$docker_version |
| 96 | +} |
| 97 | + |
| 98 | +function dockerBuild { |
| 99 | + clean |
| 100 | + setDockerTag |
| 101 | + |
| 102 | + echo "Building Docker images with version: $TAG" |
| 103 | + |
| 104 | + dotnet publish "$source_dir/IdServer/SimpleIdServer.IdServer.Startup/SimpleIdServer.IdServer.Startup.csproj" -c "$config" -o "$result_dir/docker/IdServer" --nologo |
| 105 | + dotnet publish "$source_dir/IdServer/SimpleIdServer.IdServer.Website.Startup/SimpleIdServer.IdServer.Website.Startup.csproj" -c "$config" -o "$result_dir/docker/IdServerWebsite" --nologo |
| 106 | + dotnet publish "$source_dir/Scim/SimpleIdServer.Scim.Startup/SimpleIdServer.Scim.Startup.csproj" -c "$config" -o "$result_dir/docker/Scim" --nologo |
| 107 | + dotnet publish "$source_dir/CredentialIssuer/SimpleIdServer.CredentialIssuer.Startup/SimpleIdServer.CredentialIssuer.Startup.csproj" -c "$config" -o "$result_dir/docker/CredentialIssuer" --nologo |
| 108 | + dotnet publish "$source_dir/CredentialIssuer/SimpleIdServer.CredentialIssuer.Website.Startup/SimpleIdServer.CredentialIssuer.Website.Startup.csproj" -c "$config" -o "$result_dir/docker/CredentialIssuerWebsite" --nologo |
| 109 | + |
| 110 | + docker compose -f "$base_dir/local-docker-compose.yml" build --no-cache |
| 111 | +} |
| 112 | + |
| 113 | +function dockerUp() { |
| 114 | + setDockerTag |
| 115 | + |
| 116 | + echo "Running Docker containers with version: $TAG" |
| 117 | + |
| 118 | + docker compose -f "$base_dir/local-docker-compose.yml" up -d |
| 119 | +} |
| 120 | + |
| 121 | +function dockerDown() { |
| 122 | + echo "Deleting Docker containers" |
| 123 | + |
| 124 | + docker compose -f "$base_dir/local-docker-compose.yml" down |
| 125 | +} |
| 126 | + |
| 127 | +function dockerStart() { |
| 128 | + echo "Starting Docker containers" |
| 129 | + |
| 130 | + docker compose -f "$base_dir/local-docker-compose.yml" start |
| 131 | +} |
| 132 | + |
| 133 | +function dockerStop() { |
| 134 | + echo "Stopping Docker containers" |
| 135 | + |
| 136 | + docker compose -f "$base_dir/local-docker-compose.yml" stop |
| 137 | +} |
| 138 | + |
| 139 | +help() { |
| 140 | + echo "Use: |
| 141 | +. idserver.sh OPTION CONFIG |
| 142 | +
|
| 143 | +If alias idserver was added in ~/.bash_aliases file: |
| 144 | +
|
| 145 | +idserver OPTION CONFIG |
| 146 | +
|
| 147 | +OPTIONs: |
| 148 | + clean Clean the folders. |
| 149 | + compile Compile all the projects. |
| 150 | + dockerBuild Build all the projects for running them in Docker Containers. |
| 151 | + dockerUp Build all the projects and run them in Docker Containers. |
| 152 | + dockerDown Delete all Docker Containers. |
| 153 | + dockerStart Start all Docker Containers. |
| 154 | + dockerStop Stop all Docker Containers. |
| 155 | + help Show this help message. |
| 156 | + |
| 157 | +CONFIGs: |
| 158 | + Possible values are: debug and release" |
| 159 | +} |
0 commit comments