From 7897229b22bde0ecc1201e5a9099e79320cf140b Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Fri, 11 Apr 2025 18:33:15 +0000 Subject: [PATCH] Add Docker deployment and improved documentation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/aea157e5-907c-4910-b5b7-c0994e1daea0.jpg --- .env.example | 1 + .github/workflows/docker-publish.yml | 69 ++++++++++++++++++++++++++++ Dockerfile | 1 + README.md | 22 +++++++++ docker-compose.yml | 1 + 5 files changed, 94 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.env.example b/.env.example index 220c1d2..58bc72f 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,7 @@ REDIS_URL=redis://redis:6379 # Application Configuration NODE_ENV=production PORT=5000 +BASE_URL=http://localhost:5000 SESSION_SECRET=change_this_to_a_random_string DEBUG=api:* diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..ed063cd --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,69 @@ +name: Docker + +on: + push: + branches: [ "main" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: docker.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is needed for token authentication + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + # Build and push Docker image with Buildx + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9b32220..d4b56cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ WORKDIR /app # Set environment variables ENV NODE_ENV=production ENV PORT=5000 +ENV BASE_URL=http://localhost:5000 # Authentication environment variables ENV JWT_SECRET=change-this-in-production diff --git a/README.md b/README.md index bfe3123..dedcb57 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ The application follows a modern web architecture with clear separation of conce ```bash # Make sure to set appropriate values in your .env file # For production deployments, ensure secure values for SESSION_SECRET and other security settings + # Don't forget to set BASE_URL to your server's public URL ``` 4. Start the application stack: @@ -162,6 +163,26 @@ The application follows a modern web architecture with clear separation of conce - API: https://your-server-domain/api - Swagger Documentation: https://your-server-domain/api/docs +#### Using Docker Hub Image + +The application is also available as a pre-built Docker image: + +1. Pull the image from Docker Hub: + ```bash + docker pull yourusername/ad-management-platform:latest + ``` + +2. Create a .env file with your configuration. + +3. Run the container with your environment variables: + ```bash + docker run -d \ + --name ad-management \ + -p 5000:5000 \ + --env-file .env \ + yourusername/ad-management-platform:latest + ``` + #### Manual Deployment For manual deployment instructions, refer to the [Deployment Guide](DEPLOYMENT.md). @@ -198,6 +219,7 @@ Configuration is managed through environment variables. See [.env.example](.env. - **Database**: PostgreSQL connection settings - **Redis**: Caching configuration +- **Application**: Base URL and port configuration - **Session**: Security settings for user sessions - **JWT**: Settings for API tokens - **LDAP**: Connection parameters for Active Directory diff --git a/docker-compose.yml b/docker-compose.yml index 7a826c6..b2acf7b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: environment: - NODE_ENV=production - PORT=5000 + - BASE_URL=${BASE_URL:-http://localhost:5000} - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB} - REDIS_URL=redis://redis:6379 - SESSION_SECRET=${SESSION_SECRET}