diff --git a/README.md b/README.md index 0a4747f..4021f4c 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ cargo run --bin forc.pub Before starting the server, the local database must be up and running. ```sh -./scripts/start_local_db.sh +docker compose up ``` Next, set up the environment by filling in the `.env` file with your Pinata test gateway details. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f395399 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.8' + +services: + postgres: + image: postgres:latest + container_name: forc_pub_db + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB_NAME} + ports: + - "${POSTGRES_PORT}:${POSTGRES_PORT}" + volumes: + - postgres_data:/var/lib/postgresql/data + + pgadmin: + image: dpage/pgadmin4:latest + container_name: pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: admin@admin.com + PGADMIN_DEFAULT_PASSWORD: admin + ports: + - "5050:80" + depends_on: + - postgres + + migrations: + image: rust:latest + container_name: migrations + volumes: + - .:/app + working_dir: /app + command: bash -c "cargo install diesel_cli --no-default-features --features postgres && diesel migration run" + depends_on: + - postgres + +volumes: + postgres_data: diff --git a/scripts/start_local_db.sh b/scripts/start_local_db.sh deleted file mode 100755 index a9af97e..0000000 --- a/scripts/start_local_db.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Source environment variables -source .env -NETWORK_NAME="forc_pub_net" -CONTAINER_NAME="forc_pub_db" - -# Check if Docker is installed -if ! command -v docker &> /dev/null; then - echo "Docker is not installed. Please install Docker to run this script." - exit 1 -fi - -# Check if the PostgreSQL container is already running -if docker ps --format '{{.Names}}' | grep -q ^$CONTAINER_NAME$; then - echo "PostgreSQL container is already running." - exit 0 -fi - -# Create docker network if it does not exist -if [ -z $(docker network ls --filter name=^${NETWORK_NAME}$ --format="{{ .Name }}") ] ; then - echo "Creating docker network ${NETWORK_NAME}." - docker network create $NETWORK_NAME -fi - -# Start PostgreSQL container -docker run \ - --rm -d \ - --name $CONTAINER_NAME \ - --network $NETWORK_NAME \ - -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \ - -e POSTGRES_DB=$POSTGRES_DB_NAME \ - -p $POSTGRES_PORT:$POSTGRES_PORT \ - postgres - -echo "PostgreSQL container started successfully." \ No newline at end of file diff --git a/scripts/start_local_server.sh b/scripts/start_local_server.sh old mode 100755 new mode 100644 index 4b2fc86..feed2ef --- a/scripts/start_local_server.sh +++ b/scripts/start_local_server.sh @@ -1,8 +1,5 @@ #!/bin/bash -# Start the PostgreSQL container -./scripts/start_local_db.sh - # Source environment variables source .env @@ -57,6 +54,9 @@ if [[ "$(docker ps -aqf name=$CONTAINER_NAME)" ]]; then fi fi +# Start the services using docker-compose +docker-compose up -d + # Start the Docker container on the same network as the PostgreSQL container docker run \ --rm -d \ @@ -69,4 +69,4 @@ docker run \ -e POSTGRES_DB_NAME=$POSTGRES_DB_NAME \ $CONTAINER_NAME -echo "Server container started successfully." \ No newline at end of file +echo "Server container started successfully."