Spaces:
Sleeping
Sleeping
Praneeth Yerrapragada commited on
Commit ·
a58da97
1
Parent(s): e612627
feat: setting up local database in a docker
Browse files- .env.example +4 -0
- Dockerfile.local.postgres +23 -0
- Makefile +8 -0
.env.example
CHANGED
|
@@ -43,3 +43,7 @@ APP_HOST=0.0.0.0
|
|
| 43 |
|
| 44 |
# The port to start the backend app.
|
| 45 |
APP_PORT=8000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# The port to start the backend app.
|
| 45 |
APP_PORT=8000
|
| 46 |
+
|
| 47 |
+
# Postgres database configuration
|
| 48 |
+
POSTGRES_USER=postgres
|
| 49 |
+
POSTGRES_PASSWORD=postgres
|
Dockerfile.local.postgres
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Pull the official PostgreSQL 16 image
|
| 2 |
+
FROM postgres:16
|
| 3 |
+
|
| 4 |
+
# Create a directory for the database files
|
| 5 |
+
RUN mkdir -p /var/lib/postgresql/data
|
| 6 |
+
|
| 7 |
+
# Change the ownership of the data directory
|
| 8 |
+
RUN chown -R postgres:postgres /var/lib/postgresql/data
|
| 9 |
+
|
| 10 |
+
# Copy the configuration files into the data directory
|
| 11 |
+
# NOTE: the [f] suffix is to ensure that the COPY command will not fail if the files don't exist
|
| 12 |
+
COPY ./pg_hba.con[f] /var/lib/postgresql/data/pg_hba.conf
|
| 13 |
+
COPY ./postgresql.con[f] /var/lib/postgresql/data/postgresql.conf
|
| 14 |
+
|
| 15 |
+
# Include environment variables for the PostgreSQL user and password
|
| 16 |
+
ENV POSTGRES_USER=${POSTGRES_USER}
|
| 17 |
+
ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
| 18 |
+
|
| 19 |
+
# Expose the default PostgreSQL port
|
| 20 |
+
EXPOSE 5432
|
| 21 |
+
|
| 22 |
+
# Start the PostgreSQL server
|
| 23 |
+
CMD ["postgres", "-c", "config_file=/var/lib/postgresql/data/postgresql.conf"]
|
Makefile
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
include .env
|
| 3 |
+
|
| 4 |
+
build-postgres:
|
| 5 |
+
docker build -t codepath_project_postgres -f Dockerfile.local.postgres .
|
| 6 |
+
|
| 7 |
+
run-postgres:
|
| 8 |
+
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} -e POSTGRES_USER=${POSTGRES_USER} --name codepath_project_postgres_local codepath_project_postgres
|