generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Adds a Feature that installs a version of the `postgresql-client` libraries (notably, `psql`) for interacting with a PostgreSQL server. ## Commits - Formatting [skip ci] - Update metadata and README [skip ci] - Add PostgreSQL client feature
- Loading branch information
Showing
9 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# postgresql-client | ||
|
||
Install client and administrative programs for [PostgreSQL](https://www.postgresql.org). | ||
|
||
## Usage | ||
|
||
```json | ||
"features": { | ||
"ghcr.io/CargoSense/devcontainer-features/postgresql-client:1": {} | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
| Option ID | Description | Type | Default Value | | ||
|:--------------|:------------------------------------------|:-------|:--------------| | ||
| `version` | The postgresql-client version to install. | string | `os-provided` | | ||
|
||
## OS Support | ||
|
||
This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "PostgreSQL Client", | ||
"id": "postgresql-client", | ||
"version": "1.0.0", | ||
"description": "Install client and administrative programs for PostgreSQL.", | ||
"options": { | ||
"version": { | ||
"type": "string", | ||
"enum": [ | ||
"15", | ||
"16", | ||
"os-provided" | ||
], | ||
"default": "os-provided", | ||
"description": "Select or enter a PostgreSQL version." | ||
} | ||
}, | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers/features/common-utils" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
POSTGRESQL_VERSION="${VERSION:-"os-provided"}" | ||
VERSION_CODENAME="$(sed -nr 's/VERSION_CODENAME=(.+)/\1/p' /etc/os-release)" | ||
|
||
if [ "$(id -u)" -ne 0 ]; then | ||
printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' | ||
exit 1 | ||
fi | ||
|
||
if [ "${POSTGRESQL_VERSION}" = "os-provided" ]; then | ||
apt update --yes | ||
apt install --no-install-recommends --yes postgresql-client | ||
|
||
exit 0 | ||
fi | ||
|
||
curl_installed="" | ||
gpg_installed="" | ||
|
||
if ! type curl >/dev/null 2>&1; then | ||
apt update --yes | ||
apt install --no-install-recommends --yes curl ca-certificates | ||
|
||
curl_installed="true" | ||
fi | ||
|
||
if ! type gpg >/dev/null 2>&1; then | ||
apt update --yes | ||
apt install --no-install-recommends --yes gpg | ||
|
||
gpg_installed="true" | ||
fi | ||
|
||
install -d /usr/share/postgresql-common/pgdg | ||
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc | ||
sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt '${VERSION_CODENAME}'-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | ||
|
||
apt update --yes | ||
apt install --no-install-recommends --yes postgresql-client-${POSTGRESQL_VERSION} | ||
|
||
if ! [ -z $curl_installed ]; then | ||
apt purge curl --autoremove --yes | ||
fi | ||
|
||
if ! [ -z $gpg_installed ]; then | ||
apt purge gpg --autoremove --yes | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This test file will be executed against an auto-generated devcontainer.json that | ||
# includes the 'postgresql-client' Feature with no options. | ||
# | ||
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md | ||
# | ||
# Eg: | ||
# { | ||
# "image": "<..some-base-image...>", | ||
# "features": { | ||
# "postgresql-client": {} | ||
# }, | ||
# "remoteUser": "root" | ||
# } | ||
# | ||
# Thus, the value of all options will fall back to the default value in the | ||
# Feature's 'devcontainer-feature.json'. | ||
# | ||
# These scripts are run as 'root' by default. Although that can be changed | ||
# with the '--remote-user' flag. | ||
# | ||
# This test can be run with the following command: | ||
# | ||
# devcontainer features test \ | ||
# --features postgresql-client \ | ||
# --remote-user root \ | ||
# --skip-scenarios \ | ||
# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ | ||
# /path/to/this/repo | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib | ||
# Provides the 'check' and 'reportResults' commands. | ||
source dev-container-features-test-lib | ||
|
||
# Feature-specific tests | ||
# The 'check' command comes from the dev-container-features-test-lib. Syntax is... | ||
# check <LABEL> <cmd> [args...] | ||
check "version" bash -c "psql --version | grep -E 'psql \(PostgreSQL\) 15\..+'" | ||
|
||
# Report result | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"postgresql-client-15": { | ||
"image": "debian:latest", | ||
"features": { | ||
"postgresql-client": { | ||
"version": "15" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This test file will be executed against an auto-generated devcontainer.json that | ||
# includes the 'postgresql-client' Feature with no options. | ||
# | ||
# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md | ||
# | ||
# Eg: | ||
# { | ||
# "image": "<..some-base-image...>", | ||
# "features": { | ||
# "postgresql-client": {} | ||
# }, | ||
# "remoteUser": "root" | ||
# } | ||
# | ||
# Thus, the value of all options will fall back to the default value in the | ||
# Feature's 'devcontainer-feature.json'. | ||
# | ||
# These scripts are run as 'root' by default. Although that can be changed | ||
# with the '--remote-user' flag. | ||
# | ||
# This test can be run with the following command: | ||
# | ||
# devcontainer features test \ | ||
# --features postgresql-client \ | ||
# --remote-user root \ | ||
# --skip-scenarios \ | ||
# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ | ||
# /path/to/this/repo | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib | ||
# Provides the 'check' and 'reportResults' commands. | ||
source dev-container-features-test-lib | ||
|
||
# Feature-specific tests | ||
# The 'check' command comes from the dev-container-features-test-lib. Syntax is... | ||
# check <LABEL> <cmd> [args...] | ||
check "version" psql --version | ||
check "which psql" bash -c "which psql | grep /usr/bin/psql" | ||
|
||
# Report result | ||
# If any of the checks above exited with a non-zero exit code, the test will fail. | ||
reportResults |