-
Notifications
You must be signed in to change notification settings - Fork 0
feat(docker): Add Docker local development environment #537
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
Open
ashggan
wants to merge
2
commits into
develop
Choose a base branch
from
feature/docker-local-development
base: develop
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 all commits
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 hidden or 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,48 @@ | ||
| # Dependencies | ||
| node_modules/ | ||
| **/node_modules/ | ||
|
|
||
| # Build outputs | ||
| dist/ | ||
| **/dist/ | ||
| build/ | ||
| **/build/ | ||
|
|
||
| # Git | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Logs | ||
| *.log | ||
| npm-debug.log* | ||
|
|
||
| # Test files | ||
| coverage/ | ||
| **/*.test.ts | ||
| **/*.test.js | ||
| **/*.spec.ts | ||
| **/*.spec.js | ||
|
|
||
| # Documentation | ||
| docs/ | ||
| *.md | ||
|
|
||
| # Docker files (avoid recursive copies) | ||
| docker/ | ||
| Dockerfile* | ||
|
|
||
| # Environment files (use docker-compose env instead) | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
|
|
||
| # QA tests | ||
| qaAutomationTests/ |
This file contains hidden or 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,46 @@ | ||
| # Digital Safe Server Environment Variables for Local Development | ||
| # Copy this to server/.env when running the server locally with Docker infrastructure | ||
|
|
||
| # ============================================ | ||
| # Core Settings | ||
| # ============================================ | ||
| ENVIRONMENT=DEVELOPMENT | ||
| PORT=2999 | ||
|
|
||
| # ============================================ | ||
| # Authentication | ||
| # ============================================ | ||
| AUTH_TOKEN=dev_auth_token_12345_change_in_production | ||
|
|
||
| # ============================================ | ||
| # PostgreSQL (Docker container) | ||
| # ============================================ | ||
| POSTGRES_HOST=localhost | ||
| POSTGRES_USER=digitalsafe | ||
| POSTGRES_DB_NAME=digitalsafe | ||
| POSTGRES_PASSWORD=digitalsafe_dev_password | ||
|
|
||
| # ============================================ | ||
| # Redis (Docker container) | ||
| # ============================================ | ||
| REDIS_URL=redis://localhost:6379 | ||
| REDIS_PASSWORD=redis_dev_password | ||
| REDIS_USE_TLS=false | ||
|
|
||
| # ============================================ | ||
| # Azure Storage (Azurite emulator) | ||
| # ============================================ | ||
| AZURE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1; | ||
| AZURE_ACCOUNT_NAME=devstoreaccount1 | ||
| AZURE_ACCOUNT_KEY=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== | ||
|
|
||
| # ============================================ | ||
| # Application Settings | ||
| # ============================================ | ||
| DIGITAL_SAFE_DOMAIN=localhost | ||
|
|
||
| # ============================================ | ||
| # Optional Services | ||
| # ============================================ | ||
| KUTT_URL=https://old.tinylink.me/ | ||
| SENTRY_EXPRESS_DSN= |
This file contains hidden or 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,23 @@ | ||
| # Digital Safe Client Dockerfile (Development) | ||
Check noticeCode scanning / Trivy No HEALTHCHECK defined Low
Artifact: docker/Dockerfile.client
Type: dockerfile Vulnerability DS026 Severity: LOW Message: Add HEALTHCHECK instruction in your Dockerfile Link: DS026 |
||
| FROM node:20-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy package files for client | ||
| COPY client/package*.json ./client/ | ||
|
|
||
| # Install client dependencies | ||
| WORKDIR /app/client | ||
| RUN npm ci | ||
|
|
||
| # Copy client source code | ||
| COPY client/ ./ | ||
|
|
||
| # Expose Vite dev server port | ||
| EXPOSE 5173 | ||
|
|
||
| # Use non-root user for security | ||
| USER node | ||
|
|
||
| # Start Vite dev server with host binding for Docker | ||
| CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"] | ||
This file contains hidden or 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,36 @@ | ||
| # Digital Safe Server Dockerfile | ||
|
||
| FROM node:20-alpine | ||
|
|
||
| # Install build dependencies for native modules (argon2) | ||
| RUN apk add --no-cache python3 make g++ libc6-compat | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy package files for server | ||
| COPY server/package*.json ./server/ | ||
|
|
||
| # Install server dependencies | ||
| WORKDIR /app/server | ||
| RUN npm ci | ||
|
|
||
| # Copy server source code | ||
| COPY server/ ./ | ||
|
|
||
| # Copy shared files if needed | ||
| COPY custom-types/ /app/custom-types/ | ||
| COPY custom-webgl-ext.d.ts /app/ | ||
|
|
||
| # Build TypeScript | ||
| RUN npm run build | ||
|
|
||
| # Set working directory to dist for running | ||
| WORKDIR /app/server/dist | ||
|
|
||
| # Expose port | ||
| EXPOSE 2999 | ||
|
|
||
| # Use non-root user for security | ||
| USER node | ||
|
|
||
| # Start the server | ||
| CMD ["node", "./server.js"] | ||
This file contains hidden or 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,130 @@ | ||
| # Digital Safe - Docker Development Setup | ||
|
|
||
| This directory contains Docker configuration for local development. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Docker Desktop installed and running | ||
| - Docker Compose (included with Docker Desktop) | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### Option 1: Infrastructure Only (Recommended for Development) | ||
|
|
||
| Start only the database and storage services, then run the app locally: | ||
|
|
||
| ```bash | ||
| # From the docker directory | ||
| cd docker | ||
|
|
||
| # Start PostgreSQL, Redis, and Azurite | ||
| docker-compose up -d postgres redis azurite | ||
|
|
||
| # Wait for services to be healthy | ||
| docker-compose ps | ||
|
|
||
| # Now run the app locally from the project root | ||
| cd .. | ||
| npm run dev:win # Windows | ||
| # or | ||
| npm run dev # Mac/Linux | ||
| ``` | ||
|
|
||
| ### Option 2: Full Stack in Docker | ||
|
|
||
| Run everything in Docker containers: | ||
|
|
||
| ```bash | ||
| # From the docker directory | ||
| cd docker | ||
|
|
||
| # Start all services including server | ||
| docker-compose up -d | ||
|
|
||
| # Or include the client as well | ||
| docker-compose --profile with-client up -d | ||
| ``` | ||
|
|
||
| ## Services | ||
|
|
||
| | Service | Port | Description | | ||
| |-----------|-------|---------------------------------| | ||
| | postgres | 5432 | PostgreSQL database | | ||
| | redis | 6379 | Redis cache | | ||
| | azurite | 10000 | Azure Blob Storage emulator | | ||
| | server | 2999 | Express API server | | ||
| | client | 5173 | Vite dev server (optional) | | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| Copy `.env` and modify as needed. The default values work for local development. | ||
|
|
||
| ### Connecting to Services Locally | ||
|
|
||
| When running the app locally (not in Docker), use these connection settings: | ||
|
|
||
| ```env | ||
| # PostgreSQL | ||
| POSTGRES_HOST=localhost | ||
| POSTGRES_USER=digitalsafe | ||
| POSTGRES_PASSWORD=digitalsafe_dev_password | ||
| POSTGRES_DB_NAME=digitalsafe | ||
|
|
||
| # Redis | ||
| REDIS_URL=redis://localhost:6379 | ||
| REDIS_PASSWORD=redis_dev_password | ||
| REDIS_USE_TLS=false | ||
|
|
||
| # Azure Storage (Azurite) | ||
| AZURE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1; | ||
| ``` | ||
|
|
||
| ## Common Commands | ||
|
|
||
| ```bash | ||
| # Start services | ||
| docker-compose up -d | ||
|
|
||
| # Stop services | ||
| docker-compose down | ||
|
|
||
| # View logs | ||
| docker-compose logs -f | ||
|
|
||
| # View logs for specific service | ||
| docker-compose logs -f postgres | ||
|
|
||
| # Reset database (removes all data) | ||
| docker-compose down -v | ||
| docker-compose up -d | ||
|
|
||
| # Rebuild containers after code changes | ||
| docker-compose build --no-cache | ||
| docker-compose up -d | ||
|
|
||
| # Connect to PostgreSQL | ||
| docker exec -it digitalsafe-postgres psql -U digitalsafe -d digitalsafe | ||
|
|
||
| # Connect to Redis | ||
| docker exec -it digitalsafe-redis redis-cli -a redis_dev_password | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Port already in use | ||
| If you get port conflicts, either stop the conflicting service or modify the ports in `docker-compose.yml`. | ||
|
|
||
| ### Database not initializing | ||
| The init script only runs on first startup. To re-run it: | ||
| ```bash | ||
| docker-compose down -v # Remove volumes | ||
| docker-compose up -d # Start fresh | ||
| ``` | ||
|
|
||
| ### Server can't connect to services | ||
| Make sure services are healthy: | ||
| ```bash | ||
| docker-compose ps | ||
| ``` | ||
|
|
||
| All services should show "healthy" or "Up" status. |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.