From f3a02df80e83a7e311aaed6aaa8ad90bc305f97a Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Tue, 27 May 2025 17:44:42 +0200 Subject: [PATCH] Version in self hosted (#770) * Enhance Application Version Management in Docker and Feature Flags - Added a new build argument `APP_VERSION` in the Docker configuration files to facilitate version tracking during builds. - Introduced a private method `getAppVersion` in `FeatureFlagsController` to retrieve the application version from the Docker environment, enhancing the feature flags response with version information. - Updated the `app.php` configuration file to include a new entry for `docker_version`, allowing for better version management and fallback when the Docker build version is unavailable. These changes aim to improve the application's versioning capabilities, ensuring that the version is consistently available across different components and environments. * Refactor OpenFormFooter and Update Feature Flags Handling - Modified `OpenFormFooter.vue` to include a version display when available, enhancing user awareness of the application version. - Refactored the script section to use the ` diff --git a/client/middleware/self-hosted-credentials.js b/client/middleware/self-hosted-credentials.js index be46fbbc..d7d6265b 100644 --- a/client/middleware/self-hosted-credentials.js +++ b/client/middleware/self-hosted-credentials.js @@ -1,11 +1,5 @@ export default defineNuxtRouteMiddleware(async () => { const authStore = useAuthStore() - const featureFlagsStore = useFeatureFlagsStore() - - // Ensure feature flags are loaded - if (!featureFlagsStore.isLoaded) { - await featureFlagsStore.fetchFlags() - } if (useFeatureFlag('self_hosted')) { if (authStore.check && authStore.user?.email === 'admin@opnform.com') { diff --git a/client/plugins/feature-flags.js b/client/plugins/feature-flags.js deleted file mode 100644 index 2c067660..00000000 --- a/client/plugins/feature-flags.js +++ /dev/null @@ -1,10 +0,0 @@ -import { useFeatureFlagsStore } from '~/stores/featureFlags' - -export default defineNuxtPlugin(async () => { - const featureFlagsStore = useFeatureFlagsStore() - - // Load flags if they haven't been loaded yet - if (!featureFlagsStore.isLoaded) { - await featureFlagsStore.fetchFlags() - } -}) \ No newline at end of file diff --git a/client/plugins/featureFlags.js b/client/plugins/featureFlags.js index 35cbca2f..1bcc8b0c 100644 --- a/client/plugins/featureFlags.js +++ b/client/plugins/featureFlags.js @@ -1,9 +1,18 @@ import { useFeatureFlagsStore } from '~/stores/featureFlags' -export default defineNuxtPlugin((nuxtApp) => { - const featureFlagsStore = useFeatureFlagsStore() +export default defineNuxtPlugin(async (nuxtApp) => { + // Get the pinia instance for SSR compatibility + const { $pinia } = nuxtApp - nuxtApp.provide('featureFlag', (key, defaultValue = false) => { - return featureFlagsStore.getFlag(key, defaultValue) - }) + try { + // Pass pinia instance for SSR compatibility + const featureFlagsStore = useFeatureFlagsStore($pinia) + + // Fetch flags during SSR to prevent hydration mismatches + if (!featureFlagsStore.isLoaded) { + await featureFlagsStore.fetchFlags() + } + } catch (error) { + console.error('Feature flags plugin failed:', error) + } }) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c1ca2438..39194bdf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,11 @@ --- services: api: &api-environment - image: jhumanj/opnform-api:latest + build: + context: . + dockerfile: docker/Dockerfile.api + args: + APP_VERSION: "local-test-1.0.0" container_name: opnform-api volumes: &api-environment-volumes - opnform_storage:/usr/share/nginx/html/storage:rw @@ -62,7 +66,11 @@ services: start_period: 70s # Allow time for first scheduled run and cache write ui: - image: jhumanj/opnform-client:latest + build: + context: . + dockerfile: docker/Dockerfile.client + args: + APP_VERSION: "local-test-1.0.0" container_name: opnform-client env_file: - ./client/.env diff --git a/docker/Dockerfile.api b/docker/Dockerfile.api index a2055666..a3e5b9ec 100644 --- a/docker/Dockerfile.api +++ b/docker/Dockerfile.api @@ -27,6 +27,9 @@ RUN composer install --optimize-autoloader --no-interaction \ # Final stage - smaller runtime image FROM php:8.3-fpm-alpine +# Accept version build argument +ARG APP_VERSION=unknown + # Install runtime dependencies RUN apk add --no-cache \ libzip \ @@ -75,6 +78,9 @@ RUN mkdir -p storage/framework/sessions \ # Copy the entire application from the builder stage COPY --from=builder /app/ ./ +# Set version as environment variable (more reliable than file approach) +ENV APP_VERSION_DOCKER=$APP_VERSION + # Setup entrypoint COPY docker/php-fpm-entrypoint /usr/local/bin/opnform-entrypoint RUN chmod a+x /usr/local/bin/*