Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Commit a601445

Browse files
committed
Merge branch 'develop'
2 parents 891a9ce + 6e8da3a commit a601445

12 files changed

Lines changed: 143 additions & 18 deletions

File tree

src/database/database_flow.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ setup_database_docker_compose_dev() {
77
perl -i -ne 'print unless /~~~database creation and migration~~~/;' "${project_root_dir}/start.sh"
88
;;
99
"pgsql" )
10+
projectinit_compose_has_root_volumes=1
1011
# shellcheck source=pgsql/container/docker/v1/pqsql.sh
1112
source "${tool_dir}/src/database/pgsql/container/docker/v1/pqsql.sh"
1213
setup_pgsql_docker_compose_dev
14+
setup_pgsql_dev_dockerfile
1315
;;
1416
"mysql" )
1517
projectinit_compose_has_root_volumes=1
@@ -58,6 +60,7 @@ setup_database_docker_compose_prod() {
5860
# shellcheck source=pgsql/container/docker/v1/pqsql.sh
5961
source "${tool_dir}/src/database/pgsql/container/docker/v1/pqsql.sh"
6062
setup_pgsql_docker_compose_prod
63+
setup_pgsql_prod_dockerfile
6164
;;
6265
"mysql" )
6366
# shellcheck source=../database/mysql/v1/mysql.sh

src/database/mariadb/v1/template/documentation/docker/implemented_configuration.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The following configuration has been implemented by ProjectInit:
44

55
* Database credentials as Docker compose secrets.
66
* Docker volume is used for persisting data on the host.
7-
* Healthcheck is implemented in Docker Compose.
7+
* Healthcheck is implemented directly in the Docker image (custom Dockerfile).
88
* Custom `my.cnf` MariaDB configuration file and directory are prepared.
99
1010
=== Configuration files
@@ -50,13 +50,13 @@ Resources:
5050

5151
=== Healthcheck
5252

53-
Official MariaDB healthcheck script is implemented in Docker Compose. It makes sure that the MariaDB container is up
53+
Basic healthcheck mechanism has been implemented in the custom Dockerfile. It makes sure that the database service is up
5454
before allowing your application to run.
5555

5656
Resources:
5757

5858
* link:https://mariadb.com/kb/en/using-healthcheck-sh/[`healthcheck.sh` Official MariaDB documentation]
59-
* link:https://docs.docker.com/reference/compose-file/services/#healthcheck[Healthcheck Docker service property]
59+
* link:https://docs.docker.com/reference/dockerfile/#healthcheck[Healthcheck in Dockerfile]
6060

6161
=== Custom MariaDB configuration
6262

src/database/mysql/v1/template/documentation/docker/implemented_configuration.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The following configuration has been implemented by ProjectInit:
44

55
* Database credentials as Docker compose secrets.
66
* Docker volume is used for persisting data on the host.
7-
* Healthcheck is implemented in Docker Compose.
7+
* Healthcheck is implemented directly in the Docker image (custom Dockerfile).
88
* Custom `my.cnf` MySQL configuration file and directory are prepared.
99
1010
=== Configuration files
@@ -50,12 +50,12 @@ Resources:
5050

5151
=== Healthcheck
5252

53-
Basic healthcheck mechanism has been implemented in Docker Compose. It makes sure that the MySQL container is up before
54-
allowing your application to run.
53+
Basic healthcheck mechanism has been implemented in the custom Dockerfile. It makes sure that the database service is up
54+
before allowing your application to run.
5555

5656
Resources:
5757

58-
* link:https://docs.docker.com/reference/compose-file/services/#healthcheck[Healthcheck Docker service property]
58+
* link:https://docs.docker.com/reference/dockerfile/#healthcheck[Healthcheck in Dockerfile]
5959

6060
=== Custom MySQL configuration
6161

src/database/percona/v1/template/documentation/docker/implemented_configuration.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The following configuration has been implemented by ProjectInit:
44

55
* Database credentials as Docker compose secrets.
66
* Docker volume is used for persisting data on the host.
7-
* Healthcheck is implemented in Docker Compose.
7+
* Healthcheck is implemented directly in the Docker image (custom Dockerfile).
88
* Custom `my.cnf` MySQL configuration file and directory are prepared.
99
* Default authentication is set to non-deprecated `caching_sha2_password` method for both MySQL daemon and client.
1010
* Percona telemetry is disabled.
@@ -52,12 +52,12 @@ Resources:
5252

5353
=== Healthcheck
5454

55-
Basic healthcheck mechanism has been implemented in Docker Compose. It makes sure that the Percona MySQL container is
56-
up before allowing your application to run.
55+
Basic healthcheck mechanism has been implemented in the custom Dockerfile. It makes sure that the database service is up
56+
before allowing your application to run.
5757

5858
Resources:
5959

60-
* link:https://docs.docker.com/reference/compose-file/services/#healthcheck[Healthcheck Docker service property]
60+
* link:https://docs.docker.com/reference/dockerfile/#healthcheck[Healthcheck in Dockerfile]
6161

6262
=== Custom MySQL configuration
6363

src/database/pgsql/container/docker/v1/pqsql.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ setup_pgsql_docker_compose_dev() {
77
perl -pi -e "s/~~~database service~~~/$(<"${tool_dir}/src/database/pgsql/container/docker/v1/template/dev" perl -pe 's/([\/\& \t])/\\$1/g')/g" "${target_file}"
88
perl -pi -e "s/~~~database service name~~~/${projectinit_database_service_name}/g" "${target_file}"
99
perl -pi -e "s/~~~database container name~~~/${projectinit_database_service_name}/g" "${target_file}"
10-
perl -pi -e "s/~~~database server version~~~/${projectinit_database_version}/g" "${target_file}"
1110
perl -pi -e "s/~~~database host port~~~/${projectinit_database_host_port}/g" "${target_file}"
11+
perl -pi -e "s/~~~root volumes~~~/~~~root volumes~~~\n ${projectinit_database_service_name}_volume:/g" "${target_file}"
1212

1313
projectinit_compose_has_secrets=1
1414
mkdir -p "${project_root_dir}/compose_secrets"
@@ -32,8 +32,30 @@ setup_pgsql_docker_compose_prod() {
3232
perl -pi -e "s/~~~database service~~~/$(<"${tool_dir}/src/database/pgsql/container/docker/v1/template/prod" perl -pe 's/([\/\& \t])/\\$1/g')/g" "${target_file}"
3333
perl -pi -e "s/~~~database service name~~~/${projectinit_database_service_name}/g" "${target_file}"
3434
perl -pi -e "s/~~~database container name~~~/${projectinit_database_service_name}/g" "${target_file}"
35-
perl -pi -e "s/~~~database server version~~~/${projectinit_database_version}/g" "${target_file}"
3635
perl -pi -e "s/~~~database host port~~~/${projectinit_database_host_port}/g" "${target_file}"
36+
perl -pi -e "s/~~~root volumes~~~/~~~root volumes~~~\n ${projectinit_database_service_name}_volume:/g" "${target_file}"
3737

3838
perl -pi -e "s/~~~compose secrets~~~/$(<"${tool_dir}/src/database/pgsql/container/docker/v1/template/secrets" perl -pe 's/([\/\& \t])/\\$1/g')/g" "${target_file}"
39-
}
39+
}
40+
41+
setup_pgsql_dev_dockerfile() {
42+
local target_file
43+
target_file="${project_root_dir}/projectinit_docker/dev/pgsql/Dockerfile"
44+
if [ ! -d "${project_root_dir}/projectinit_docker/dev/pgsql" ]; then
45+
mkdir -p "${project_root_dir}/projectinit_docker/dev/pgsql"
46+
fi
47+
48+
cp -f "${tool_dir}/src/database/pgsql/container/docker/v1/template/dockerfile/dev" "${target_file}"
49+
perl -pi -e "s/~~~database server version~~~/${projectinit_database_version}/g" "${target_file}"
50+
}
51+
52+
setup_pgsql_prod_dockerfile() {
53+
local target_file
54+
target_file="${project_root_dir}/projectinit_docker/prod/pgsql/Dockerfile"
55+
if [ ! -d "${project_root_dir}/projectinit_docker/prod/pgsql" ]; then
56+
mkdir -p "${project_root_dir}/projectinit_docker/prod/pgsql"
57+
fi
58+
59+
cp -f "${tool_dir}/src/database/pgsql/container/docker/v1/template/dockerfile/prod" "${target_file}"
60+
perl -pi -e "s/~~~database server version~~~/${projectinit_database_version}/g" "${target_file}"
61+
}

src/database/pgsql/container/docker/v1/template/dev

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
~~~database service name~~~:
22
container_name: ~~~database container name~~~
3-
image: postgres:~~~database server version~~~
3+
build:
4+
context: ./
5+
dockerfile: ./projectinit_docker/dev/pgsql/Dockerfile
46
restart: always
57
environment:
68
POSTGRES_DB_FILE: /run/secrets/postgres_db
@@ -9,7 +11,7 @@
911
ports:
1012
- "~~~database host port~~~:5432"
1113
volumes:
12-
- ./database_volume:/var/lib/database/data
14+
- ~~~database service name~~~_volume:/var/lib/postgresql/data
1315
secrets:
1416
- postgres_db
1517
- postgres_user
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM postgres:~~~database server version~~~
2+
3+
HEALTHCHECK --timeout=10s --start-period=1m \
4+
CMD pg_isready \
5+
-h 127.0.0.1 \
6+
-d $(cat $POSTGRES_DB_FILE) \
7+
-U $(cat $POSTGRES_USER_FILE) \
8+
-q
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM postgres:~~~database server version~~~
2+
3+
HEALTHCHECK --timeout=10s --start-period=1m \
4+
CMD pg_isready \
5+
-h 127.0.0.1 \
6+
-d $(cat $POSTGRES_DB_FILE) \
7+
-U $(cat $POSTGRES_USER_FILE) \
8+
-q
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
== Implemented configuration
2+
3+
The following configuration has been implemented by ProjectInit:
4+
5+
* Database credentials as Docker compose secrets.
6+
* Docker volume is used for persisting data on the host.
7+
* Healthcheck is implemented directly in the Docker image (custom Dockerfile).
8+
9+
=== Configuration files
10+
11+
* Database credentials (Docker Compose secrets):
12+
** link:../../compose_secrets/postgres_db.txt[`compose_secrets/postgres_db.txt`]
13+
** link:../../compose_secrets/postgres_password.txt[`compose_secrets/postgres_password.txt`]
14+
** link:../../compose_secrets/postgres_user.txt[`compose_secrets/postgres_user.txt`]
15+
* Dockerfile:
16+
** link:../../projectinit_docker/dev/pgsql/Dockerfile[`projectinit_docker/dev/pgsql/Dockerfile`]
17+
** link:../../projectinit_docker/prod/pgsql/Dockerfile[`projectinit_docker/prod/pgsql/Dockerfile`]
18+
19+
=== Database credentials
20+
21+
Database credentials are stored as Docker Compose secrets. The secrets are available in
22+
link:../../compose_secrets[`compose_secrets`] directory of your project.
23+
24+
Resources:
25+
26+
* link:https://docs.docker.com/compose/how-tos/use-secrets/[How to use secrets in Docker Compose]
27+
28+
=== Persisting data on the host
29+
30+
Docker volume is used for persisting data on the host. This is the default method recommended in the documentation of
31+
the official Docker image. Volume file and directory permissions are managed by Docker. You are free to mount a local
32+
directory instead (bind mount), however, you will need to set up the directory, its owner (user), permissions and other
33+
security mechanisms yourself.
34+
35+
Resources:
36+
37+
* link:https://docs.docker.com/engine/storage/volumes/[Docker Volumes]
38+
* link:https://docs.docker.com/engine/storage/bind-mounts/[Docker bind mounts]
39+
40+
=== Healthcheck
41+
42+
Basic healthcheck mechanism has been implemented in the custom Dockerfile. It makes sure that the database service is up
43+
before allowing your application to run.
44+
45+
Resources:
46+
47+
* link:https://docs.docker.com/reference/dockerfile/#healthcheck[Healthcheck in Dockerfile]
48+
* link:https://www.postgresql.org/docs/current/app-pg-isready.html[`pg_isready`]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
= PostgreSQL
2+
:toc:
3+
:toclevels: 5
4+
5+
== Introduction
6+
7+
|===
8+
|Description|Link
9+
10+
|Homepage
11+
|https://www.postgresql.org/
12+
13+
|Docker Official image (used here)
14+
|https://hub.docker.com/_/postgres
15+
16+
|===
17+
18+
[IMPORTANT]
19+
====
20+
PostgreSQL server has been set up with *minimum configuration only*, so you can start working. It's up to you how you'd
21+
like to configure it for development and production.
22+
====
23+
24+
~~~implemented configuration~~~

0 commit comments

Comments
 (0)