diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..47b7b9a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM postgres:14.5 +# requirements to run ./download +RUN apt-get update +RUN apt-get install -y wget && apt-get install -y bzip2 + +COPY . omdb-postgresql +COPY docker-import /docker-entrypoint-initdb.d/docker-import.sh + +WORKDIR omdb-postgresql + +RUN "./download" \ No newline at end of file diff --git a/README.md b/README.md index 7b65534..edd8739 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,14 @@ Create `omdb.dump` database export file: ``` pg_dump -Fc -f omdb.dump omdb ``` + +Using docker +-------------------------- +Docker compose will create postgres database +and do the importing automatically. +Created database can be accessed using credentials +specified in environment section of the docker-compose.yaml. + +```shell +docker compose up +``` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..8bc3537 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +version: "3" + +services: + db: + build: . + container_name: "postgres_db" + environment: + POSTGRES_PASSWORD: omdbmovies + POSTGRES_USER: omdbmovies + POSTGRES_NAME: omdbmovies + ports: + - "54325:5432" \ No newline at end of file diff --git a/docker-import b/docker-import new file mode 100644 index 0000000..dab3e9b --- /dev/null +++ b/docker-import @@ -0,0 +1,10 @@ +#!/bin/sh +set -eux + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER docker; + CREATE DATABASE demo; + GRANT ALL PRIVILEGES ON DATABASE demo TO docker; + CREATE EXTENSION IF NOT EXISTS tsm_system_rows; + \i omdb.sql +EOSQL