From 1e5f88f462b0c69db5f6ab8e0249a5905bc6952a Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 3 Feb 2021 20:45:30 -0500 Subject: [PATCH] feat(docker): Check for /app/config volume mount during setup (#826) --- Dockerfile | 2 ++ overseerr-api.yml | 18 +++++++++++ server/routes/index.ts | 7 +++++ server/utils/appDataVolume.ts | 8 +++++ src/components/AppDataWarning/index.tsx | 41 +++++++++++++++++++++++++ src/components/Setup/index.tsx | 2 ++ src/i18n/locale/en.json | 2 ++ 7 files changed, 80 insertions(+) create mode 100644 server/utils/appDataVolume.ts create mode 100644 src/components/AppDataWarning/index.tsx diff --git a/Dockerfile b/Dockerfile index 8b1963415..281ba10e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,8 @@ RUN yarn install --production --ignore-scripts --prefer-offline RUN rm -rf src && \ rm -rf server +RUN touch config/DOCKER + RUN echo "{\"commitTag\": \"${COMMIT_TAG}\"}" > committag.json diff --git a/overseerr-api.yml b/overseerr-api.yml index d90f79adc..1d2cd7bd4 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -1477,6 +1477,24 @@ paths: example: 1.0.0 commitTag: type: string + /status/appdata: + get: + summary: Get /app/data volume status + description: For Docker installs, returns whether or not the /app/data volume mount was configured properly. Always returns true for non-Docker installs. + security: [] + tags: + - public + responses: + '200': + description: /app/data volume status + content: + application/json: + schema: + type: object + properties: + appData: + type: boolean + example: true /settings/main: get: summary: Get main settings diff --git a/server/routes/index.ts b/server/routes/index.ts index 282f0be81..8b90be5a7 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -15,6 +15,7 @@ import personRoutes from './person'; import collectionRoutes from './collection'; import { getAppVersion, getCommitTag } from '../utils/appVersion'; import serviceRoutes from './service'; +import { appDataStatus } from '../utils/appDataVolume'; const router = Router(); @@ -27,6 +28,12 @@ router.get('/status', (req, res) => { }); }); +router.get('/status/appdata', (_req, res) => { + return res.status(200).json({ + appData: appDataStatus(), + }); +}); + router.use('/user', isAuthenticated(Permission.MANAGE_USERS), user); router.get('/settings/public', (_req, res) => { const settings = getSettings(); diff --git a/server/utils/appDataVolume.ts b/server/utils/appDataVolume.ts new file mode 100644 index 000000000..0e42a1a22 --- /dev/null +++ b/server/utils/appDataVolume.ts @@ -0,0 +1,8 @@ +import { existsSync } from 'fs'; +import path from 'path'; + +const DOCKER_PATH = path.join(__dirname, '../../config/DOCKER'); + +export const appDataStatus = (): boolean => { + return !existsSync(DOCKER_PATH); +}; diff --git a/src/components/AppDataWarning/index.tsx b/src/components/AppDataWarning/index.tsx new file mode 100644 index 000000000..c16347e0e --- /dev/null +++ b/src/components/AppDataWarning/index.tsx @@ -0,0 +1,41 @@ +import React from 'react'; +import { defineMessages, useIntl } from 'react-intl'; +import useSWR from 'swr'; +import Alert from '../Common/Alert'; + +const messages = defineMessages({ + dockerVolumeMissing: 'Docker Volume Mount Missing', + dockerVolumeMissingDescription: + 'The /app/config volume mount was not configured properly. All data will be cleared when the container is stopped or restarted.', +}); + +const AppDataWarning: React.FC = () => { + const intl = useIntl(); + const { data, error } = useSWR<{ appData: boolean }>( + '/api/v1/status/appdata' + ); + + if (!data && !error) { + return null; + } + + if (!data) { + return null; + } + + return ( + <> + {!data.appData && ( + + {intl.formatMessage(messages.dockerVolumeMissingDescription, { + code: function code(msg) { + return {msg}; + }, + })} + + )} + + ); +}; + +export default AppDataWarning; diff --git a/src/components/Setup/index.tsx b/src/components/Setup/index.tsx index a3d528088..b6d3de18a 100644 --- a/src/components/Setup/index.tsx +++ b/src/components/Setup/index.tsx @@ -11,6 +11,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import Badge from '../Common/Badge'; import LanguagePicker from '../Layout/LanguagePicker'; import PageTitle from '../Common/PageTitle'; +import AppDataWarning from '../AppDataWarning'; const messages = defineMessages({ setup: 'Setup', @@ -66,6 +67,7 @@ const Setup: React.FC = () => { className="w-auto mx-auto mb-10 max-h-32" alt="Logo" /> +