From 3ee83e344e78abd3a1f76ae394df488dabdc144d Mon Sep 17 00:00:00 2001 From: Leopere Date: Wed, 23 Apr 2025 10:32:30 -0400 Subject: [PATCH] Template Project v1.0.0 - Initial setup with Docker configuration --- .cursor/rules.json | 81 ++++++++++++++++ .cursor/rules/docker-compose-files.mdc | 5 + .cursor/rules/docker-files.mdc | 38 ++++++++ .cursor/rules/dockerfiles.mdc | 30 ++++++ .cursor/rules/git-workflow.mdc | 5 + .cursor/rules/gitignore.mdc | 38 ++++++++ .cursor/rules/gitkeep-handling.mdc | 47 +++++++++ .cursor/rules/project-structure.mdc | 5 + .cursor/rules/scripts.mdc | 5 + .cursor/rules/source-code.mdc | 5 + .cursor/rules/stack-files.mdc | 5 + .cursor/rules/temp-directory.mdc | 5 + .gitignore | 18 ++++ README.md | 126 +++++++++++++++++++++++++ build-test-run.sh | 83 ++++++++++++++++ docker-compose.dev.yml | 29 ++++++ docker-compose.production.yml | 7 +- docker-compose.staging.yml | 9 +- docker-compose.test.yml | 10 ++ docker/template/Dockerfile | 10 ++ docker/template/Dockerfile.production | 1 + docker/template/src/.gitkeep | 0 stack.production.yml | 35 ++++++- stack.staging.yml | 44 ++++----- temp/.gitkeep | 0 temp/build-test-run.log | 106 +++++++++++++++++++++ temp/test_output.log | 55 +++++++++++ tests/run_tests.sh | 32 +++++++ 28 files changed, 799 insertions(+), 35 deletions(-) create mode 100644 .cursor/rules.json create mode 100644 .cursor/rules/docker-compose-files.mdc create mode 100644 .cursor/rules/docker-files.mdc create mode 100644 .cursor/rules/dockerfiles.mdc create mode 100644 .cursor/rules/git-workflow.mdc create mode 100644 .cursor/rules/gitignore.mdc create mode 100644 .cursor/rules/gitkeep-handling.mdc create mode 100644 .cursor/rules/project-structure.mdc create mode 100644 .cursor/rules/scripts.mdc create mode 100644 .cursor/rules/source-code.mdc create mode 100644 .cursor/rules/stack-files.mdc create mode 100644 .cursor/rules/temp-directory.mdc create mode 100644 .gitignore create mode 100644 README.md create mode 100755 build-test-run.sh create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.test.yml create mode 100644 docker/template/Dockerfile create mode 100644 docker/template/Dockerfile.production create mode 100644 docker/template/src/.gitkeep create mode 100644 temp/.gitkeep create mode 100644 temp/build-test-run.log create mode 100644 temp/test_output.log create mode 100755 tests/run_tests.sh diff --git a/.cursor/rules.json b/.cursor/rules.json new file mode 100644 index 0000000..8848517 --- /dev/null +++ b/.cursor/rules.json @@ -0,0 +1,81 @@ +{ + "version": 1, + "rules": [ + { + "pattern": "**/*", + "rule": "project-structure.mdc" + }, + { + "pattern": "**/docker/template/Dockerfile", + "rule": "dockerfiles.mdc" + }, + { + "pattern": "**/docker/template/Dockerfile.production", + "rule": "dockerfiles.mdc" + }, + { + "pattern": "**/docker-compose.dev.yml", + "rule": "docker-compose-files.mdc" + }, + { + "pattern": "**/docker-compose.staging.yml", + "rule": "docker-compose-files.mdc" + }, + { + "pattern": "**/docker-compose.production.yml", + "rule": "docker-compose-files.mdc" + }, + { + "pattern": "**/docker-compose.test.yml", + "rule": "docker-compose-files.mdc" + }, + { + "pattern": "**/stack.staging.yml", + "rule": "stack-files.mdc" + }, + { + "pattern": "**/stack.production.yml", + "rule": "stack-files.mdc" + }, + { + "pattern": "**/*.sh", + "rule": "scripts.mdc" + }, + { + "pattern": "**/build-test-run.sh", + "rule": "git-workflow.mdc" + }, + { + "pattern": "**/temp/**/*", + "rule": ["temp-directory.mdc", "gitkeep-handling.mdc"] + }, + { + "pattern": "**/.gitignore", + "rule": "gitignore.mdc" + }, + { + "pattern": "**/.git/**/*", + "rule": "git-workflow.mdc" + }, + { + "pattern": "**/docker/template/src/**/*", + "rule": ["source-code.mdc", "gitkeep-handling.mdc"] + }, + { + "pattern": "**/.gitkeep", + "rule": "gitkeep-handling.mdc" + }, + { + "pattern": "**/temp/", + "rule": ["temp-directory.mdc", "gitkeep-handling.mdc"] + }, + { + "pattern": "**/docker/template/src/", + "rule": ["source-code.mdc", "gitkeep-handling.mdc"] + }, + { + "pattern": "**/.woodpecker.yml", + "rule": "project-structure.mdc" + } + ] +} \ No newline at end of file diff --git a/.cursor/rules/docker-compose-files.mdc b/.cursor/rules/docker-compose-files.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/docker-compose-files.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.cursor/rules/docker-files.mdc b/.cursor/rules/docker-files.mdc new file mode 100644 index 0000000..f7cb622 --- /dev/null +++ b/.cursor/rules/docker-files.mdc @@ -0,0 +1,38 @@ +--- +description: +globs: Dockerfile,Dockerfile.* +alwaysApply: false +--- +# Docker Files + +## Dockerfiles +- [docker/template/Dockerfile](mdc:docker/template/Dockerfile): Development/Base Dockerfile + - Used for local development and testing + - Referenced in [docker-compose.dev.yml](mdc:docker-compose.dev.yml) + +- [docker/template/Dockerfile.production](mdc:docker/template/Dockerfile.production): Production-optimized Dockerfile + - Used for production deployments + - Referenced in [docker-compose.production.yml](mdc:docker-compose.production.yml) + +## Docker Compose Files +- [docker-compose.dev.yml](mdc:docker-compose.dev.yml): Development setup + - Uses volume mounts for live code changes + - Configures development environment variables + - Mounts the [temp](mdc:temp) directory for local testing + +- [docker-compose.staging.yml](mdc:docker-compose.staging.yml): Staging build configuration + - Builds and tags the staging image + - Used by CI/CD for staging deployments + +- [docker-compose.production.yml](mdc:docker-compose.production.yml): Production build configuration + - Builds and tags the production image + - Used by CI/CD for production deployments + +## Stack Files +- [stack.staging.yml](mdc:stack.staging.yml): Staging stack deployment + - Configures service deployment for staging environment + - Sets up Traefik routing rules + +- [stack.production.yml](mdc:stack.production.yml): Production stack deployment + - Configures service deployment for production environment + - Sets up Traefik routing rules with appropriate security headers diff --git a/.cursor/rules/dockerfiles.mdc b/.cursor/rules/dockerfiles.mdc new file mode 100644 index 0000000..4094973 --- /dev/null +++ b/.cursor/rules/dockerfiles.mdc @@ -0,0 +1,30 @@ +--- +description: +globs: +alwaysApply: false +--- +# Dockerfiles + +This project uses a multi-stage Dockerfile approach for different environments. + +## Development Dockerfile +[docker/template/Dockerfile](mdc:docker/template/Dockerfile): Used for local development +- Optimized for fast rebuilds and development workflow +- Includes development tools and debugging capabilities +- Used by [docker-compose.dev.yml](mdc:docker-compose.dev.yml) +- Allows for volume mounting of source code + +## Production Dockerfile +[docker/template/Dockerfile.production](mdc:docker/template/Dockerfile.production): Used for production deployments +- Optimized for security, size, and performance +- Removes development dependencies and tools +- Used by [docker-compose.production.yml](mdc:docker-compose.production.yml) +- Bakes the source code into the image + +## Guidelines +- Keep base images consistent between environments +- Use multi-stage builds to optimize image size +- Pin specific versions of base images +- Include proper healthchecks +- Document any environment variables required +- Optimize caching by ordering instructions appropriately (dependencies first, code last) diff --git a/.cursor/rules/git-workflow.mdc b/.cursor/rules/git-workflow.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/git-workflow.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.cursor/rules/gitignore.mdc b/.cursor/rules/gitignore.mdc new file mode 100644 index 0000000..d839a6e --- /dev/null +++ b/.cursor/rules/gitignore.mdc @@ -0,0 +1,38 @@ +--- +description: +globs: +alwaysApply: false +--- +# Gitignore Rules + +The [.gitignore](mdc:.gitignore) file controls which files are tracked by Git. + +## Key Patterns + +- Cruft files (temporary/generated files) should always be ignored +- The `./temp` directory should exist in the repository +- Contents of `./temp` should be ignored (except for `.gitkeep`) + +## Standard Cruft Files to Ignore + +- `*.log` - Log files +- `*.tmp`, `*.bak` - Temporary and backup files +- `*.swp`, `*.swo` - Vim swap files +- `*.pyc`, `__pycache__/` - Python bytecode +- `node_modules/` - Node.js dependencies +- `dist/`, `build/` - Build output directories +- `*.DS_Store`, `Thumbs.db` - OS-specific files + +## Temp Directory Setup + +```gitignore +# Allow temp directory but ignore its contents +./temp/* +!./temp/.gitkeep +``` + +## Important Guidelines + +- When adding files to a previously empty directory with a `.gitkeep`, remove the `.gitkeep` file +- Never commit sensitive data, temporary build artifacts, or large binary files +- Keep the temp directory clean by only using it for local testing diff --git a/.cursor/rules/gitkeep-handling.mdc b/.cursor/rules/gitkeep-handling.mdc new file mode 100644 index 0000000..5385427 --- /dev/null +++ b/.cursor/rules/gitkeep-handling.mdc @@ -0,0 +1,47 @@ +--- +description: +globs: +alwaysApply: false +--- +# .gitkeep File Handling + +## Purpose of .gitkeep + +The `.gitkeep` file is a convention (not a Git feature) used to: +- Track otherwise empty directories in Git +- Ensure important directory structures are maintained +- Placeholder for directories that will contain files in the future + +## Important Rule + +**When adding content to a directory that contains a `.gitkeep` file, you should delete the `.gitkeep` file.** + +```bash +# Example workflow when adding content to a previously empty directory +# 1. Check if .gitkeep exists +if [ -f directory/.gitkeep ]; then + # 2. Remove it when adding actual content + rm directory/.gitkeep +fi + +# 3. Add your files +touch directory/your-new-file.txt + +# 4. Commit both changes together +git add directory/ +git commit -m "Add content to directory and remove .gitkeep" +``` + +## Why Remove .gitkeep? + +- `.gitkeep` serves no purpose once a directory contains files +- Leaving it creates confusion about the directory's status +- Proper cleanup maintains a clean repository + +## Locations with .gitkeep + +In this project, the following locations may contain `.gitkeep` files: +- [temp/.gitkeep](mdc:temp/.gitkeep) - Keeps the temp directory in the repo +- [docker/template/src/.gitkeep](mdc:docker/template/src/.gitkeep) - Keeps the source directory in the repo + +Always check for `.gitkeep` when adding files to these directories and remove it if found. diff --git a/.cursor/rules/project-structure.mdc b/.cursor/rules/project-structure.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/project-structure.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.cursor/rules/scripts.mdc b/.cursor/rules/scripts.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/scripts.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.cursor/rules/source-code.mdc b/.cursor/rules/source-code.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/source-code.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.cursor/rules/stack-files.mdc b/.cursor/rules/stack-files.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/stack-files.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.cursor/rules/temp-directory.mdc b/.cursor/rules/temp-directory.mdc new file mode 100644 index 0000000..b93c988 --- /dev/null +++ b/.cursor/rules/temp-directory.mdc @@ -0,0 +1,5 @@ +--- +description: +globs: +alwaysApply: false +--- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..208930a --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +./temp/* + +# Common cruft files (temporary/generated files) +*.log # Log files +*.bak # Backup files (e.g., from editors) +*.swp # Vim swap files +*.swo # Vim swap files +*.tmp # Generic temporary files +*.pyc # Python bytecode +__pycache__/ # Python cache directories +*.o # Object files (C/C++ builds) +*.a # Static libraries +*.so # Shared libraries +node_modules/ # Node.js dependencies +dist/ # Build output directories +build/ # Build output directories +*.DS_Store # macOS cruft +Thumbs.db # Windows cruft diff --git a/README.md b/README.md new file mode 100644 index 0000000..f3bf1bc --- /dev/null +++ b/README.md @@ -0,0 +1,126 @@ +# Template Project + +This is a template project that follows a standardized structure for Docker-based applications. + +## Project Structure + +``` +./ +├── .woodpecker.yml # CI configuration +├── build-test-run.sh # Convenience script for local development +├── docker/ +│ └── template/ # Main application container +│ ├── Dockerfile # Base Dockerfile +│ ├── Dockerfile.production # Production-specific Dockerfile +│ └── src/ # Application source code +├── tests/ # Test scripts +├── temp/ # Local testing scratch space +├── docker-compose.dev.yml # Docker Compose for local development +├── docker-compose.production.yml +├── docker-compose.staging.yml +├── docker-compose.test.yml +├── stack.staging.yml +└── stack.production.yml +``` + +## Local Development + +### Quick Start + +The easiest way to get started with local development is to use the `build-test-run.sh` script: + +```bash +./build-test-run.sh +``` + +This script will: +1. Build the Docker images using docker-compose.dev.yml +2. Run tests if available +3. Start all services in the background +4. Display the URL to access the application + +### Development Compose File + +The `docker-compose.dev.yml` file is designed for local development. It includes: +- Volume mounts for code changes without rebuilding +- Debug environment variables +- Health checks +- Local ports for easy access + +To use it directly: +```bash +# Build and start in one command +docker compose -f docker-compose.dev.yml up --build + +# Run in the background +docker compose -f docker-compose.dev.yml up -d + +# View logs +docker compose -f docker-compose.dev.yml logs -f + +# Stop services +docker compose -f docker-compose.dev.yml down +``` + +### Using the `temp` Directory + +The `./temp/` directory serves as a scratch space for local testing and development. It's designed to store temporary files that shouldn't be committed to version control, such as: + +- Test output logs (e.g., `test_output.log`) +- Temporary build artifacts +- Local configuration overrides +- Mock data for testing +- Debug logs and crash reports + +#### Example Usage + +1. Running tests with output: +```bash +# Test output will be written to ./temp/test_output.log +./tests/run_tests.sh > ./temp/test_output.log +``` + +2. Local configuration: +```bash +# Create a local config override +cp config.yml ./temp/local_config.yml +# Edit local_config.yml for testing +``` + +3. Debug logs: +```bash +# Application debug logs +docker-compose -f docker-compose.test.yml up > ./temp/debug.log +``` + +### Important Notes + +- The `./temp/` directory is git-ignored +- Files in this directory are temporary and can be safely deleted +- Use this directory for any files that shouldn't be committed to version control +- The directory is mounted in test containers for easy access to test outputs + +## Development Workflow + +1. Start local development: +```bash +./build-test-run.sh +# or +docker compose -f docker-compose.dev.yml up --build +``` + +2. Run tests: +```bash +./tests/run_tests.sh +``` + +3. Check test outputs in `./temp/` directory + +4. Clean up temporary files: +```bash +rm -rf ./temp/* +``` + +## CI/CD + +The project uses Woodpecker CI for continuous integration. The `temp` directory is not included in CI builds to ensure clean, reproducible builds. \ No newline at end of file diff --git a/build-test-run.sh b/build-test-run.sh new file mode 100755 index 0000000..39881f4 --- /dev/null +++ b/build-test-run.sh @@ -0,0 +1,83 @@ +#!/bin/bash +set -e + +# Colors for terminal output +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +echo -e "${YELLOW}Starting build-test-run script for local development${NC}" + +# Create temp directory if it doesn't exist +mkdir -p ./temp + +# Log file for build output +LOG_FILE="./temp/build-test-run.log" +echo "Build started at $(date)" > $LOG_FILE + +# Step 1: Build the Docker images +echo -e "${GREEN}Step 1: Building Docker images${NC}" +echo "Building Docker images..." >> $LOG_FILE +docker compose -f docker-compose.dev.yml build >> $LOG_FILE 2>&1 +if [ $? -ne 0 ]; then + echo -e "${RED}Build failed. Check $LOG_FILE for details.${NC}" + exit 1 +fi +echo -e "${GREEN}Build completed successfully${NC}" + +# Step 2: Run tests if they exist +TESTS_PASSED=false +if [ -f "./tests/run_tests.sh" ]; then + echo -e "${GREEN}Step 2: Running tests${NC}" + echo "Running tests..." >> $LOG_FILE + chmod +x ./tests/run_tests.sh + ./tests/run_tests.sh >> $LOG_FILE 2>&1 + if [ $? -ne 0 ]; then + echo -e "${RED}Tests failed. Check $LOG_FILE for details.${NC}" + echo -e "${YELLOW}Please fix the issues before committing your changes.${NC}" + exit 1 + fi + echo -e "${GREEN}Tests completed successfully${NC}" + TESTS_PASSED=true +else + echo -e "${YELLOW}No test script found. Skipping tests.${NC}" +fi + +# Step 3: Start the services +echo -e "${GREEN}Step 3: Starting services${NC}" +echo "Starting services..." >> $LOG_FILE +docker compose -f docker-compose.dev.yml up -d >> $LOG_FILE 2>&1 +if [ $? -ne 0 ]; then + echo -e "${RED}Failed to start services. Check $LOG_FILE for details.${NC}" + exit 1 +fi + +# Get the URL for the service +PORT=$(docker compose -f docker-compose.dev.yml port template 3000 2>/dev/null | cut -d: -f2) +if [ -n "$PORT" ]; then + echo -e "${GREEN}Service is running at: ${YELLOW}http://localhost:$PORT${NC}" +else + echo -e "${YELLOW}Service is running but couldn't determine the port.${NC}" +fi + +echo -e "${GREEN}All services are up and running!${NC}" +echo -e "To view logs: ${YELLOW}docker compose -f docker-compose.dev.yml logs -f${NC}" +echo -e "To stop: ${YELLOW}docker compose -f docker-compose.dev.yml down${NC}" +echo "Build and run completed at $(date)" >> $LOG_FILE + +# Show Git workflow guidance if tests passed +if [ "$TESTS_PASSED" = true ]; then + echo -e "\n${BLUE}=== Ready to Commit and Push ===${NC}" + echo -e "${GREEN}All tests have passed! You can now commit and push your changes:${NC}" + echo -e "${YELLOW}git add .${NC}" + echo -e "${YELLOW}git commit -m \"Your descriptive commit message\"${NC}" + echo -e "${YELLOW}git push${NC}" + echo -e "\n${GREEN}Or use the convenient one-liner:${NC}" + echo -e "${YELLOW}git add . && git commit -m \"Your descriptive commit message\" && git push${NC}" + echo -e "\n${BLUE}Remember:${NC}" + echo -e "- Use descriptive commit messages" + echo -e "- Add 'HOTFIX:' prefix for emergency fixes" + echo -e "- Document significant changes in your commit message" +fi \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..6f340cd --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,29 @@ +# Development configuration for local testing +services: + template: + build: + context: ./docker/template + dockerfile: Dockerfile + image: template:dev + volumes: + - ./docker/template/src:/scratch + - ./temp:/temp + networks: + - dev_network + + # Add any additional services you need here + # Example: + # db: + # image: postgres:14 + # environment: + # - POSTGRES_PASSWORD=postgres + # - POSTGRES_USER=postgres + # - POSTGRES_DB=template + # volumes: + # - ./temp/postgres-data:/var/lib/postgresql/data + # networks: + # - dev_network + +networks: + dev_network: + driver: bridge \ No newline at end of file diff --git a/docker-compose.production.yml b/docker-compose.production.yml index d0e3da8..930125d 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -1,6 +1,7 @@ +# The only stuff that happens here is template gets replaced and so does possibly nixius services: - midtownplaydio: + template: build: - context: ./docker/midtownplaydio + context: ./docker/template dockerfile: Dockerfile.production - image: git.nixc.us/colin/midtownplaydio:production \ No newline at end of file + image: git.nixc.us/nixius/template:production \ No newline at end of file diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index 5636c9a..a96c565 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -1,6 +1,7 @@ +# The only stuff that happens here is template gets replaced and so does possibly nixius services: - midtownplaydio: + template: build: - context: ./docker/midtownplaydio - dockerfile: Dockerfile - image: git.nixc.us/colin/midtownplaydio:staging \ No newline at end of file + context: ./docker/template + dockerfile: Dockerfile.staging + image: git.nixc.us/colin/template:staging \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..e26e989 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,10 @@ +# Test configuration +services: + template: + build: + context: ./docker/template + dockerfile: Dockerfile + image: template:test + volumes: + - ./docker/template/src:/scratch + - ./temp:/temp \ No newline at end of file diff --git a/docker/template/Dockerfile b/docker/template/Dockerfile new file mode 100644 index 0000000..55a0f12 --- /dev/null +++ b/docker/template/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.18 + +# Create directories for volume mounts +RUN mkdir -p /scratch /temp + +# Set working directory +WORKDIR /scratch + +# Simple command to keep container running +CMD ["tail", "-f", "/dev/null"] diff --git a/docker/template/Dockerfile.production b/docker/template/Dockerfile.production new file mode 100644 index 0000000..35a86f7 --- /dev/null +++ b/docker/template/Dockerfile.production @@ -0,0 +1 @@ +FROM git.nixc.us/nixius/template:staging diff --git a/docker/template/src/.gitkeep b/docker/template/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/stack.production.yml b/stack.production.yml index 290b9ba..6f0317d 100644 --- a/stack.production.yml +++ b/stack.production.yml @@ -3,8 +3,37 @@ networks: external: true services: + template: + image: git.nixc.us/nixius/template:production + deploy: + replicas: 1 + restart_policy: + condition: on-failure + max_attempts: 3 + update_config: + parallelism: 1 + delay: 10s + order: start-first + rollback_config: + parallelism: 1 + delay: 10s + order: stop-first + networks: + - traefik + labels: + - traefik.enable=true + - traefik.http.routers.production_template.rule=Host(`template.nixc.us`) + - traefik.http.routers.production_template.entrypoints=websecure + - traefik.http.routers.production_template.tls=true + - traefik.http.routers.production_template.tls.certresolver=letsencryptresolver + - traefik.http.services.production_template.loadbalancer.server.port=3000 + # - traefik.http.services.production_template.loadbalancer.healthcheck.path=/health + # - traefik.http.services.production_template.loadbalancer.healthcheck.interval=30s + # - traefik.http.services.production_template.loadbalancer.healthcheck.timeout=5s + - traefik.http.routers.production_template.middlewares=secure-headers + midtownplaydio: - image: git.nixc.us/colin/midtownplaydio:production + image: git.nixc.us/nixius/midtownplaydio:production networks: - traefik deploy: @@ -23,6 +52,7 @@ services: traefik.http.routers.production_midtownplaydio.entrypoints: "websecure" traefik.http.routers.production_midtownplaydio.tls: "true" traefik.http.routers.production_midtownplaydio.tls.certresolver: "letsencryptresolver" + traefik.http.routers.production_midtownplaydio.middlewares: "secure-headers" traefik.http.services.production_midtownplaydio.loadbalancer.server.port: "3000" traefik.docker.network: "traefik" # traefik.http.services.production_midtownplaydio.loadbalancer.healthcheck.path: "/health" @@ -39,6 +69,3 @@ services: traefik.http.middlewares.secure-headers.headers.browserXssFilter: "true" traefik.http.middlewares.secure-headers.headers.referrerPolicy: "no-referrer" traefik.http.middlewares.secure-headers.headers.featurePolicy: "camera 'none'; geolocation 'none'; microphone 'none'; payment 'none'; usb 'none'; vr 'none'" - - # Attach security headers middleware to the router - traefik.http.routers.production_midtownplaydio.middlewares: "secure-headers" diff --git a/stack.staging.yml b/stack.staging.yml index 86a0650..ea38fa1 100644 --- a/stack.staging.yml +++ b/stack.staging.yml @@ -1,37 +1,33 @@ -version: '3.8' - networks: traefik: external: true default: services: - midtownplaydio: - image: git.nixc.us/colin/midtownplaydio:staging - networks: - - traefik - - default + template: + image: git.nixc.us/nixius/template:staging deploy: replicas: 1 - placement: - constraints: - - node.hostname == ingress.nixc.us - preferences: - - spread: node.id restart_policy: condition: on-failure + max_attempts: 3 update_config: - delay: 20s parallelism: 1 + delay: 10s order: start-first - labels: - traefik.enable: "true" - traefik.http.routers.staging_midtownplaydio.rule: "Host(`staging.midtownplaydio.nixc.us`)" - traefik.http.routers.staging_midtownplaydio.entrypoints: "websecure" - traefik.http.routers.staging_midtownplaydio.tls: "true" - traefik.http.routers.staging_midtownplaydio.tls.certresolver: "letsencryptresolver" - traefik.http.services.staging_midtownplaydio.loadbalancer.server.port: "3000" - traefik.docker.network: "traefik" - # traefik.http.services.staging_midtownplaydio.loadbalancer.healthcheck.path: "/health" - # traefik.http.services.staging_midtownplaydio.loadbalancer.healthcheck.interval: "30s" - # traefik.http.services.staging_midtownplaydio.loadbalancer.healthcheck.timeout: "5s" + rollback_config: + parallelism: 1 + delay: 10s + order: stop-first + networks: + - traefik + labels: + - traefik.enable=true + - traefik.http.routers.staging_template.rule=Host(`staging.template.nixc.us`) + - traefik.http.routers.staging_template.entrypoints=websecure + - traefik.http.routers.staging_template.tls=true + - traefik.http.routers.staging_template.tls.certresolver=letsencryptresolver + - traefik.http.services.staging_template.loadbalancer.server.port=3000 + # - traefik.http.services.staging_template.loadbalancer.healthcheck.path=/health + # - traefik.http.services.staging_template.loadbalancer.healthcheck.interval=30s + # - traefik.http.services.staging_template.loadbalancer.healthcheck.timeout=5s diff --git a/temp/.gitkeep b/temp/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/temp/build-test-run.log b/temp/build-test-run.log new file mode 100644 index 0000000..7a02eea --- /dev/null +++ b/temp/build-test-run.log @@ -0,0 +1,106 @@ +Build started at Wed Apr 23 10:27:39 EDT 2025 +Building Docker images... +#0 building with "desktop-linux" instance using docker driver + +#1 [template internal] load build definition from Dockerfile +#1 transferring dockerfile: 279B done +#1 DONE 0.0s + +#2 [template internal] load metadata for docker.io/library/alpine:3.18 +#2 DONE 4.5s + +#3 [template internal] load .dockerignore +#3 transferring context: 2B done +#3 DONE 0.0s + +#4 [template 1/3] FROM docker.io/library/alpine:3.18@sha256:de0eb0b3f2a47ba1eb89389859a9bd88b28e82f5826b6969ad604979713c2d4f +#4 resolve docker.io/library/alpine:3.18@sha256:de0eb0b3f2a47ba1eb89389859a9bd88b28e82f5826b6969ad604979713c2d4f 0.0s done +#4 sha256:95459497489f07b9d71d294c852a09f9bbf1af51bb35db752a31f6f48935e293 0B / 3.34MB 0.2s +#4 sha256:95459497489f07b9d71d294c852a09f9bbf1af51bb35db752a31f6f48935e293 1.05MB / 3.34MB 0.3s +#4 sha256:95459497489f07b9d71d294c852a09f9bbf1af51bb35db752a31f6f48935e293 3.34MB / 3.34MB 0.4s done +#4 extracting sha256:95459497489f07b9d71d294c852a09f9bbf1af51bb35db752a31f6f48935e293 0.1s done +#4 DONE 0.5s + +#5 [template 2/3] RUN mkdir -p /scratch /temp +#5 DONE 0.2s + +#6 [template 3/3] WORKDIR /scratch +#6 DONE 0.0s + +#7 [template] exporting to image +#7 exporting layers 0.0s done +#7 exporting manifest sha256:15b202f67217697a010a43b0d8ef636c8bd4a00a7258dc8334ce1220aa5ad10d done +#7 exporting config sha256:e4f5b35710a25e9116a133bde6255ccc3f91a39c9b99e4f4a44d7eaf27024e7d done +#7 exporting attestation manifest sha256:1381754eaa2ff6ca7277a69421f9a2e9bfd02920098acac0b6d9a0d87b4abe9c done +#7 exporting manifest list sha256:59daf10da628c4a24e9396d0656c99dff8d7036f3b29e0ec6d7392c1e72adfc0 done +#7 naming to docker.io/library/template:dev done +#7 unpacking to docker.io/library/template:dev 0.0s done +#7 DONE 0.1s + +#8 [template] resolving provenance for metadata file +#8 DONE 0.0s + template Built +Running tests... +Running tests... +Test results have been saved to ./temp/test_output.log +Test started at Wed Apr 23 10:27:45 EDT 2025 +Testing Docker build... +#0 building with "desktop-linux" instance using docker driver + +#1 [template internal] load build definition from Dockerfile +#1 transferring dockerfile: 279B done +#1 DONE 0.0s + +#2 [template internal] load metadata for docker.io/library/alpine:3.18 +#2 DONE 0.2s + +#3 [template internal] load .dockerignore +#3 transferring context: 2B done +#3 DONE 0.0s + +#4 [template 1/3] FROM docker.io/library/alpine:3.18@sha256:de0eb0b3f2a47ba1eb89389859a9bd88b28e82f5826b6969ad604979713c2d4f +#4 resolve docker.io/library/alpine:3.18@sha256:de0eb0b3f2a47ba1eb89389859a9bd88b28e82f5826b6969ad604979713c2d4f done +#4 DONE 0.0s + +#5 [template 2/3] RUN mkdir -p /scratch /temp +#5 CACHED + +#6 [template 3/3] WORKDIR /scratch +#6 CACHED + +#7 [template] exporting to image +#7 exporting layers done +#7 exporting manifest sha256:15b202f67217697a010a43b0d8ef636c8bd4a00a7258dc8334ce1220aa5ad10d done +#7 exporting config sha256:e4f5b35710a25e9116a133bde6255ccc3f91a39c9b99e4f4a44d7eaf27024e7d done +#7 exporting attestation manifest sha256:ec2582c7e07cfeaaeb69797430b3d687550c642903473dbe1fbcdea58fefc2cb 0.0s done +#7 exporting manifest list sha256:1f3404b565e38ec1490f2d56d612438b611b2fd31e213e39e37c8e3e80c4b3ff done +#7 naming to docker.io/library/template:test done +#7 unpacking to docker.io/library/template:test done +#7 DONE 0.0s + +#8 [template] resolving provenance for metadata file +#8 DONE 0.0s + template Built +Testing container startup... + Network template_default Creating + Network template_default Created + Container template-template-1 Recreate + Container template-template-1 Recreated + Container template-template-1 Starting + Container template-template-1 Started +Container status: +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +Cleaning up... + Container template-template-1 Stopping + Container template-template-1 Stopped + Container template-template-1 Removing + Container template-template-1 Removed + Network template_default Removing + Network template_default Removed +Tests completed at Wed Apr 23 10:27:52 EDT 2025 +Starting services... + Container template-template-1 Creating + Container template-template-1 Created + Container template-template-1 Starting + Container template-template-1 Started +Build and run completed at Wed Apr 23 10:27:53 EDT 2025 diff --git a/temp/test_output.log b/temp/test_output.log new file mode 100644 index 0000000..0c6ed85 --- /dev/null +++ b/temp/test_output.log @@ -0,0 +1,55 @@ +Test started at Wed Apr 23 10:27:45 EDT 2025 +Testing Docker build... +#0 building with "desktop-linux" instance using docker driver + +#1 [template internal] load build definition from Dockerfile +#1 transferring dockerfile: 279B done +#1 DONE 0.0s + +#2 [template internal] load metadata for docker.io/library/alpine:3.18 +#2 DONE 0.2s + +#3 [template internal] load .dockerignore +#3 transferring context: 2B done +#3 DONE 0.0s + +#4 [template 1/3] FROM docker.io/library/alpine:3.18@sha256:de0eb0b3f2a47ba1eb89389859a9bd88b28e82f5826b6969ad604979713c2d4f +#4 resolve docker.io/library/alpine:3.18@sha256:de0eb0b3f2a47ba1eb89389859a9bd88b28e82f5826b6969ad604979713c2d4f done +#4 DONE 0.0s + +#5 [template 2/3] RUN mkdir -p /scratch /temp +#5 CACHED + +#6 [template 3/3] WORKDIR /scratch +#6 CACHED + +#7 [template] exporting to image +#7 exporting layers done +#7 exporting manifest sha256:15b202f67217697a010a43b0d8ef636c8bd4a00a7258dc8334ce1220aa5ad10d done +#7 exporting config sha256:e4f5b35710a25e9116a133bde6255ccc3f91a39c9b99e4f4a44d7eaf27024e7d done +#7 exporting attestation manifest sha256:ec2582c7e07cfeaaeb69797430b3d687550c642903473dbe1fbcdea58fefc2cb 0.0s done +#7 exporting manifest list sha256:1f3404b565e38ec1490f2d56d612438b611b2fd31e213e39e37c8e3e80c4b3ff done +#7 naming to docker.io/library/template:test done +#7 unpacking to docker.io/library/template:test done +#7 DONE 0.0s + +#8 [template] resolving provenance for metadata file +#8 DONE 0.0s + template Built +Testing container startup... + Network template_default Creating + Network template_default Created + Container template-template-1 Recreate + Container template-template-1 Recreated + Container template-template-1 Starting + Container template-template-1 Started +Container status: +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +Cleaning up... + Container template-template-1 Stopping + Container template-template-1 Stopped + Container template-template-1 Removing + Container template-template-1 Removed + Network template_default Removing + Network template_default Removed +Tests completed at Wed Apr 23 10:27:52 EDT 2025 diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100755 index 0000000..169ab4f --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Create temp directory if it doesn't exist +mkdir -p ./temp + +# Run tests and capture output +echo "Running tests..." +echo "Test started at $(date)" > ./temp/test_output.log + +# Example test commands +echo "Testing Docker build..." >> ./temp/test_output.log +docker compose -f docker-compose.test.yml build >> ./temp/test_output.log 2>&1 + +echo "Testing container startup..." >> ./temp/test_output.log +docker compose -f docker-compose.test.yml up -d >> ./temp/test_output.log 2>&1 + +# Wait for container to be ready +sleep 5 + +# Check container status +echo "Container status:" >> ./temp/test_output.log +docker compose -f docker-compose.test.yml ps >> ./temp/test_output.log 2>&1 + +# Clean up +echo "Cleaning up..." >> ./temp/test_output.log +docker compose -f docker-compose.test.yml down >> ./temp/test_output.log 2>&1 + +echo "Tests completed at $(date)" >> ./temp/test_output.log + +# Display results +echo "Test results have been saved to ./temp/test_output.log" +cat ./temp/test_output.log \ No newline at end of file