-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
337 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM mcr.microsoft.com/devcontainers/java:21 | ||
|
||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get -y install --no-install-recommends libpq-dev |
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,12 @@ | ||
{ | ||
"dockerComposeFile": "docker-compose.yml", | ||
"service": "app", | ||
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", | ||
"features": { | ||
"ghcr.io/devcontainers/features/sshd:1": {} | ||
}, | ||
|
||
"forwardPorts": [ | ||
5432 | ||
] | ||
} |
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,38 @@ | ||
version: '3.8' | ||
|
||
services: | ||
app: | ||
container_name: javadev | ||
# https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native | ||
platform: "linux/amd64" | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
environment: | ||
POSTGRES_HOSTNAME: postgresdb | ||
POSTGRES_DB: postgres | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
|
||
volumes: | ||
- ../..:/workspaces:cached | ||
|
||
command: sleep infinity | ||
|
||
network_mode: service:db | ||
|
||
db: | ||
container_name: postgresdb | ||
image: postgres:latest | ||
restart: unless-stopped | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready" ] | ||
interval: 1s | ||
timeout: 5s | ||
retries: 10 | ||
environment: | ||
POSTGRES_DB: postgres | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
ports: | ||
- "5432:5432" |
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,138 @@ | ||
name: Setup PostgreSQL for Linux/macOS/Windows | ||
author: Ihor Kalnytskyi | ||
description: Setup a preinstalled PostgreSQL server. | ||
branding: | ||
icon: database | ||
color: purple | ||
inputs: | ||
username: | ||
description: The username of the user to setup. | ||
default: postgres | ||
required: false | ||
password: | ||
description: The password of the user to setup. | ||
default: postgres | ||
required: false | ||
database: | ||
description: The database name to setup and grant permissions to created user. | ||
default: postgres | ||
required: false | ||
port: | ||
description: The server port to listen on. | ||
default: "5432" | ||
required: false | ||
outputs: | ||
connection-uri: | ||
description: The connection URI to connect to PostgreSQL. | ||
value: ${{ steps.set-outputs.outputs.connection-uri }} | ||
service-name: | ||
description: The service name with connection parameters. | ||
value: ${{ steps.set-outputs.outputs.service-name }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Prerequisites | ||
run: | | ||
if [ "$RUNNER_OS" == "Linux" ]; then | ||
echo "$(pg_config --bindir)" >> $GITHUB_PATH | ||
elif [ "$RUNNER_OS" == "Windows" ]; then | ||
echo "$PGBIN" >> $GITHUB_PATH | ||
echo "PQ_LIB_DIR=$PGROOT\lib" >> $GITHUB_ENV | ||
# The Windows runner has some PostgreSQL environment variables set | ||
# that may confuse users since they may be irrelevant to the | ||
# PostgreSQL server we're using. | ||
for name in "PGROOT" "PGDATA" "PGBIN" "PGUSER" "PGPASSWORD"; do | ||
echo "$name=" >> $GITHUB_ENV | ||
done | ||
elif [ "$RUNNER_OS" == "macOS" ]; then | ||
case "$(sw_vers -productVersion)" in | ||
12.*|13.*) | ||
brew install postgresql@14 | ||
echo "/usr/local/opt/postgresql@14/bin" >> $GITHUB_PATH | ||
;; | ||
14.*) | ||
brew install postgresql@16 | ||
echo "/opt/homebrew/opt/postgresql@16/bin" >> $GITHUB_PATH | ||
;; | ||
esac | ||
fi | ||
shell: bash | ||
|
||
- name: Setup and start PostgreSQL | ||
run: | | ||
export PGDATA="$RUNNER_TEMP/pgdata" | ||
export PWFILE="$RUNNER_TEMP/pwfile" | ||
# Unfortunately 'initdb' could only receive a password via file on disk | ||
# or prompt to enter on. Prompting is not an option since we're running | ||
# in non-interactive mode. | ||
echo '${{ inputs.password }}' > $PWFILE | ||
# There are couple of reasons why we need to create a new PostgreSQL | ||
# database cluster. First and foremost, we have to create a superuser | ||
# with provided credentials. Second, we want the PostgreSQL client | ||
# applications [1] to be available for execution without | ||
# run-from-another-user dances. Third, we want to make sure that | ||
# settings are the same between operating systems and aren't changed by | ||
# package vendors. | ||
# | ||
# [1] https://www.postgresql.org/docs/15/reference-client.html | ||
initdb \ | ||
--username="${{ inputs.username }}" \ | ||
--pwfile="$PWFILE" \ | ||
--auth="scram-sha-256" \ | ||
--encoding="UTF-8" \ | ||
--locale="en_US.UTF-8" \ | ||
--no-instructions | ||
# Do not create unix sockets since they are created by default in the | ||
# directory we have no permissions to (owned by system postgres user). | ||
echo "unix_socket_directories = ''" >> "$PGDATA/postgresql.conf" | ||
echo "port = ${{ inputs.port }}" >> "$PGDATA/postgresql.conf" | ||
pg_ctl start | ||
# Save required connection parameters for created superuser to the | ||
# connection service file [1]. This allows using these connection | ||
# parameters by setting 'PGSERVICE' environment variable or by | ||
# requesting them via connection string. | ||
# | ||
# HOST is required for Linux/macOS because these OS-es default to unix | ||
# sockets but we turned them off. | ||
# | ||
# PORT, USER, PASSWORD and DBNAME are required because they could be | ||
# parametrized via action input parameters. | ||
# | ||
# [1] https://www.postgresql.org/docs/15/libpq-pgservice.html | ||
cat <<EOF > "$PGDATA/pg_service.conf" | ||
[${{ inputs.username }}] | ||
host=localhost | ||
port=${{ inputs.port }} | ||
user=${{ inputs.username }} | ||
password=${{ inputs.password }} | ||
dbname=${{ inputs.database }} | ||
EOF | ||
echo "PGSERVICEFILE=$PGDATA/pg_service.conf" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: Setup PostgreSQL database | ||
run: | | ||
# The 'postgres' database is a pre-created database meant for use by | ||
# users, utilities and third party applications. There's no way to | ||
# parametrize the name, so all we can do is to avoid creating a | ||
# database if provided name is 'postgres'. | ||
if [ "${{ inputs.database }}" != "postgres" ]; then | ||
createdb -O "${{ inputs.username }}" "${{ inputs.database }}" | ||
fi | ||
env: | ||
PGSERVICE: ${{ inputs.username }} | ||
shell: bash | ||
|
||
- name: Set action outputs | ||
run: | | ||
CONNECTION_URI="postgresql://${{ inputs.username }}:${{ inputs.password }}@localhost:${{ inputs.port }}/${{ inputs.database }}" | ||
echo "connection-uri=$CONNECTION_URI" >> $GITHUB_OUTPUT | ||
echo "service-name=${{ inputs.username }}" >> $GITHUB_OUTPUT | ||
shell: bash | ||
id: set-outputs |
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
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
Oops, something went wrong.