Skip to content

Commit

Permalink
Docker/workspace testing (#352)
Browse files Browse the repository at this point in the history
Co-authored-by: Adrien Chauve <[email protected]>
  • Loading branch information
iNeoO and achauve authored Jul 18, 2024
1 parent 0548a38 commit 6b15a48
Show file tree
Hide file tree
Showing 22 changed files with 2,684 additions and 11,033 deletions.
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fileignoreconfig:
- filename: docker-compose.prod.yaml
checksum: a9495759b787f06a1d8d5ff1bdb5fad2c9f3cf40e6fad67cad8dddf6fd3e6d15
- filename: docker-compose.yaml
checksum: 66bb0acb17d53ce520538dbc71ef82379a6bc0eb73d9e48711b2d540f9519bb0
checksum: a631fbf33a27c02362e3986094d5f674db98a3265c10c3f8aad9abad6dd43679
- filename: packages/backend/src/config.js
checksum: c0baf7f4f878d3f3406030471f15c092ed9fc671b1e66276fe9b071ea025b58c
- filename: packages/backend/src/controllers/authentication/email/forgotten-password.js
Expand Down Expand Up @@ -195,6 +195,8 @@ fileignoreconfig:
checksum: c792d383dfec26115dfab5a391e6427b5b9c4416da783388c7ef00d4f97585bb
- filename: packages/migrations/src/knexfile.js
checksum: 1d3be5d2c46636eb90b74382447f23ffefc943ed963736ffab7556336d2df667
- filename: packages/shared/src/components/Chat.vue
checksum: f2dbbf72bf098c7abd2c3aee230d220f5a5a106952883c0e116eb49f4f9d4db7
- filename: pg/scripts/01-init.sql
checksum: 20dd5b8d36b1b0517fe185d30003af7866ef5678eed4e7571a6d9797ec3b2a46
- filename: pg/scripts/02/02-1-geo-init.sql
Expand Down
16 changes: 8 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ volumes:
services:
frontend-usagers:
build:
context: packages/frontend-usagers
dockerfile: Dockerfile.local
context: .
dockerfile: packages/frontend-usagers/Dockerfile.local
working_dir: /app
command: /app/entrypoint.sh
command: /app/packages/frontend-usagers/entrypoint.sh
volumes:
- $PWD/packages/frontend-usagers:/app:delegated
- $PWD:/app:delegated
- $HOME/.ssh:/home/node/.ssh:ro
- $HOME/.gitconfig:/home/node/.gitconfig:ro
- $HOME/.npm:/home/node/.npm:delegated
Expand All @@ -29,12 +29,12 @@ services:

frontend-bo:
build:
context: packages/frontend-bo
dockerfile: Dockerfile.local
context: .
dockerfile: packages/frontend-bo/Dockerfile.local
working_dir: /app
command: /app/entrypoint.sh
command: /app/packages/frontend-bo/entrypoint.sh
volumes:
- $PWD/packages/frontend-bo:/app:delegated
- $PWD:/app:delegated
- $HOME/.ssh:/home/node/.ssh:ro
- $HOME/.gitconfig:/home/node/.gitconfig:ro
- $HOME/.npm:/home/node/.npm:delegated
Expand Down
8 changes: 7 additions & 1 deletion packages/backend/src/routes/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ router.post(
);
router.get("/admin/:id", boCheckJWT, messageController.get);
router.get(
"/:id",
"/admin/:declarationId",
boCheckJWT,
checkPermissionDeclarationSejour,
messageController.get,
);
router.get(
"/:declarationId",
checkJWT,
checkPermissionDeclarationSejour,
messageController.get,
Expand Down
18 changes: 9 additions & 9 deletions packages/frontend-bo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ARG NODE_VERSION=20-bullseye-slim
ARG NODE_VERSION=20.15.1-bullseye-slim
FROM node:${NODE_VERSION} AS builder

WORKDIR /app

COPY ./package.json ./yarn.lock ./
RUN yarn --frozen-lockfile

COPY . .
COPY package.json yarn.lock ./
COPY packages/shared/package.json packages/shared/
COPY packages/frontend-bo/package.json packages/frontend-bo/yarn.lock packages/frontend-bo/
RUN yarn workspace @vao/frontend-bo install --frozen-lockfile

# these variables are needed at build time because we produce a *static* app
ARG NUXT_PUBLIC_APP_VERSION=development
Expand All @@ -27,10 +27,10 @@ ENV NUXT_PUBLIC_MATOMO_SITE_ID=$NUXT_PUBLIC_MATOMO_SITE_ID
ENV NUXT_PUBLIC_SENTRY_DSN=$NUXT_PUBLIC_SENTRY_DSN
ENV NUXT_PUBLIC_SENTRY_ENABLED=$NUXT_PUBLIC_SENTRY_ENABLED

# replace environment variables

RUN yarn generate
COPY packages/shared packages/shared
COPY packages/frontend-bo packages/frontend-bo
RUN yarn workspace @vao/frontend-bo generate

FROM ghcr.io/socialgouv/docker/nginx4spa:8.2.3

COPY --from=builder --chown=101:101 /app/.output/public /usr/share/nginx/html
COPY --from=builder --chown=101:101 /app/packages/frontend-bo/.output/public /usr/share/nginx/html
7 changes: 5 additions & 2 deletions packages/frontend-bo/Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ FROM local-node:latest as builder
USER root

WORKDIR /usr/cache

COPY package*.json yarn.lock ./
COPY packages/shared packages/shared/
COPY packages/frontend-bo/package*.json packages/frontend-bo/yarn.lock packages/frontend-bo/

RUN chown -R node /usr/cache

USER node

RUN yarn install
RUN yarn workspace @vao/frontend-bo install --frozen-lockfile

WORKDIR /app

CMD ["yarn", "dev"]
CMD ["yarn" "workspace", "@vao/frontend-bo", "dev"]
11 changes: 5 additions & 6 deletions packages/frontend-bo/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

rm -rf /app/node_modules
cp -r /usr/cache/node_modules /app/node_modules
cp -r /usr/cache/package.json /app/package.json
cp -r /usr/cache/yarn.lock /app/yarn.lock
exec yarn run dev
rm -rf /app/packages/frontend-bo/node_modules
cp -r /usr/cache/packages/frontend-bo/node_modules /app/packages/frontend-bo/node_modules
cp -r /usr/cache/packages/frontend-bo/package*.json /app/packages/frontend-bo/package*.json
cp -r /usr/cache/packages/frontend-bo/yarn.lock /app/packages/frontend-bo/yarn.lock
exec yarn workspace @vao/frontend-bo dev
2 changes: 2 additions & 0 deletions packages/frontend-bo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@pinia/nuxt": "~0.5.1",
"@sentry/vue": "~7.117.0",
"@socialgouv/dsfr-toaster-nuxt-module": "~1.2.1",
"@vao/shared": "1.0.0",
"@vee-validate/i18n": "~4.13.0",
"@vee-validate/rules": "~4.13.0",
"@vueform/multiselect": "~2.6.7",
Expand All @@ -28,6 +29,7 @@
"nuxt-security": "~1.4.0",
"oh-vue-icons": "~1.0.0-rc3",
"pinia": "~2.1.7",
"ufo": "^1.5.4",
"vee-validate": "~4.13.0",
"vue-matomo": "~4.2.0",
"yup": "~1.4.0"
Expand Down
53 changes: 51 additions & 2 deletions packages/frontend-bo/src/pages/sejours/[demandeId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@
:selected="selectedTabIndex === 3"
:asc="asc"
>
<DemandesSejourMessage
<Chat
ref="chatRef"
:messages="demandeStore.messages"
@send="fetchMessages"
:backend-url="`${config.public.backendUrl}/documents/`"
:is-loading="isSendingMessage"
@send="sendMessage"
/>
</DsfrTabContent>
</DsfrTabs>
Expand Down Expand Up @@ -165,6 +168,7 @@

<script setup>
import dayjs from "dayjs";
import { Chat } from "@vao/shared";
import { useIsDownloading } from "~/composables/useIsDownloading";
definePageMeta({
Expand All @@ -180,9 +184,12 @@ const route = useRoute();
const initialSelectedIndex = 0;
const chatRef = ref(null);
const asc = ref(true);
const selectedTabIndex = ref(initialSelectedIndex);
const config = useRuntimeConfig();
const selectTab = (idx) => {
asc.value = selectedTabIndex.value < idx;
selectedTabIndex.value = idx;
Expand Down Expand Up @@ -226,6 +233,48 @@ onMounted(async () => {
}
});
const isSendingMessage = ref(false);
const sendMessage = async ({ message, file }) => {
let newFile;
isSendingMessage.value = true;
if (file) {
try {
const uuid = await UploadFile("message", file);
newFile = {
uuid,
name: file.name ?? "document_messagerie",
createdAt: new Date(),
};
toaster.info(`Document déposé`);
} catch (error) {
log.w(error);
return toaster.error(
`Une erreur est survenue lors du dépôt du document ${file.name}`,
);
}
}
try {
const url = `/message/admin/${route.params.demandeId}`;
const response = await $fetchBackend(url, {
method: "POST",
credentials: "include",
body: { message: message ?? "", file: newFile },
});
if (response.id) {
chatRef.value.resetForm();
}
isSendingMessage.value = false;
} catch (error) {
isSendingMessage.value = false;
log.w("envoi de message : ", { error });
return toaster.error(
`Une erreur est survenue lors de l'envoi de votre message`,
);
}
fetchMessages();
};
const tabTitles = [
{ title: " Formulaire" },
{ title: "Documents joints" },
Expand Down
15 changes: 8 additions & 7 deletions packages/frontend-usagers/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ARG NODE_VERSION=20-bullseye-slim
ARG NODE_VERSION=20.15.1-bullseye-slim
FROM node:${NODE_VERSION} AS builder

WORKDIR /app

COPY ./package.json ./yarn.lock ./
RUN yarn --frozen-lockfile

COPY . .
COPY package.json yarn.lock ./
COPY packages/shared/package.json packages/shared/
COPY packages/frontend-usagers/package.json packages/frontend-usagers/yarn.lock packages/frontend-usagers/
RUN yarn workspace @vao/frontend-usagers install --frozen-lockfile

# these variables are needed at build time because we produce a *static* app
ARG NUXT_PUBLIC_APP_VERSION=development
Expand All @@ -27,9 +27,10 @@ ENV NUXT_PUBLIC_MATOMO_SITE_ID=$NUXT_PUBLIC_MATOMO_SITE_ID
ENV NUXT_PUBLIC_SENTRY_DSN=$NUXT_PUBLIC_SENTRY_DSN
ENV NUXT_PUBLIC_SENTRY_ENABLED=$NUXT_PUBLIC_SENTRY_ENABLED

# replace environment variables
COPY packages/shared packages/shared
COPY packages/frontend-usagers packages/frontend-usagers
RUN yarn workspace @vao/frontend-usagers generate

RUN yarn generate

FROM ghcr.io/socialgouv/docker/nginx4spa:8.2.3

Expand Down
7 changes: 5 additions & 2 deletions packages/frontend-usagers/Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ FROM local-node:latest as builder
USER root

WORKDIR /usr/cache

COPY package*.json yarn.lock ./
COPY packages/shared packages/shared/
COPY packages/frontend-usagers/package*.json packages/frontend-usagers/yarn.lock packages/frontend-usagers/

RUN chown -R node /usr/cache

USER node

RUN yarn install
RUN yarn workspace @vao/frontend-usagers install

WORKDIR /app

CMD ["yarn", "dev"]
CMD ["yarn" "workspace", "@vao/frontend-usagers", "dev"]
10 changes: 5 additions & 5 deletions packages/frontend-usagers/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

rm -rf /app/node_modules
cp -r /usr/cache/node_modules /app/node_modules
cp -r /usr/cache/package.json /app/package.json
cp -r /usr/cache/yarn.lock /app/yarn.lock
exec yarn run dev
rm -rf /app/packages/frontend-usagers/node_modules
cp -r /usr/cache/packages/frontend-usagers/node_modules /app/packages/frontend-usagers/node_modules
cp -r /usr/cache/packages/frontend-usagers/package*.json /app/packages/frontend-usagers/package*.json
cp -r /usr/cache/packages/frontend-usagers/yarn.lock /app/packages/frontend-usagers/yarn.lock
exec yarn workspace @vao/frontend-usagers dev
8 changes: 6 additions & 2 deletions packages/frontend-usagers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@vao/frontend-usagers",
"version": "0.1.1",
"description": "Client pour les usages du projet VAO",
"license": "Apache-2.0",
"scripts": {
"build": "nuxt build",
"dev": "rm -rf /tmp/nitro && nuxt dev",
Expand All @@ -13,10 +14,12 @@
"dependencies": {
"@gouvfr/dsfr": "~1.11.2",
"@gouvminint/vue-dsfr": "~5.17.0",
"@nuxtjs/leaflet": "^1.0.14",
"@nuxtjs/leaflet": "^1.0.14",
"@pinia/nuxt": "~0.5.1",
"@sentry/vue": "~7.117.0",
"@socialgouv/dsfr-toaster-nuxt-module": "~1.2.1",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@vao/shared": "^1.0.0",
"@vee-validate/i18n": "~4.13.0",
"@vee-validate/rules": "~4.13.0",
"@vueform/multiselect": "~2.6.7",
Expand All @@ -33,6 +36,7 @@
"@nuxt/devtools": "^1.3.9",
"@nuxt/eslint-config": "^0.3.6",
"@socialgouv/eslint-config-recommended": "^1.131.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
Expand All @@ -46,4 +50,4 @@
"lint-staged": {
"src/**/*.{js,vue,ts}": "npx eslint --cache --fix"
}
}
}
Loading

0 comments on commit 6b15a48

Please sign in to comment.