Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add Disclaimer and update version (#7)
Browse files Browse the repository at this point in the history
Update to latest PG 15

Signed-off-by: Bill Maxwell <[email protected]>
  • Loading branch information
cloudnautique authored Jan 17, 2024
1 parent 2588b65 commit 019f965
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 66 deletions.
103 changes: 51 additions & 52 deletions Acornfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,79 @@ info: localData.info
icon: "./icon.png"

args: {
// Name of the default database
dbName: "postgres"
// Name of the default database
dbName: "postgres"

// Name of the default user
dbUser: "postgres"
// Name of the default user
dbUser: "postgres"
}

services: db: {
default: true
container: "postgres"
secrets: ["admin"]
ports: "5432"
secrets: ["admin"]
ports: "5432"
data: dbName: args.dbName
}

containers: {
postgres: {
name: "Postgres"
description: "Container running a Postgres server"
image: "postgres:15.3-alpine3.18"
env: {
PGDATA: "/var/lib/postgresql/data/db"
POSTGRES_DB: args.dbName
POSTGRES_USER: "secret://admin/username"
POSTGRES_PASSWORD: "secret://admin/password"
}
dirs: {
"/var/lib/postgresql/data": "volume://db-data"
}
probes: [
{
type: "liveness"
initialDelaySeconds: 10
exec: command: localData.livenessProbeCommand
},
{
type: "readiness"
initialDelaySeconds: 5
exec: command: localData.readinessProbeCommand
},
]
}
postgres: {
name: "Postgres"
description: "Container running a Postgres server"
image: "postgres:15.5-alpine3.18"
env: {
PGDATA: "/var/lib/postgresql/data/db"
POSTGRES_DB: args.dbName
POSTGRES_USER: "secret://admin/username"
POSTGRES_PASSWORD: "secret://admin/password"
}
dirs: {
"/var/lib/postgresql/data": "volume://db-data"
}
probes: [
{
type: "liveness"
initialDelaySeconds: 10
exec: command: localData.livenessProbeCommand
},
{
type: "readiness"
initialDelaySeconds: 5
exec: command: localData.readinessProbeCommand
},
]
}
}

volumes: {
"db-data": {}
"db-data": {}
}

secrets: {
admin: {
name: "credentials of the admin user"
type: "basic"
params: {
passwordLength: 10
passwordCharacters: "A-Za-z0-9"
}
data: {
username: std.ifelse(args.dbUser != "", args.dbUser, "")
password: ""
}
}
admin: {
name: "credentials of the admin user"
type: "basic"
params: {
passwordLength: 10
passwordCharacters: "A-Za-z0-9"
}
data: {
username: std.ifelse(args.dbUser != "", args.dbUser, "")
password: ""
}
}
}

localData: readinessProbeCommand: [
"bash",
"-c",
"PGPASSWORD=\"${POSTGRES_PASSWORD}\" psql -U \"${POSTGRES_USER}\" -d \"${POSTGRES_DB}\" -c 'SELECT 1'"
"bash",
"-c",
"PGPASSWORD=\"${POSTGRES_PASSWORD}\" psql -U \"${POSTGRES_USER}\" -d \"${POSTGRES_DB}\" -c 'SELECT 1'",
]

localData: livenessProbeCommand: [
"bash",
"-c",
"PGPASSWORD=\"${POSTGRES_PASSWORD}\" pg_isready -U \"${POSTGRES_USER}\" -d \"${POSTGRES_DB}\""
"bash",
"-c",
"PGPASSWORD=\"${POSTGRES_PASSWORD}\" pg_isready -U \"${POSTGRES_USER}\" -d \"${POSTGRES_DB}\"",
]

localData: info: """
Expand All @@ -98,4 +98,3 @@ localData: info: """
}
}
"""

35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ PostgreSQL is an open-source object-relational database system that uses and ext
This Acorn provides a Postgres database as an Acorn Service. It can be used to easily get a Postgres database for your application during development. The current service runs a single Postgres container backed by a persistent volume and define credentials for an admin user.

This Postgres instance:

- is backed by a persistent volume
- generate credentials for an admin user

The Acorn image of this service is hosted in GitHub container registry at [ghcr.io/acorn-io/postgres](ghcr.io/acorn-io/postgres).
The Acorn image of this service is hosted in GitHub container registry at [ghcr.io/acorn-io/postgres](ghcr.io/acorn-io/postgres).

Currently this Acorn has the following configuration options:

- *dbName*: name of the database (*postgres* by default)
- *dbUser*: name of the admin user (*postgres* by default)

## Usage

The [examples folder](https://github.com/acorn-io/postgres/tree/main/examples) contains a sample application using this Service. This app consists in a Python backend based on the FastAPI library, it displays a web page indicating the number of times the application was called, a counter is saved in the underlying Postgres database and incremented with each request. The screenshot below shows the UI of the example application.
The [examples folder](https://github.com/acorn-io/postgres/tree/main/examples) contains a sample application using this Service. This app consists in a Python backend based on the FastAPI library, it displays a web page indicating the number of times the application was called, a counter is saved in the underlying Postgres database and incremented with each request. The screenshot below shows the UI of the example application.

![UI](./examples/images/ui.png)

Expand All @@ -32,22 +34,23 @@ Next we define the application container:

```
containers: app: {
build: {
context: "."
target: "dev"
}
consumes: ["db"]
ports: publish: "8000/http"
env: {
POSTGRES_HOST: "@{service.db.address}"
POSTGRES_DB: "@{service.db.data.dbName}"
POSTGRES_USER: "@{service.db.secrets.admin.username}"
POSTGRES_PASSWORD: "@{service.db.secrets.admin.password}"
}
build: {
context: "."
target: "dev"
}
consumes: ["db"]
ports: publish: "8000/http"
env: {
POSTGRES_HOST: "@{service.db.address}"
POSTGRES_DB: "@{service.db.data.dbName}"
POSTGRES_USER: "@{service.db.secrets.admin.username}"
POSTGRES_PASSWORD: "@{service.db.secrets.admin.password}"
}
}
```

This container is built using the Dockerfile in the examples folder. Once built, the container consumes the Postgres service using properties provided by the service:

- @{service.db.address} : URL to connect to the postgres service
- @{service.db.data.dbName}: database name
- @{service.db.secrets.admin.username}: username of the admin user
Expand All @@ -74,3 +77,7 @@ Instead of managing your own Acorn installation, you can deploy this application
[![Run in Acorn](https://acorn.io/v1-ui/run/badge?image=ghcr.io+acorn-io+postgres+examples:v%23.%23-%23)](https://acorn.io/run/ghcr.io/acorn-io/postgres/examples:v%23.%23-%23)

An application running in the Sandbox will automatically shut down after 2 hours, but you can use the Acorn Pro plan to remove the time limit and gain additional functionalities.

## Disclaimer

Disclaimer: You agree all software products on this site, including Acorns or their contents, may contain projects and materials subject to intellectual property restrictions and/or Open-Source license (“Restricted Items”). Restricted Items found anywhere within this Acorn or on Acorn.io are provided “as-is” without warranty of any kind and are subject to their own Open-Source licenses and your compliance with such licenses are solely and exclusively your responsibility. [PostgreSQL](https://www.postgresql.org) is licensed under PostgreSQL License which can be found [here](https://opensource.org/license/postgresql/) and Acorn.io does not endorse and is not affiliated with PostgreSQL. By using Acorn.io you agree to our general disclaimer here: <https://www.acorn.io/terms-of-use>.

0 comments on commit 019f965

Please sign in to comment.