Merge ~ubuntu-docker-images/ubuntu-docker-images/+git/templates:postgresql into ~ubuntu-docker-images/ubuntu-docker-images/+git/templates:master

Proposed by Sergio Durigan Junior
Status: Merged
Merged at revision: 7baf5b4b17c88fa34c73f9f35b188b6cc39bbcdb
Proposed branch: ~ubuntu-docker-images/ubuntu-docker-images/+git/templates:postgresql
Merge into: ~ubuntu-docker-images/ubuntu-docker-images/+git/templates:master
Diff against target: 191 lines (+179/-0)
2 files modified
data/postgres.yaml (+73/-0)
out/postgres.md (+106/-0)
Reviewer Review Type Date Requested Status
Valentin Viennot (community) Needs Fixing
Richard Harding Pending
Lucas Kanashiro Pending
Canonical Server Pending
Review via email: mp+394276@code.launchpad.net

Description of the change

Postgres data (needed to generate the README file) and the corresponding postgres.md (generated from the data).

To post a comment you must log in.
Revision history for this message
Valentin Viennot (valentinviennot) wrote :

there's a tiny mistake in the run command

review: Needs Fixing
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

On Saturday, November 21 2020, Valentin Viennot wrote:

> Review: Needs Fixing
>
> there's a tiny mistake in the run command

Thanks, I fixed the mistake and merged the MP.

--
Sergio
GPG key ID: E92F D0B3 6B14 F1F4 D8E0 EB2F 106D A1C8 C3CB BF14

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/data/postgres.yaml b/data/postgres.yaml
2new file mode 100644
3index 0000000..621d565
4--- /dev/null
5+++ b/data/postgres.yaml
6@@ -0,0 +1,73 @@
7+application: Postgres
8+repo: postgres
9+description: >
10+ PostgreSQL is a powerful, open source object-relational database system. It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages). It includes most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP. It also supports storage of binary large objects, including pictures, sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others, and exceptional documentation. Read more on the [PostgreSQL website](https://www.postgresql.org/docs/).
11+version: "12.4"
12+base: Ubuntu 20.04 LTS
13+architectures:
14+ - amd64
15+ - arm64
16+ - s390x
17+docker:
18+ parameters:
19+ - -p 30432:5432
20+ - -e POSTGRES_PASSWORD=My:s3Cr3t/
21+ access: Access your Redis server at `localhost:30432`.
22+parameters:
23+ - type: -e
24+ value: TZ=UTC
25+ description: Timezone.
26+ - type: -e
27+ value: POSTGRES_PASSWORD=secret
28+ description: Set the password for the superuser which is `postgres` by default. Bear in mind that to connect to the database in the same host the password is not needed but to access it via an external host (for instance another container) the password is needed. This option is **mandatory** and **must not be empty**.
29+ - type: -e
30+ value: POSTGRES_USER=john
31+ description: Create a new user with superuser privileges. This is used in conjunction with `POSTGRES_PASSWORD`.
32+ - type: -e
33+ value: POSTGRES_DB=db_test
34+ description: Set the name of the default database.
35+ - type: -e
36+ value: POSTGRES_INITDB_ARGS="--data-checksums"
37+ description: Pass arguments to the `postgres initdb` call.
38+ - type: -e
39+ value: POSTGRES_INITDB_WALDIR=/path/to/location
40+ description: Set the location of the Postgres transaction log. By default it is stored in a subdirectory of the main Postgres data folder (`PGDATA`).
41+ - type: -e
42+ value: POSTGRES_HOST_AUTH_METHOD=trust
43+ description: "Set the `auth-method` for `host` connections for `all` databases, `all` users, and `all` addresses. The following will be added to the `pg_hba.conf` if this option is passed: `host all all all $POSTGRES_HOST_AUTH_METHOD`."
44+ - type: -e
45+ value: PGDATA=/path/to/location
46+ description: Set the location of the database files. The default is `/var/lib/postgresql/data`.
47+ - type: -p
48+ value: 30432:5432
49+ description: Expose Postgres on `localhost:30432`.
50+ - type: -v
51+ value: /path/to/postgresql.conf:/etc/postgresql/postgresql.conf
52+ description: Local [configuration file](https://www.postgresql.org/docs/12/index.html) `postgresql.conf` (try [this example](https://git.launchpad.net/~canonical-server/ubuntu-docker-images/+git/postgresql/plain/examples/config/postgresql.conf)).
53+ - type: -v
54+ value: /path/to/persisted/data:/var/lib/postgresql/data
55+ description: Persist data instead of initializing a new database every time you launch a new container.
56+debug:
57+ extraparagraph: |
58+ #### Initialization Scripts
59+
60+ One can also add initialization scripts to their containers. This includes `*.sql`, `.sql.gz`, and `*.sh` scripts, and you just need to put them inside the `/docker-entrypoint-initdb.d` directory inside the container. After Postgres initialization is done and the default database and user are created, the scripts are executed in the following order:
61+
62+ * Run any `*.sql` files in alphabetically order. It will be executed with `POSTGRES_USER`.
63+ * Run any executable `*.sh` scripts in alphabetically order.
64+ * Source any non-executable `*.sh` scripts in alphabetically order.
65+
66+ All of this is done before the Postgres service is started. Keep in mind if your `PGDATA` directory is not empty (contains pre-existing database) they will be left untouched.
67+ network:
68+ client: psql
69+ args: -h postgres-container -U postgres
70+ helper: The password will be asked and you can enter `My:s3Cr3t/`. Now, you are logged in and can enjoy your new instance.
71+microk8s:
72+ configmap:
73+ files:
74+ - key: main-config
75+ name: postgresql.conf
76+ link: https://git.launchpad.net/~canonical-server/ubuntu-docker-images/+git/postgresql/plain/examples/config/postgresql.conf
77+ deploy:
78+ link: https://git.launchpad.net/~canonical-server/ubuntu-docker-images/+git/postgresql/plain/examples/postgres-deployment.yml
79+ access: You will now be able to connect to the Postgres server on `localhost:30306`.
80diff --git a/out/postgres.md b/out/postgres.md
81new file mode 100644
82index 0000000..1c2a674
83--- /dev/null
84+++ b/out/postgres.md
85@@ -0,0 +1,106 @@
86+# Postgres | Ubuntu
87+
88+
89+## About Postgres
90+
91+PostgreSQL is a powerful, open source object-relational database system. It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages). It includes most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP. It also supports storage of binary large objects, including pictures, sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others, and exceptional documentation. Read more on the [PostgreSQL website](https://www.postgresql.org/docs/).
92+
93+
94+## Tags and Architectures
95+
96+
97+| Tag | Currently | Architectures |
98+|---|---|---|
99+| `12.x`    ![BETA](https://assets.ubuntu.com/v1/e8ac33d1-header-beta-flag.svg) | Postgres 12.4 on Ubuntu 20.04 LTS | `amd64`, `arm64`, `s390x` |
100+
101+## Usage
102+
103+Launch this image locally:
104+
105+```sh
106+docker run -d --name postgres-container -e TZ=UTC -p 30432:5432 -e POSTGRES_PASSWORD=My:s3Cr3t/ ubuntu/postgres:12.x
107+```
108+
109+Access your Redis server at `localhost:30432`.
110+
111+#### Parameters
112+
113+| Parameter | Description |
114+|---|---|
115+| `-e TZ=UTC` | Timezone. |
116+| `-e POSTGRES_PASSWORD=secret` | Set the password for the superuser which is `postgres` by default. Bear in mind that to connect to the database in the same host the password is not needed but to access it via an external host (for instance another container) the password is needed. This option is **mandatory** and **must not be empty**. |
117+| `-e POSTGRES_USER=john` | Create a new user with superuser privileges. This is used in conjunction with `POSTGRES_PASSWORD`. |
118+| `-e POSTGRES_DB=db_test` | Set the name of the default database. |
119+| `-e POSTGRES_INITDB_ARGS="--data-checksums"` | Pass arguments to the `postgres initdb` call. |
120+| `-e POSTGRES_INITDB_WALDIR=/path/to/location` | Set the location of the Postgres transaction log. By default it is stored in a subdirectory of the main Postgres data folder (`PGDATA`). |
121+| `-e POSTGRES_HOST_AUTH_METHOD=trust` | Set the `auth-method` for `host` connections for `all` databases, `all` users, and `all` addresses. The following will be added to the `pg_hba.conf` if this option is passed: `host all all all $POSTGRES_HOST_AUTH_METHOD`. |
122+| `-e PGDATA=/path/to/location` | Set the location of the database files. The default is `/var/lib/postgresql/data`. |
123+| `-p 30432:5432` | Expose Postgres on `localhost:30432`. |
124+| `-v /path/to/postgresql.conf:/etc/postgresql/postgresql.conf` | Local [configuration file](https://www.postgresql.org/docs/12/index.html) `postgresql.conf` (try [this example](https://git.launchpad.net/~canonical-server/ubuntu-docker-images/+git/postgresql/plain/examples/config/postgresql.conf)). |
125+| `-v /path/to/persisted/data:/var/lib/postgresql/data` | Persist data instead of initializing a new database every time you launch a new container. |
126+
127+#### Initialization Scripts
128+
129+One can also add initialization scripts to their containers. This includes `*.sql`, `.sql.gz`, and `*.sh` scripts, and you just need to put them inside the `/docker-entrypoint-initdb.d` directory inside the container. After Postgres initialization is done and the default database and user are created, the scripts are executed in the following order:
130+
131+* Run any `*.sql` files in alphabetically order. It will be executed with `POSTGRES_USER`.
132+* Run any executable `*.sh` scripts in alphabetically order.
133+* Source any non-executable `*.sh` scripts in alphabetically order.
134+
135+All of this is done before the Postgres service is started. Keep in mind if your `PGDATA` directory is not empty (contains pre-existing database) they will be left untouched.
136+
137+
138+#### Testing/Debugging
139+
140+To debug the container:
141+
142+```sh
143+$ docker logs -f postgres-container
144+```
145+
146+To get an interactive shell:
147+
148+```sh
149+$ docker exec -it postgres-container /bin/bash
150+```
151+
152+This image also includes the `psql` client for interactive container use:
153+
154+```sh
155+$ docker network create postgres-network
156+$ docker network connect postgres-network postgres-container
157+$ docker run -it --rm --network postgres-network ubuntu/postgres:12.x psql -h postgres-container -U postgres
158+```
159+
160+The password will be asked and you can enter `My:s3Cr3t/`. Now, you are logged in and can enjoy your new instance.
161+
162+## Deploy with Kubernetes
163+
164+
165+
166+Works with any Kubernetes; if you don't have one, we recommend you [install MicroK8s](https://microk8s.io/) and `microk8s enable dns storage` then alias `kubectl` to `microk8s.kubectl`.
167+
168+Download
169+[postgresql.conf](https://git.launchpad.net/~canonical-server/ubuntu-docker-images/+git/postgresql/plain/examples/config/postgresql.conf), and
170+[postgres-deployment.yml](https://git.launchpad.net/~canonical-server/ubuntu-docker-images/+git/postgresql/plain/examples/postgres-deployment.yml). Then:
171+
172+```sh
173+$ kubectl create configmap postgres-config --from-file=main-config=postgresql.conf
174+$ kubectl apply -f postgres-deployment.yml
175+```
176+
177+You will now be able to connect to the Postgres server on `localhost:30306`.
178+
179+## Bugs and feature requests
180+
181+If you find a bug in our image or want to request a specific feature, please file a bug here:
182+
183+[https://bugs.launchpad.net/ubuntu-docker-images/+filebug](https://bugs.launchpad.net/ubuntu-docker-images/+filebug)
184+
185+Please title the bug "`postgres: <reason>`".
186+
187+Make sure to include the digest of the image you are using, from:
188+```sh
189+$ docker images --no-trunc --quiet ubuntu/postgres:<tag>
190+```
191+

Subscribers

People subscribed via source and target branches

to all changes: