{"id":19687205,"url":"https://github.com/trinitronx/docker-psql","last_synced_at":"2026-03-02T18:46:23.403Z","repository":{"id":136205251,"uuid":"56646393","full_name":"trinitronx/docker-psql","owner":"trinitronx","description":null,"archived":false,"fork":false,"pushed_at":"2017-01-25T21:36:36.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-10T07:47:22.416Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trinitronx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-20T01:48:13.000Z","updated_at":"2020-02-02T21:55:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"cd2dbf05-60ef-4f3c-bc87-1b5f324ac0db","html_url":"https://github.com/trinitronx/docker-psql","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fdocker-psql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fdocker-psql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fdocker-psql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinitronx%2Fdocker-psql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trinitronx","download_url":"https://codeload.github.com/trinitronx/docker-psql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240993952,"owners_count":19890419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T18:33:23.729Z","updated_at":"2026-03-02T18:46:23.310Z","avatar_url":"https://github.com/trinitronx.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"returnpath/psql\n===============\n\nA basic container with `psql`, the PostgreSQL Command Line Client installed.\n\nBuilding\n========\n\nThis project includes a `Makefile` with targets to build \u0026 ship the container.\n\n    make build  # to build\n    make ship   # to build \u0026 push to Docker Hub (you must be a maintainer for permissions)\n\nRunning\n=======\n\n## Docker\n\nTo run the pod in Docker:\n\n    docker run --rm -ti \\\n      -e PGUSER=your_db_user \\\n      -e PGPASSWORD=your_db_password \\\n      -e PGDATABASE=your_db_name \\\n      -e PGHOST=your_db_host \\\n      -e PGPORT=5432 \\\n    returnpath/psql -c '\\dS'\n\n## Kubernetes\n\nTo run a test pod in Kubernetes via a ReplicationController, first create a Secret containing your `base64` encoded database credentials: `db-secret.yml`\n\n    apiVersion: v1\n    kind: Secret\n    metadata:\n      name: db-secret-name\n      labels:\n        environment: prod\n    type: Opaque\n    data:\n      pguser: \u003cPGUSER\u003e\n      pgpassword: \u003cPGPASSWORD\u003e\n      pgdatabase: \u003cPGDATABASE\u003e\n      pghost: \u003cPGHOST\u003e\n      pgport: \u003cPGPORT\u003e\n\nTo encode your credentials:\n\n - Run: `echo -n 'your-pg-user' | base64`\n - Paste in the result into the `db-secret.yml` in place of `\u003cPGUSER\u003e`\n - Repeat for all the other variables\n - Create the secret into the Kubernetes cluster: `kubectl apply -f db-secret.yml`\n\nThen, create a file `psql-rc-test.yaml` containing:\n\n    apiVersion: v1\n    kind: ReplicationController\n    metadata:\n      name: psql\n    spec:\n      replicas: 1\n      selector:\n        name: psql-test\n      template:\n        metadata:\n          labels:\n            name: psql-test\n            service: psql-test\n        spec:\n          containers:\n          - name: psql-test\n            image: returnpath/psql\n            env:\n            - name: PGUSER\n              valueFrom:\n                secretKeyRef:\n                  name: db-secret-name\n                  key: pguser\n            - name: PGPASSWORD\n              valueFrom:\n                secretKeyRef:\n                  name: db-secret-name\n                  key: pgpassword\n            - name: PGDATABASE\n              valueFrom:\n                secretKeyRef:\n                  name: db-secret-name\n                  key: pgdatabase\n            - name: PGHOST\n              valueFrom:\n                secretKeyRef:\n                  name: db-secret-name\n                  key: pghost\n            - name: PGPORT\n              valueFrom:\n                secretKeyRef:\n                  name: db-secret-name\n                  key: pgport\n            args:\n              - \"-c\"\n              - \"\\\\dS\"\n          restartPolicy: Always\n\nThen run:\n\n    kubectl apply -f psql-rc-test.yaml\n\nA Pod \u0026 ReplicationController should start and run the command: `psql -c \\dS`\n\nThe above example is only truly useful as a test for whether this pod \u0026 your database connection is working.  In order to make practical use of this container, you probably want to run it with queries as scheduled jobs.\n\nUntil Kubernetes `1.3`, the `ScheduledJob` construct did not exist.  If you are using a version of Kubernetes without `ScheduledJob`, you probably want to check out: [ReturnPath/job-runner][returnpath-job-runner].\n\nIn order to use the job runner, you should use the `kubernetes-native` Job Runner.  The [job-runner's][returnpath-job-runner] `ONBUILD` instructions will copy `cron`, `defaults`, `jobs` and `k8s-jobs` directories into your image which is based on it.  \n\nFirst, create a Docker image based on `returnpath/job-runner` to contain your job definitions:\n\n`Dockerfile`:\n\n    FROM returnpath/job-runner\n\nCreate a directory `k8s-jobs/`, then place native Kubernetes Job `.yaml` files in it.  An example for using this `psql` container might be:\n\n`mkdir k8s-jobs/`\n`k8s-jobs/psql-test.yaml`:\n\n    apiVersion: batch/v1\n    kind: Job\n    metadata:\n      name: psql-test\n    spec:\n      template:\n        metadata:\n          name: psql-test\n          labels:\n            service: psql-test\n        spec:\n          containers:\n            - name: psql-test\n              image: returnpath/psql\n              args: [ \"-c\", \"\\\\dS\" ]\n              env:\n                - name: PGUSER\n                  valueFrom:\n                    secretKeyRef:\n                      name: db-secret-name\n                      key: pguser\n                - name: PGPASSWORD\n                  valueFrom:\n                    secretKeyRef:\n                      name: db-secret-name\n                      key: pgpassword\n                - name: PGDATABASE\n                  valueFrom:\n                    secretKeyRef:\n                      name: db-secret-name\n                      key: pgdatabase\n                - name: PGHOST\n                  valueFrom:\n                    secretKeyRef:\n                      name: db-secret-name\n                      key: pghost\n                - name: PGPORT\n                  valueFrom:\n                    secretKeyRef:\n                      name: db-secret-name\n                      key: pgport\n          restartPolicy: Never\n\nThen, create a [`crond` style][cron-wikipedia] schedule for the job by creating a directory named `cron/` with a file with the **same name** as your job, passing your job name as the first argument to `/app/processor/runner`.  For example, to run it every `5` minutes:\n\n    mkdir -p cron/\n    echo \"*/5 * * * * root /app/processor/runner psql-test \u003e\u003e /var/log/cron.log 2\u003e\u00261\" \u003e cron/psql-test\n\nThen, create a `defaults/job-name` file, even if it is blank!  **It is important to note** that without this file, the job reaper will not delete the job, and subsequent runs will fail due to already having existed.  This can be useful for testing that a job runs one time \u0026 inspecting things afterwards without worrying about the reaper deleting jobs \u0026 pods.\n\nAny files under `default` will be copied into `/etc/default/`, and sourced in the context of the job-runner container's \"runner\" script. This can be useful for setting environment variables or executing pre-task bash commands or functions.\n\nTo create a blank `/etc/defaults` file for the job:\n\n    touch defaults/psql-test\n\nNext, build your job container with:\n\n    docker build -t your-dockerhub-username/test-jobs .\n    docker push your-dockerhub-username/test-jobs\n\nFinally, start the job-runner container you have just built on the cluster.  For example, to run `1` instance of the job-runner via a ReplicationController, create a file:\n\n`job-runner.yaml`:\n\n    apiVersion: v1\n    kind: ReplicationController\n    metadata:\n      name: job-runner\n    spec:\n      replicas: 1\n      selector:\n        name: job-runner\n      template:\n        metadata:\n          labels:\n            name: job-runner\n        spec:\n          containers:\n          - name: job-runner\n            image: your-dockerhub-username/test-jobs\n            env:\n            - name: RUNNER\n              value: kubernetes-native\n            - name: KUBERNETES_MASTER\n              value: https://kubernetes:443\n\n    kubectl apply -f job-runner.yaml\n\nNote: If you wish to run multiple instances of the `job-runner`, you will need to use the \"Distributed Locking\" feature of the base container.  This involves installing Consul, and is a bit more complicated than this README will delve into.\n\nIf all went well, you should now have a test job scheduled to run every 5 minutes.  To see the jobs \u0026 pods:\n\n    kubectl get pods -l name=job-runner\n    kubectl describe rc,pod -l name=job-runner\n    kubectl get jobs -l service=psql-test\n    kubectl get pods -l service=psql-test\n    kubectl describe jobs,pods -l service=psql-test\n\nTo follow the logs for the job-runner or job pods, find the unique pod name for each via the above commands and run either of:\n\n    kubectl logs -f job-runner-xxxxx\n    kubectl logs -f psql-test-xxxxx\n\n[returnpath-job-runner]: https://github.com/ReturnPath/job-runner\n[cron-wikipedia]: https://en.wikipedia.org/wiki/Cron#Configuration_file\n\n## License\n\nThis project is simply a packaging script for the [`psql`][psql-repo-license], and [`awscli`][awscli-github] tools.  As such, nothing in this repository is \"novel\", or \"non-obvious\". This repo is therefore released under the permissive [MIT License][mit-license].\n\nHowever, the upstream tools are released under various Open Source Licenses:\n\n - [\"`awscli`\"][awscli-license] is released under the [Apache 2.0 License][apache-2-license]. \n - [\"`psql`\"][psql-license] is released under the [PostgreSQL License][PostgreSQL-license]. \n\nThe text of these tool's licenses are included here to avoid confusion.\n\n[mit-license]: https://choosealicense.com/licenses/mit/\n[awscli-github]: https://github.com/aws/aws-cli\n[apache-2-license]: https://choosealicense.com/licenses/apache-2.0/\n[awscli-license]: https://github.com/aws/aws-cli/blob/develop/LICENSE.txt\n[psql-repo-license]: https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=COPYRIGHT;h=c320eccac08f7bec087f47efd48182eeca639d26;hb=HEAD\n[psql-license]: https://www.postgresql.org/about/licence/\n[PostgreSQL-license]: https://opensource.org/licenses/postgresql\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinitronx%2Fdocker-psql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrinitronx%2Fdocker-psql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinitronx%2Fdocker-psql/lists"}