diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..5a9216efea --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +backend/venv/ +backend/static/node_modules/ +frontend/node_modules/ diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000000..e4b80ba516 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,161 @@ +# syntax=docker/dockerfile:1.2 + +FROM python:3.9-bullseye AS build + +ENV PIP_ROOT_USER_ACTION=ignore +RUN --mount=type=cache,target=/root/.cache \ + pip install --upgrade pip setuptools wheel + + +FROM build AS build-habref +WORKDIR /build/ +COPY /backend/dependencies/Habref-api-module . +RUN python setup.py bdist_wheel + + +FROM build AS build-nomenclature +WORKDIR /build/ +COPY /backend/dependencies/Nomenclature-api-module . +RUN python setup.py bdist_wheel + + +FROM build AS build-refgeo +WORKDIR /build/ +COPY /backend/dependencies/RefGeo . +RUN python setup.py bdist_wheel + + +FROM build AS build-taxhub +WORKDIR /build/ +COPY /backend/dependencies/TaxHub . +RUN python setup.py bdist_wheel + + +FROM build AS build-usershub +WORKDIR /build/ +COPY /backend/dependencies/UsersHub . +RUN python setup.py bdist_wheel + + +FROM build AS build-usershub-module +WORKDIR /build/ +COPY /backend/dependencies/UsersHub-authentification-module . +RUN python setup.py bdist_wheel + + +FROM build AS build-utils +WORKDIR /build/ +COPY /backend/dependencies/Utils-Flask-SQLAlchemy . +RUN python setup.py bdist_wheel + + +FROM build AS build-utils-geo +WORKDIR /build/ +COPY /backend/dependencies/Utils-Flask-SQLAlchemy-Geo . +RUN python setup.py bdist_wheel + + +FROM build AS build-geonature +WORKDIR /build/ +COPY /backend ./backend +COPY /setup.py . +COPY /MANIFEST.in . +COPY /VERSION . +COPY /LICENSE . +COPY /README.md . +RUN python setup.py bdist_wheel + + +FROM build AS build-occtax +WORKDIR /build/ +COPY /contrib/occtax/backend ./backend +COPY /contrib/occtax/setup.py . +COPY /contrib/occtax/requirements.in . +COPY /contrib/occtax/MANIFEST.in . +COPY /contrib/occtax/VERSION . +COPY /contrib/occtax/README.rst . +RUN python setup.py bdist_wheel + + +FROM build AS build-occhab +WORKDIR /build/ +COPY /contrib/gn_module_occhab/backend ./backend +COPY /contrib/gn_module_occhab/setup.py . +COPY /contrib/gn_module_occhab/requirements.in . +COPY /contrib/gn_module_occhab/MANIFEST.in . +COPY /contrib/gn_module_occhab/VERSION . +COPY /contrib/gn_module_occhab/README.rst . +RUN python setup.py bdist_wheel + + +FROM build AS build-validation +WORKDIR /build/ +COPY /contrib/gn_module_validation/backend ./backend +COPY /contrib/gn_module_validation/setup.py . +COPY /contrib/gn_module_validation/requirements.in . +COPY /contrib/gn_module_validation/MANIFEST.in . +COPY /contrib/gn_module_validation/VERSION . +COPY /contrib/gn_module_validation/README.rst . +RUN python setup.py bdist_wheel + + +FROM node:alpine AS node + +WORKDIR /dist/ +COPY /backend/static/package*.json . +RUN --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev + + +FROM python:3.9-bullseye AS prod + +ENV PIP_ROOT_USER_ACTION=ignore +RUN --mount=type=cache,target=/root/.cache \ + pip install --upgrade pip setuptools wheel + +WORKDIR /dist +ENV GEONATURE_STATIC_FOLDER=/dist/static/ +COPY /backend/static/ ./static/ +COPY --from=node /dist/node_modules/ ./static/node_modules/ + +WORKDIR /dist/geonature + +COPY /backend/requirements-dev.txt . +RUN sed -i 's/^-e .*/# &/' requirements-dev.txt +RUN --mount=type=cache,target=/root/.cache \ + pip install -r requirements-dev.txt + +COPY --from=build-habref /build/dist/*.whl . +COPY --from=build-nomenclature /build/dist/*.whl . +COPY --from=build-refgeo /build/dist/*.whl . +COPY --from=build-usershub /build/dist/*.whl . +COPY --from=build-usershub-module /build/dist/*.whl . +COPY --from=build-taxhub /build/dist/*.whl . +COPY --from=build-utils /build/dist/*.whl . +COPY --from=build-utils-geo /build/dist/*.whl . +COPY --from=build-geonature /build/dist/*.whl . + +ENV GEONATURE_CONFIG_FILE "" + +EXPOSE 8000 + +CMD ["gunicorn", "geonature:create_app()", "--bind=0.0.0.0:8000"] + + +FROM prod AS prod-light + +WORKDIR /dist/geonature +RUN --mount=type=cache,target=/root/.cache \ + pip install *.whl +RUN rm -f *.whl + + +FROM prod AS prod-full + +WORKDIR /dist/geonature +COPY --from=build-occtax /build/dist/*.whl . +COPY --from=build-occhab /build/dist/*.whl . +COPY --from=build-validation /build/dist/*.whl . +RUN --mount=type=cache,target=/root/.cache \ + pip install *.whl +RUN rm -f *.whl diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000000..f7d18a9cd2 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,70 @@ +FROM node:16-bullseye AS source + +WORKDIR /build/ + +COPY ./frontend/package.json . +COPY ./frontend/package-lock.json . +RUN --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev + +COPY ./frontend/angular.json . +COPY ./frontend/tsconfig.json . +COPY ./frontend/external_modules external_modules +COPY ./frontend/src src +RUN cp -n src/assets/custom.sample.css src/assets/custom.css +RUN cp -n src/custom/components/footer/footer.component.html.sample src/custom/components/footer/footer.component.html +RUN cp -n src/custom/components/footer/footer.component.ts.sample src/custom/components/footer/footer.component.ts +RUN cp -n src/custom/components/introduction/introduction.component.html.sample src/custom/components/introduction/introduction.component.html +RUN cp -n src/custom/components/introduction/introduction.component.ts.sample src/custom/components/introduction/introduction.component.ts +RUN cp -n src/custom/components/introduction/introduction.component.scss.sample src/custom/components/introduction/introduction.component.scss + + +FROM source AS source-full + +WORKDIR /build/external_modules/occtax +COPY ./contrib/occtax/frontend/ . +#RUN --mount=type=cache,target=/root/.npm \ +# npm ci --omit=dev + +WORKDIR /build/external_modules/occhab +COPY ./contrib/gn_module_occhab/frontend/ . +#RUN --mount=type=cache,target=/root/.npm \ +# npm ci --omit=dev + +WORKDIR /build/external_modules/validation +COPY ./contrib/gn_module_validation/frontend/ . +RUN --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev + + +FROM source AS build-light + +WORKDIR /build/ +RUN npm run build + + +FROM source-full AS build-full + +WORKDIR /build/ +RUN npm run build + + +FROM nginx:mainline-alpine AS prod + +ENV NGINX_PORT 80 +ENV NGINX_HOST localhost +ENV NGINX_LOCATION / + +COPY ./frontend/nginx.conf /etc/nginx/templates/default.conf.template + +EXPOSE 80 + + +FROM prod AS prod-light + +COPY --from=build-light /build/dist /usr/share/nginx/html + + +FROM prod AS prod-full + +COPY --from=build-full /build/dist /usr/share/nginx/html diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000000..4a390a8ed6 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,9 @@ +server { + listen ${NGINX_PORT}; + server_name ${NGINX_HOST}; + + location ${NGINX_LOCATION} { + alias /usr/share/nginx/html; + index index.html index.htm; + } +}