diff --git a/.docker/nginx.apps.conf b/.docker/nginx.apps.conf new file mode 100644 index 0000000..e5b7ba9 --- /dev/null +++ b/.docker/nginx.apps.conf @@ -0,0 +1,34 @@ +server { + listen 8000; + listen [::]:8000; + server_name localhost; + + root /usr/share/nginx/html; + + server_tokens off; + + location ~ /index.html|.*\.toml|.*\.json$ { + expires -1; + add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + } + + location ~ .*\.css$|.*\.js$ { + add_header Cache-Control 'max-age=86400'; # 24h + } + + location ~ .*\.otf$|.*\.ttf$|.*\.woff2?$ { + add_header Cache-Control 'max-age=31536000'; # 1year + } + + location / { + try_files $uri $uri/ /index.html; + + add_header Cache-Control 'max-age=86400'; # 24h + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} + diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..5a8f59a --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,77 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + pull: true + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e60d3c0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +ARG registry=docker.io +FROM ${registry}/library/node:18-slim as nodebuild + +RUN apt-get update +RUN npm install -g npm +RUN npm install -g @angular/cli@17.3.0 + +RUN mkdir /opt/cartosp && chown -R node:node /opt/cartosp +WORKDIR /opt/cartosp +COPY . . +RUN npm install +RUN ng build +RUN chown -R node /opt/cartosp/dist/cartosp/browser +USER node + +FROM ${registry}/nginxinc/nginx-unprivileged:stable + +# USER 101 +COPY --from=nodebuild /opt/cartosp/dist/cartosp/browser/ /usr/share/nginx/html +COPY .docker/nginx.apps.conf /etc/nginx/conf.d/default.conf diff --git a/angular.json b/angular.json index 39287c9..d0338d6 100644 --- a/angular.json +++ b/angular.json @@ -77,6 +77,16 @@ ], "scripts": [ "./node_modules/@gouvfr/dsfr/dist/dsfr/dsfr.module.js" + ], + "allowedCommonJsDependencies": [ + "lodash", + "rbush", + "pbf", + "loglevel", + "eventbusjs", + "node-fetch", + "es6-promise", + "@xmldom/xmldom" ] }, "configurations": { @@ -84,8 +94,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" + "maximumWarning": "5mb", + "maximumError": "10mb" }, { "type": "anyComponentStyle", diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cb4caeb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + + site: + image: cartosp + build: + context: . + dockerfile: Dockerfile + args: + - http_proxy + - https_proxy + ports: + - "8000:8000" + restart: unless-stopped \ No newline at end of file