From d7f2bbe2900322bb5ecba94aa1ab4fafad5cf21c Mon Sep 17 00:00:00 2001 From: Peter Motzko <56410761+pmoscode@users.noreply.github.com> Date: Thu, 23 Nov 2023 08:43:10 +0100 Subject: [PATCH] feat(dev): add pgAdmin to local dev env (#144) Additions and Changes: - add pgAdmin to docker-compose.yaml (incl. mounts) - preconfigure pgAdmin DB server - add tem. files to gitignore - update README.md - update Taskfile tasks for linux and macos - update env.* environment files - Match Postgresql version to the version of the Helm chart (14.5) --- .gitignore | 2 ++ README.md | 23 +++++++++++++++++- .../docker-environment/docker-compose.yaml | 24 +++++++++++++++++-- .../pgAdmin/servers.json.tpl | 22 +++++++++++++++++ .../pgAdmin/storage/.git-keep | 22 +++++++++++++++++ .../docker-environment/postgres/init.sql | 21 ---------------- dev-assets/env-files/env.docker.dist | 4 ++++ dev-assets/env-files/env.local.dist | 4 ++++ dev-assets/tasks/darwin/docker.yaml | 6 +++-- dev-assets/tasks/linux/docker.yaml | 6 +++-- 10 files changed, 106 insertions(+), 28 deletions(-) create mode 100755 dev-assets/docker-environment/pgAdmin/servers.json.tpl create mode 100755 dev-assets/docker-environment/pgAdmin/storage/.git-keep delete mode 100644 dev-assets/docker-environment/postgres/init.sql diff --git a/.gitignore b/.gitignore index b355ac349..4bbae21a7 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,8 @@ dev-assets/env-files/env.local dev-assets/env-files/env.docker dev-assets/env-files/env.environment dev-assets/docker-environment/postgres/db.sh +dev-assets/docker-environment/pgAdmin/servers.json +dev-assets/docker-environment/pgAdmin/storage/* .java-version diff --git a/README.md b/README.md index 97b62258a..85bd88f3c 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,27 @@ When you just run `task` without parameters, you will see all tasks available. 5. Click on "Authorize" and "close" 6. MIW is up and running +### pgAdmin + +This local environment contains [pgAdmin](https://www.pgadmin.org/), which is also started (default: http://localhost:8888). +The default login is: + +``` +user: pg@admin.com (you can change it in the env.* files) +password: the one you set for "POSTGRES_PASSWORD" in the env.* files +``` + +#### DB connection password + +When you log in into pgAdmin, the local Postgresql server is already configured. +But you will be asked to enter the DB password on the first time you connect to the DB. +(password: POSTGRES_PASSWORD in the env.* files) + +#### Storage folder + +The storage folder of pgAdmin is mounted to `dev-assets/docker-environment/pgAdmin/storage/`. +For example, You can save DB backups there, so you can access them on your local machine. + # End Users See OpenAPI documentation, which is automatically created from the source and available on each deployment at @@ -344,4 +365,4 @@ See [Docker-hub-notice.md](./Docker-hub-notice.md) We would like to give credit to these projects, which we use in our project. -[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) \ No newline at end of file +[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) diff --git a/dev-assets/docker-environment/docker-compose.yaml b/dev-assets/docker-environment/docker-compose.yaml index aa092e263..a2873cf45 100644 --- a/dev-assets/docker-environment/docker-compose.yaml +++ b/dev-assets/docker-environment/docker-compose.yaml @@ -34,7 +34,7 @@ services: - miw-net postgres: - image: postgres:15.3-alpine3.18 + image: postgres:14.5-alpine3.16 volumes: - postgres_data:/var/lib/postgresql/data - ./postgres/db.sh:/docker-entrypoint-initdb.d/init-database.sh @@ -63,10 +63,30 @@ services: networks: - miw-net + pgadmin: + image: dpage/pgadmin4 + ports: + - "8888:80" + user: root # If removed, the storage mount won't work + env_file: + - ../env-files/env.$DEV_ENVIRONMENT + environment: + PGADMIN_DISABLE_POSTFIX: true + volumes: + - pgadmin_data:/var/lib/pgadmin + - ./pgAdmin/servers.json:/pgadmin4/servers.json + - ./pgAdmin/storage/:/var/lib/pgadmin/storage/pg_admin.com/ + depends_on: + - postgres + networks: + - miw-net + volumes: postgres_data: driver: local + pgadmin_data: + driver: local networks: miw-net: - name: miw-net \ No newline at end of file + name: miw-net diff --git a/dev-assets/docker-environment/pgAdmin/servers.json.tpl b/dev-assets/docker-environment/pgAdmin/servers.json.tpl new file mode 100755 index 000000000..ac34530a5 --- /dev/null +++ b/dev-assets/docker-environment/pgAdmin/servers.json.tpl @@ -0,0 +1,22 @@ +{ + "Servers": { + "1": { + "Name": "Local", + "Group": "Servers", + "Host": "postgres", + "Port": 5432, + "MaintenanceDB": "postgres", + "Username": "$POSTGRES_USER", + "UseSSHTunnel": 0, + "TunnelPort": "22", + "TunnelAuthentication": 0, + "KerberosAuthentication": false, + "ConnectionParameters": { + "sslmode": "prefer", + "connect_timeout": 10, + "sslcert": "/.postgresql/postgresql.crt", + "sslkey": "/.postgresql/postgresql.key" + } + } + } +} diff --git a/dev-assets/docker-environment/pgAdmin/storage/.git-keep b/dev-assets/docker-environment/pgAdmin/storage/.git-keep new file mode 100755 index 000000000..1f8f00cda --- /dev/null +++ b/dev-assets/docker-environment/pgAdmin/storage/.git-keep @@ -0,0 +1,22 @@ +# +# /******************************************************************************** +# Copyright (c) 2021,2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ********************************************************************************/ +# + +Is mounted as storage folder inside the pgAdmin container. diff --git a/dev-assets/docker-environment/postgres/init.sql b/dev-assets/docker-environment/postgres/init.sql deleted file mode 100644 index 64f272cf7..000000000 --- a/dev-assets/docker-environment/postgres/init.sql +++ /dev/null @@ -1,21 +0,0 @@ -/* - * ******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ****************************************************************************** - */ - diff --git a/dev-assets/env-files/env.docker.dist b/dev-assets/env-files/env.docker.dist index aec3b1b29..12aed3d56 100644 --- a/dev-assets/env-files/env.docker.dist +++ b/dev-assets/env-files/env.docker.dist @@ -14,6 +14,9 @@ POSTGRES_DB_NAME_MIW=miw POSTGRES_USERNAME_MIW=miw_user POSTGRES_PASSWORD_MIW= +# Docker: pgAdmin config +PGADMIN_DEFAULT_EMAIL=pg@admin.com + # Docker: Keycloak config KEYCLOAK_MIW_PUBLIC_CLIENT=miw_public DB_DATABASE=keycloak @@ -45,5 +48,6 @@ DB_USER=${POSTGRES_USER} DB_NAME=${POSTGRES_DB_NAME_MIW} DB_USER_NAME=${POSTGRES_USERNAME_MIW} DB_PASSWORD=${POSTGRES_PASSWORD_MIW} +PGADMIN_DEFAULT_PASSWORD=${POSTGRES_PASSWORD} ORG_GRADLE_PROJECT_githubUserName=${GITHUB_USERNAME} ORG_GRADLE_PROJECT_githubToken=${GITHUB_TOKEN} diff --git a/dev-assets/env-files/env.local.dist b/dev-assets/env-files/env.local.dist index 039992bbf..3f9459316 100644 --- a/dev-assets/env-files/env.local.dist +++ b/dev-assets/env-files/env.local.dist @@ -14,6 +14,9 @@ POSTGRES_DB_NAME_MIW=miw POSTGRES_USERNAME_MIW=miw_user POSTGRES_PASSWORD_MIW= +# Docker: pgAdmin config +PGADMIN_DEFAULT_EMAIL=pg@admin.com + # Docker: Keycloak config KEYCLOAK_MIW_PUBLIC_CLIENT=miw_public DB_DATABASE=keycloak @@ -45,5 +48,6 @@ DB_USER=${POSTGRES_USER} DB_NAME=${POSTGRES_DB_NAME_MIW} DB_USER_NAME=${POSTGRES_USERNAME_MIW} DB_PASSWORD=${POSTGRES_PASSWORD_MIW} +PGADMIN_DEFAULT_PASSWORD=${POSTGRES_PASSWORD} ORG_GRADLE_PROJECT_githubUserName=${GITHUB_USERNAME} ORG_GRADLE_PROJECT_githubToken=${GITHUB_TOKEN} diff --git a/dev-assets/tasks/darwin/docker.yaml b/dev-assets/tasks/darwin/docker.yaml index cd3fa1fd5..a7af6cbf2 100644 --- a/dev-assets/tasks/darwin/docker.yaml +++ b/dev-assets/tasks/darwin/docker.yaml @@ -32,9 +32,10 @@ tasks: ignore_error: true vars: OPTIONS: '{{ default "" .OPTIONS }}' - CONTAINERS: '{{ default "postgres keycloak" .CONTAINERS }}' + CONTAINERS: '{{ default "postgres keycloak pgadmin" .CONTAINERS }}' cmds: - cat postgres/db.sh.tpl | envsubst > postgres/db.sh + - cat pgAdmin/servers.json.tpl | envsubst > pgAdmin/servers.json - chmod +x postgres/db.sh - "docker compose up {{.OPTIONS}} {{.CONTAINERS}}" @@ -43,9 +44,10 @@ tasks: dir: dev-assets/docker-environment cmds: - docker compose down - - cmd: docker volume remove docker-environment_postgres_data + - cmd: docker volume remove docker-environment_postgres_data docker-environment_pgadmin_data ignore_error: true - rm -f postgres/db.sh + - rm -f pgAdmin/servers.json start-app: desc: Run the app in a container environment (including middleware aka Postgresql and Keycloak) diff --git a/dev-assets/tasks/linux/docker.yaml b/dev-assets/tasks/linux/docker.yaml index cd3fa1fd5..a7af6cbf2 100644 --- a/dev-assets/tasks/linux/docker.yaml +++ b/dev-assets/tasks/linux/docker.yaml @@ -32,9 +32,10 @@ tasks: ignore_error: true vars: OPTIONS: '{{ default "" .OPTIONS }}' - CONTAINERS: '{{ default "postgres keycloak" .CONTAINERS }}' + CONTAINERS: '{{ default "postgres keycloak pgadmin" .CONTAINERS }}' cmds: - cat postgres/db.sh.tpl | envsubst > postgres/db.sh + - cat pgAdmin/servers.json.tpl | envsubst > pgAdmin/servers.json - chmod +x postgres/db.sh - "docker compose up {{.OPTIONS}} {{.CONTAINERS}}" @@ -43,9 +44,10 @@ tasks: dir: dev-assets/docker-environment cmds: - docker compose down - - cmd: docker volume remove docker-environment_postgres_data + - cmd: docker volume remove docker-environment_postgres_data docker-environment_pgadmin_data ignore_error: true - rm -f postgres/db.sh + - rm -f pgAdmin/servers.json start-app: desc: Run the app in a container environment (including middleware aka Postgresql and Keycloak)