Skip to content

Commit

Permalink
feat: update devcontainer configuration, add post-create and post-sta…
Browse files Browse the repository at this point in the history
…rt scripts, and enhance README for setup instructions
  • Loading branch information
hackerman70000 committed Jan 13, 2025
1 parent be52844 commit fbaf69e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 81 deletions.
76 changes: 36 additions & 40 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"dockerComposeFile": "docker-compose.yml",
"name": "Dev Container",
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/va-h/devcontainers-features/uv:1": {
"version": "latest"
},
"ghcr.io/itsmechlark/features/postgresql:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/github-cli:1": {
}
},

"features": {
"ghcr.io/va-h/devcontainers-features/uv:1": {
"version": "latest"
},
"ghcr.io/itsmechlark/features/postgresql:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/node:1": {
"version": "18"
}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"forwardPorts": [5000, 8081],

"containerEnv": {
"DATABASE_URL": "postgresql://postgres:postgres@db:5432/postgres",
"EXPO_PUBLIC_API_URL": "http://localhost:5000/api"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [5000],
"containerEnv": {
"DATABASE_URL": "postgresql://postgres:postgres@db:5432/postgres"
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "/bin/bash -c 'if [ ! -f ${containerWorkspaceFolder}/backend/.env ]; then echo \"Setting up environment variables...\"; read -p \"Enter Gmail address: \" email; echo \"Enter Gmail app password: \"; read -s password; echo; echo \"SECRET_KEY=$(openssl rand -base64 32)\" > ${containerWorkspaceFolder}/backend/.env; echo \"TOKEN_SECRET_KEY=$(openssl rand -base64 32)\" >> ${containerWorkspaceFolder}/backend/.env; echo \"MAIL_SERVER=smtp.gmail.com\" >> ${containerWorkspaceFolder}/backend/.env; echo \"MAIL_PORT=587\" >> ${containerWorkspaceFolder}/backend/.env; echo \"MAIL_USE_TLS=True\" >> ${containerWorkspaceFolder}/backend/.env; echo \"MAIL_USERNAME=$email\" >> ${containerWorkspaceFolder}/backend/.env; echo \"MAIL_PASSWORD=$password\" >> ${containerWorkspaceFolder}/backend/.env; echo \"MAIL_DEFAULT_SENDER=$email\" >> ${containerWorkspaceFolder}/backend/.env; fi'",
"updateContentCommand": "cd ${containerWorkspaceFolder}/backend && uv sync",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"charliermarsh.ruff"
]
}
}
"postCreateCommand": "bash ${containerWorkspaceFolder}/.devcontainer/scripts/post-create.sh",
"postStartCommand": "bash ${containerWorkspaceFolder}/.devcontainer/scripts/post-start.sh",

"remoteUser": "root",

"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"charliermarsh.ruff",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
}
}
5 changes: 3 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
version: '3.8'
services:
devcontainer:
image: mcr.microsoft.com/devcontainers/base:noble
volumes:
- ../..:/workspaces:cached
- frontend-node-modules:/workspaces/${localWorkspaceFolderBasename}/frontend/node_modules
command: sleep infinity
ports:
- "5000:5000"
- "8081:8081"

db:
image: postgres:latest
Expand All @@ -20,4 +21,4 @@ services:

volumes:
postgres-data:

frontend-node-modules:
39 changes: 39 additions & 0 deletions .devcontainer/scripts/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

WORKSPACE_ROOT="/workspaces/pharmacy-app"

if [ ! -f "${WORKSPACE_ROOT}/backend/.env" ]; then
echo "Setting up environment variables..."

read -p "Enter Gmail address: " email
echo "Enter Gmail app password: "
read -s password
echo

cat > "${WORKSPACE_ROOT}/backend/.env" << ENVEOF
SECRET_KEY=$(openssl rand -base64 32)
TOKEN_SECRET_KEY=$(openssl rand -base64 32)
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_USERNAME=$email
MAIL_PASSWORD=$password
MAIL_DEFAULT_SENDER=$email
ENVEOF
fi

if [ -f "${WORKSPACE_ROOT}/frontend/package.json" ]; then
echo "Installing frontend dependencies..."
cd "${WORKSPACE_ROOT}/frontend"
npm install
else
echo "Error: ${WORKSPACE_ROOT}/frontend/package.json not found"
fi

if [ -f "${WORKSPACE_ROOT}/backend/pyproject.toml" ]; then
echo "Installing backend dependencies..."
cd "${WORKSPACE_ROOT}/backend"
uv sync
else
echo "Error: ${WORKSPACE_ROOT}/backend/pyproject.toml not found"
fi
12 changes: 12 additions & 0 deletions .devcontainer/scripts/post-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

WORKSPACE_ROOT="/workspaces/pharmacy-app"

if [ -f "${WORKSPACE_ROOT}/backend/pyproject.toml" ]; then
echo "Running database migrations..."
cd "${WORKSPACE_ROOT}/backend"
uv run flask db upgrade
uv run flask seed products
else
echo "Error: ${WORKSPACE_ROOT}/backend/pyproject.toml not found"
fi
48 changes: 9 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
# Pharmacy App

This project is a pharmacy application that includes user account management, product browsing, a shopping cart, and email notifications. It is designed to run on Docker and PostgreSQL with a Python backend built using Flask and React Native frontend built using Expo.
A pharmacy application with features for user management, product browsing, shopping cart functionality, and email notifications. Built with a Flask backend and React Native frontend, running in Docker with PostgreSQL database.

## Development

### Setup
## Development setup

Follow these steps to set up the project locally:

#### Access the Docker Environment
### Access the Docker Environment

In VSCode, use the "Reopen in Container" option to seamlessly open the project inside the container.

#### Navigate to `/backend`
### Backend setup

```bash
cd backend
uv run flask run -h 0.0.0.0
```

#### Apply Migrations

Run the following command to apply existing database migrations:
### Frontend setup

```bash
uv run flask db upgrade
cd frontend
npx expo start -c
```

#### Run the Development Server

Start the Flask development server:

```bash
uv run flask run
```
Access the application at http://localhost (Port 8081).

---

Expand Down Expand Up @@ -69,28 +61,6 @@ To run tests in the Docker container:
docker compose exec backend uv run pytest
```

## Frontend

To start developing the app all you need to do is:

### Navigate to `/frontend`

```bash
cd frontend
```

### Install all dependencies

```bash
npm install
```

### Starting the app

```bash
npx expo start -c
```

---

## Production deployment
Expand Down

0 comments on commit fbaf69e

Please sign in to comment.