diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 000000000..60b5d4e15 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# 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. + +name: Java CI with Maven + +on: + push: + branches: [ "develop-6.2.x" ] + pull_request: + branches: [ "develop-6.2.x" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..e0f15db2e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..dd3cfa63e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM node:12.21.0-buster-slim as base + +# This image is NOT made for production use. +LABEL maintainer="Eero Ruohola " + + +RUN apt-get update \ + && apt-get --assume-yes install \ + libpangocairo-1.0-0 \ + python3 \ + python3-dev \ + python3-pil \ + python3-pip \ + && rm -rf /var/lib/apt/lists/ /var/cache/apt/ + +RUN python3 -m pip install --upgrade pip setuptools wheel django-prometheus \ + && pip3 install 'markupsafe==1.1.1' + +# These invalidate the cache every single time but +# there really isn't any other obvious way to do this. +COPY . /app +WORKDIR /app + +# The dev compose file sets this to 1 to support development and editing the source code. +# The default value of 0 just installs the demo for running. +ARG editable=0 + +RUN if [ "$editable" -eq 1 ]; then pip3 install -r requirements-tests.txt && python3 setup.py build_resources; else pip3 install shuup; fi +RUN pip install django-prometheus +RUN python3 -m shuup_workbench migrate +RUN python3 -m shuup_workbench shuup_init + +RUN echo '\ +from django.contrib.auth import get_user_model\n\ +from django.db import IntegrityError\n\ +try:\n\ + get_user_model().objects.create_superuser("admin", "admin@admin.com", "admin")\n\ +except IntegrityError:\n\ + pass\n'\ +| python3 -m shuup_workbench shell + +CMD ["python3", "-m", "shuup_workbench", "runserver", "0.0.0.0:8000"] diff --git a/alert.rules.yml b/alert.rules.yml new file mode 100644 index 000000000..c12607110 --- /dev/null +++ b/alert.rules.yml @@ -0,0 +1,11 @@ +groups: +- name: SRE_FInal_alerts + rules: + - alert: ElevatedResponseTime + expr: http_request_duration_seconds_mean > 0.5 + for: 1m + labels: + severity: critical + annotations: + summary: "Elevated Response Time Alert" + description: "The average response time has exceeded 0.5 seconds for over 1 minute." diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..e213e7763 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3.7" + +networks: + monitoring: + driver: bridge + +volumes: + prometheus_data: + srefinal_app: + +services: + srefinal_app: + image: srefinal_app + ports: + - "8080:8080" + restart: unless-stopped + networks: + - monitoring + + prometheus: + container_name: prometheus + image: prom/prometheus:latest + volumes: + - /c/Users/gupra/Downloads/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro + - prometheus_data:/prometheus + command: + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.path=/prometheus' + - '--web.console.libraries=/usr/share/prometheus/console_libraries' + - '--web.console.templates=/usr/share/prometheus/consoles' + ports: + - 9091:9090 + depends_on: + - srefinal_app + restart: always + networks: + - monitoring + hostname: prometheus diff --git a/pom.xml b/pom.xml index 26cd3b389..384f19d59 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,15 @@ boot-community-demo-core ${project.version} - + + org.springframework.boot + spring-boot-starter-actuator + + + io.micrometer + micrometer-registry-prometheus + + diff --git a/site/pom.xml b/site/pom.xml index 50ac2f817..c7216b0b7 100644 --- a/site/pom.xml +++ b/site/pom.xml @@ -61,6 +61,11 @@ org.springframework.boot spring-boot-starter-web + + io.micrometer + micrometer-registry-prometheus + 1.12.5 + - + \ No newline at end of file diff --git a/site/src/main/resources/runtime-properties/default.properties b/site/src/main/resources/runtime-properties/default.properties index 471f694da..8f1dbed4d 100644 --- a/site/src/main/resources/runtime-properties/default.properties +++ b/site/src/main/resources/runtime-properties/default.properties @@ -9,6 +9,7 @@ blPU.hibernate.hbm2ddl.auto=create blEventPU.hibernate.hbm2ddl.auto=create +management.endpoints.web.exposure.include=prometheus jmx.app.name=site http.server.port=8080 server.port=8443 diff --git a/site/src/main/resources/webTemplates/catalog/Dockerfile b/site/src/main/resources/webTemplates/catalog/Dockerfile new file mode 100644 index 000000000..dd3cfa63e --- /dev/null +++ b/site/src/main/resources/webTemplates/catalog/Dockerfile @@ -0,0 +1,42 @@ +FROM node:12.21.0-buster-slim as base + +# This image is NOT made for production use. +LABEL maintainer="Eero Ruohola " + + +RUN apt-get update \ + && apt-get --assume-yes install \ + libpangocairo-1.0-0 \ + python3 \ + python3-dev \ + python3-pil \ + python3-pip \ + && rm -rf /var/lib/apt/lists/ /var/cache/apt/ + +RUN python3 -m pip install --upgrade pip setuptools wheel django-prometheus \ + && pip3 install 'markupsafe==1.1.1' + +# These invalidate the cache every single time but +# there really isn't any other obvious way to do this. +COPY . /app +WORKDIR /app + +# The dev compose file sets this to 1 to support development and editing the source code. +# The default value of 0 just installs the demo for running. +ARG editable=0 + +RUN if [ "$editable" -eq 1 ]; then pip3 install -r requirements-tests.txt && python3 setup.py build_resources; else pip3 install shuup; fi +RUN pip install django-prometheus +RUN python3 -m shuup_workbench migrate +RUN python3 -m shuup_workbench shuup_init + +RUN echo '\ +from django.contrib.auth import get_user_model\n\ +from django.db import IntegrityError\n\ +try:\n\ + get_user_model().objects.create_superuser("admin", "admin@admin.com", "admin")\n\ +except IntegrityError:\n\ + pass\n'\ +| python3 -m shuup_workbench shell + +CMD ["python3", "-m", "shuup_workbench", "runserver", "0.0.0.0:8000"]