-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LLSC-32] Add script for starting up a postgres database with docker #10
Open
mslwang
wants to merge
2
commits into
main
Choose a base branch
from
mslwang/LLSC-32-add-postgres-dockerfile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ | ||
FROM postgres:16-alpine | ||
|
||
# Set environment variables for PostgreSQL | ||
ENV POSTGRES_USER=${POSTGRES_USER} | ||
ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
ENV POSTGRES_DB=${POSTGRES_DATABASE} | ||
|
||
# Add a health check for the PostgreSQL server | ||
HEALTHCHECK --interval=5s --timeout=5s --retries=5 \ | ||
CMD pg_isready -U ${POSTGRES_USER} || exit 1 | ||
|
||
# Expose PostgreSQL port | ||
EXPOSE 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 |
---|---|---|
|
@@ -34,13 +34,19 @@ To start the backend locally, use the following command: | |
pdm run dev | ||
``` | ||
|
||
Note: If you wish to run the backend outside of Docker (e.g., for local development), you'll need to set up a PostgreSQL database. Ensure your database configuration is set properly in the environment variables before running the project. For the time being, the recommended approach for local development using the database is to use the docker compose Postgres instance with your local dev backend. | ||
Note: If you wish to run the backend outside of Docker (e.g., for local development), you'll need to set up a PostgreSQL database. Ensure your database configuration is set properly in the environment variables before running the project. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some note about setting up the readme properly prior to running this command |
||
|
||
To start up the database using docker, run the following command: | ||
```bash | ||
cd backend | ||
pdm run db | ||
``` | ||
|
||
To check if the database has been started up, type the following: | ||
```bash | ||
docker ps | grep llsc_db | ||
docker ps | grep llsc_db_dev_local | ||
``` | ||
This checks the list of docker containers and searchs for the container name `llsc_db` | ||
This checks the list of docker containers and searchs for the container name `llsc_db_dev_local` | ||
|
||
## Run Project | ||
|
||
|
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,16 @@ | ||
#!/bin/bash | ||
|
||
envfile=".env" | ||
|
||
# Prioritize base dir .env over backend dir .env, as docker-compose should pull from there | ||
if [ -s "../.env" ]; then | ||
envfile="../.env" | ||
fi | ||
|
||
docker build -t llsc_db_dev_local -f Dockerfile.db . | ||
docker run -d \ | ||
--name llsc_db_dev_local \ | ||
--env-file $envfile \ | ||
-p 5432:5432 \ | ||
-v llsc_postgres_data:/var/lib/postgresql/data \ | ||
llsc_db_dev_local |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question when we run
pdm run dev
are we currently connecting to the right db port so that we automatically connect to the db when running locally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 5432 is the current default db port.