Skip to content

Dynamic Subpath Support for Deployment#197

Merged
BryonLewis merged 3 commits intomainfrom
subpath-deployment
Jun 30, 2025
Merged

Dynamic Subpath Support for Deployment#197
BryonLewis merged 3 commits intomainfrom
subpath-deployment

Conversation

@BryonLewis
Copy link
Collaborator

@BryonLewis BryonLewis commented Jun 27, 2025

This update should allow for dynamic subpath values that can be used for deploying the application.

Deployment Notes:

  • SUBPATH - New Environment Variable that needs to be added to the .env.prod.docker-compose or other deployment sections. If this is empty (SUBPATH=) it will fall back to old behavior. If it has a subpath it will be added to the client and django for all applications to provide a new example.com/subpath for all values
  • IMPORTANT - the client build process has been updated so if you update your ./dev/.env.prod.docker-compose you need to run the following command before building:
    • source ./dev/export-env.sh ./dev/.env.prod.docker-compose
    • This command prevents needing to copy the .env file into the ./client folder, the build process will do it instead
    • use docker compose -f docker-compose.prod.yml config to confirm that the client: build arguments have the SUBPATH set

Dev/Review Notes:

  • .env.prod.docker-compose.template has a new value SUBPATH if empty it will use default deployment. If it has a value it updates the client build and the django runtime environment variables to support having a subpath
  • Django Updates
    • settings.py now has two new settings that are changed based on the SUBPATH environment varaible
      • STATIC_URL - dynamically set to make sure that static assests in swagger/login are updated to the newer subpath
      • LOGIN_URL - the login page goeas to /oauth which redirects to /accounts/login this makes it so it redirects to {SUBPATH}/accounts/login instead
    • urls.py - This is updated to prefix a path to all the endpoints that are used based on the SUBPATH environment variable
      • Just takes all of the URLPatterns we are already using and changes the path to make them have a different path
  • Client Updates
    • The client dockerfile will now handle building and passing in SUBPATH as VITE_APP_SUBPATH before building so the vite knows what the subpath is.
    • vite-config.js - Updates the base for vite config. This makes it so all assets reference /{Base}/asset instead of direction referencing the asset so the system can handle a subpath
    • router/index.ts the routes need to have the same base value so they append thme to the beginning and sharing the url leads to the proper location.
  • nginx Updates
    • Created a new file nginx.subpath.template that has templated values for subpath in it that can be replaced using a shell script. This file is only used if the subpath is a non-empty value
  • Docker Build Updates
    • Client/NGINX updates
      • Passes in the VITE_APP variables as build arguments as well as SUBPATH.
      • NOTE These arguments are not found in the runtime .env file for the client so they need to be sourced using the ./dev/export.env.sh script before building. That is how these values are properly passed into the system
      • These values are then output into the /client directory as a .env.production file
      • The build /dist file is placed in a tmp location and the nginx.conf and the nginx.subpath.conf are placed in the root location
      • A conditional checks to see if the SUBPATH is empty or not
        • If empty the nginx.conf is copied to /etc/nginx/nginx.conf and the dist directory is placed in /usr/share/nginx/html to be served.
        • If it is not empty a shell script takes the nginx.subpath.conf file and replaces all instances of ${SUBPATH} with the value and uses that as the /etc/nginx/nginx.conf. Then the dist directory is copied to /usr/share/nginx/html/{SUBPATH}/ to be served.

@BryonLewis BryonLewis requested a review from naglepuff June 27, 2025 18:46
@BryonLewis BryonLewis merged commit 2162c29 into main Jun 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant