From d1cf45e1459f039d4385d1ffde5057f1b0180bdb Mon Sep 17 00:00:00 2001 From: Luiggi Tenorio Date: Tue, 11 Jun 2024 10:27:00 +0200 Subject: [PATCH 1/5] initial demo dockerfile --- docker/demo/Dockerfile | 23 +++++++++++++++++++++++ docker/demo/entrypoint.sh | 7 +++++++ 2 files changed, 30 insertions(+) create mode 100644 docker/demo/Dockerfile create mode 100644 docker/demo/entrypoint.sh diff --git a/docker/demo/Dockerfile b/docker/demo/Dockerfile new file mode 100644 index 000000000..9a8fb8117 --- /dev/null +++ b/docker/demo/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.8-slim-bookworm + +# Install apt dependencies +RUN apt-get update && \ + apt-get install -y git graphviz sqlite3 + +RUN pip3 install \ + autosubmit==4.0.105 \ + autosubmit-api==4.0.0b5 \ + jupyterlab + +ENV PROTECTION_LEVEL=NONE + +# Install Autosubmit +RUN autosubmit configure &&\ + autosubmit install + +# Copy entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Set the entrypoint +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/demo/entrypoint.sh b/docker/demo/entrypoint.sh new file mode 100644 index 000000000..94191e25b --- /dev/null +++ b/docker/demo/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Run jupyter lab as daemon +jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root & + +# Run the command passed by docker run +autosubmit_api start -b 0.0.0.0:8000 -- GitLab From 55b5dab2b3a3056ccd6732961c6ce8ac2d4cadb6 Mon Sep 17 00:00:00 2001 From: Luiggi Tenorio Date: Tue, 11 Jun 2024 15:34:23 +0200 Subject: [PATCH 2/5] initial helm chart --- docker/demo/README.md | 55 ++++++++++++++++++++++ docker/demo/helm/.helmignore | 23 +++++++++ docker/demo/helm/Chart.yaml | 24 ++++++++++ docker/demo/helm/templates/deployment.yaml | 32 +++++++++++++ docker/demo/helm/templates/ingress.yaml | 44 +++++++++++++++++ docker/demo/helm/templates/service.yaml | 23 +++++++++ docker/demo/helm/values.yaml | 5 ++ 7 files changed, 206 insertions(+) create mode 100644 docker/demo/README.md create mode 100644 docker/demo/helm/.helmignore create mode 100644 docker/demo/helm/Chart.yaml create mode 100644 docker/demo/helm/templates/deployment.yaml create mode 100644 docker/demo/helm/templates/ingress.yaml create mode 100644 docker/demo/helm/templates/service.yaml create mode 100644 docker/demo/helm/values.yaml diff --git a/docker/demo/README.md b/docker/demo/README.md new file mode 100644 index 000000000..3e56d0e9a --- /dev/null +++ b/docker/demo/README.md @@ -0,0 +1,55 @@ + +## Prepare Minikube + +### Build the docker images inside minikube + +Build the images inside Minikube + +```bash +eval $(minikube docker-env) + +docker build -t as-demo:latest ~/projects/autosubmit/docker/demo +docker build --build-arg "AUTOSUBMIT_API_SOURCE=/api" --build-arg="PUBLIC_URL=/gui"\ + -t as-gui-demo:latest ~/projects/autosubmitreact-update/docker +``` + +The script above use the default names of the images. You can change and set them in the `values.yaml` as you wish. + +### Install Nginx Ingress Controller + +Install nginx Ingress Controller https://kubernetes.github.io/ingress-nginx/deploy/ + +```bash +helm upgrade --install ingress-nginx ingress-nginx \ + --repo https://kubernetes.github.io/ingress-nginx \ + --namespace ingress-nginx --create-namespace +``` + +Enable Ingress for testing + +```bash +minikube addons enable ingress +``` + +## Install using helm + +Install helm + +```bash +helm install test-demo . +``` + + +Clean up helm + +```bash +helm uninstall test-demo +``` + +## Test locally + +Forward nginx ingress controller port 80 to localhost:8080: + +```bash +kubectl port-forward --namespace=ingress-nginx service/ingress-nginx-controller 8080:80 +``` \ No newline at end of file diff --git a/docker/demo/helm/.helmignore b/docker/demo/helm/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/docker/demo/helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/docker/demo/helm/Chart.yaml b/docker/demo/helm/Chart.yaml new file mode 100644 index 000000000..7875694c6 --- /dev/null +++ b/docker/demo/helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: autosubmit-demo +description: A Helm chart for trying Autosubmit tools + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/docker/demo/helm/templates/deployment.yaml b/docker/demo/helm/templates/deployment.yaml new file mode 100644 index 000000000..64f37fedb --- /dev/null +++ b/docker/demo/helm/templates/deployment.yaml @@ -0,0 +1,32 @@ +# Add deployment and service +apiVersion: apps/v1 +kind: Deployment +metadata: + name: autosubmit-deployment + labels: + app: autosubmit-demo +spec: + replicas: 1 + selector: + matchLabels: + app: autosubmit-demo + template: + metadata: + labels: + app: autosubmit-demo + spec: + containers: + # Main Autosubmit docker image with exposed ports 8888 and 8000 + - name: autosubmit-container + image: {{ .Values.images.autosubmitDemo.image }} + imagePullPolicy: Never + ports: + - containerPort: 8888 + - containerPort: 8000 + # GUI docker image with exposed port 3000 + - name: autosubmit-gui-container + image: {{ .Values.images.autosubmitDemoGUI.image }} + imagePullPolicy: Never + ports: + - containerPort: 8080 + diff --git a/docker/demo/helm/templates/ingress.yaml b/docker/demo/helm/templates/ingress.yaml new file mode 100644 index 000000000..cd167eb03 --- /dev/null +++ b/docker/demo/helm/templates/ingress.yaml @@ -0,0 +1,44 @@ +# Add Ingress +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: autosubmit-ingress + annotations: + nginx.ingress.kubernetes.io/use-regex: "true" + nginx.ingress.kubernetes.io/rewrite-target: /$2 +spec: + ingressClassName: nginx + selector: + app: autosubmit-demo + rules: + - host: localhost + http: + paths: + - pathType: ImplementationSpecific + path: "/api(/|$)(.*)" + backend: + service: + name: autosubmit-demo-service + port: + number: 8000 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: autosubmit-ingress-gui +spec: + ingressClassName: nginx + selector: + app: autosubmit-demo + rules: + - host: localhost + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: autosubmit-demo-service + port: + number: 8888 + \ No newline at end of file diff --git a/docker/demo/helm/templates/service.yaml b/docker/demo/helm/templates/service.yaml new file mode 100644 index 000000000..1432a0d32 --- /dev/null +++ b/docker/demo/helm/templates/service.yaml @@ -0,0 +1,23 @@ +# Add service +apiVersion: v1 +kind: Service +metadata: + name: autosubmit-demo-service + labels: + app: autosubmit-demo +spec: + selector: + app: autosubmit-demo + ports: + - name: jupyterlab-port + protocol: TCP + port: 8888 + targetPort: 8888 + - name: api-port + protocol: TCP + port: 8000 + targetPort: 8000 + - name: gui-port + protocol: TCP + port: 8080 + targetPort: 8080 diff --git a/docker/demo/helm/values.yaml b/docker/demo/helm/values.yaml new file mode 100644 index 000000000..c1ad6603f --- /dev/null +++ b/docker/demo/helm/values.yaml @@ -0,0 +1,5 @@ +images: + autosubmitDemo: + image: as-demo + autosubmitDemoGUI: + image: as-gui-demo -- GitLab From 9ba663ca540b9a7e48687da8508fd94a3140b957 Mon Sep 17 00:00:00 2001 From: Luiggi Tenorio Date: Wed, 12 Jun 2024 12:08:19 +0200 Subject: [PATCH 3/5] fix subpath ingress --- docker/demo/Dockerfile | 2 +- docker/demo/README.md | 2 +- docker/demo/entrypoint.sh | 2 +- docker/demo/helm/templates/ingress.yaml | 12 ++++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docker/demo/Dockerfile b/docker/demo/Dockerfile index 9a8fb8117..01e7c5495 100644 --- a/docker/demo/Dockerfile +++ b/docker/demo/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get update && \ RUN pip3 install \ autosubmit==4.0.105 \ - autosubmit-api==4.0.0b5 \ + autosubmit-api==4.0.0b8 \ jupyterlab ENV PROTECTION_LEVEL=NONE diff --git a/docker/demo/README.md b/docker/demo/README.md index 3e56d0e9a..b86253b06 100644 --- a/docker/demo/README.md +++ b/docker/demo/README.md @@ -48,7 +48,7 @@ helm uninstall test-demo ## Test locally -Forward nginx ingress controller port 80 to localhost:8080: +Forward nginx ingress controller port `80` to `localhost:8080`: ```bash kubectl port-forward --namespace=ingress-nginx service/ingress-nginx-controller 8080:80 diff --git a/docker/demo/entrypoint.sh b/docker/demo/entrypoint.sh index 94191e25b..b26154217 100644 --- a/docker/demo/entrypoint.sh +++ b/docker/demo/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash # Run jupyter lab as daemon -jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root & +jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.base_url=/jupyterlab & # Run the command passed by docker run autosubmit_api start -b 0.0.0.0:8000 diff --git a/docker/demo/helm/templates/ingress.yaml b/docker/demo/helm/templates/ingress.yaml index cd167eb03..47cd29bbe 100644 --- a/docker/demo/helm/templates/ingress.yaml +++ b/docker/demo/helm/templates/ingress.yaml @@ -1,4 +1,4 @@ -# Add Ingress +# Rewrite ingress apiVersion: networking.k8s.io/v1 kind: Ingress metadata: @@ -22,6 +22,7 @@ spec: port: number: 8000 --- +# Prefix ingress apiVersion: networking.k8s.io/v1 kind: Ingress metadata: @@ -35,10 +36,17 @@ spec: http: paths: - pathType: Prefix - path: "/" + path: "/jupyterlab" backend: service: name: autosubmit-demo-service port: number: 8888 + - pathType: Prefix + path: "/gui" + backend: + service: + name: autosubmit-demo-service + port: + number: 8080 \ No newline at end of file -- GitLab From 6faceafa6a68b66bdb807251b2b2af1fe859ef5e Mon Sep 17 00:00:00 2001 From: Luiggi Tenorio Date: Thu, 13 Jun 2024 13:40:24 +0200 Subject: [PATCH 4/5] remove cache, add version args & clean ingress --- docker/demo/Dockerfile | 13 ++++++++++--- docker/demo/helm/templates/ingress.yaml | 4 ---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docker/demo/Dockerfile b/docker/demo/Dockerfile index 01e7c5495..ac3be4ba6 100644 --- a/docker/demo/Dockerfile +++ b/docker/demo/Dockerfile @@ -2,13 +2,20 @@ FROM python:3.8-slim-bookworm # Install apt dependencies RUN apt-get update && \ - apt-get install -y git graphviz sqlite3 + apt-get install -y git graphviz sqlite3 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install Autosubmit +ARG AUTOSUBMIT_VERSION=4.0.105 +ARG AUTOSUBMIT_API_VERSION=4.0.0b8 RUN pip3 install \ - autosubmit==4.0.105 \ - autosubmit-api==4.0.0b8 \ + autosubmit==${AUTOSUBMIT_VERSION} \ + autosubmit-api==${AUTOSUBMIT_API_VERSION} \ jupyterlab +# Set the environment variables ENV PROTECTION_LEVEL=NONE # Install Autosubmit diff --git a/docker/demo/helm/templates/ingress.yaml b/docker/demo/helm/templates/ingress.yaml index 47cd29bbe..973f734d1 100644 --- a/docker/demo/helm/templates/ingress.yaml +++ b/docker/demo/helm/templates/ingress.yaml @@ -8,8 +8,6 @@ metadata: nginx.ingress.kubernetes.io/rewrite-target: /$2 spec: ingressClassName: nginx - selector: - app: autosubmit-demo rules: - host: localhost http: @@ -29,8 +27,6 @@ metadata: name: autosubmit-ingress-gui spec: ingressClassName: nginx - selector: - app: autosubmit-demo rules: - host: localhost http: -- GitLab From 76dbd5298006c240efe528a8dd2af14ee3c42328 Mon Sep 17 00:00:00 2001 From: Luiggi Tenorio Date: Thu, 13 Jun 2024 14:30:27 +0200 Subject: [PATCH 5/5] paramertrize more values --- docker/demo/helm/templates/deployment.yaml | 4 ++-- docker/demo/helm/templates/ingress.yaml | 4 ++-- docker/demo/helm/values.yaml | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docker/demo/helm/templates/deployment.yaml b/docker/demo/helm/templates/deployment.yaml index 64f37fedb..2482ccd9f 100644 --- a/docker/demo/helm/templates/deployment.yaml +++ b/docker/demo/helm/templates/deployment.yaml @@ -19,14 +19,14 @@ spec: # Main Autosubmit docker image with exposed ports 8888 and 8000 - name: autosubmit-container image: {{ .Values.images.autosubmitDemo.image }} - imagePullPolicy: Never + imagePullPolicy: {{ .Values.images.autosubmitDemo.imagePullPolicy }} ports: - containerPort: 8888 - containerPort: 8000 # GUI docker image with exposed port 3000 - name: autosubmit-gui-container image: {{ .Values.images.autosubmitDemoGUI.image }} - imagePullPolicy: Never + imagePullPolicy: {{ .Values.images.autosubmitDemoGUI.imagePullPolicy }} ports: - containerPort: 8080 diff --git a/docker/demo/helm/templates/ingress.yaml b/docker/demo/helm/templates/ingress.yaml index 973f734d1..733096deb 100644 --- a/docker/demo/helm/templates/ingress.yaml +++ b/docker/demo/helm/templates/ingress.yaml @@ -9,7 +9,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: localhost + - host: {{ .Values.ingress.host }} http: paths: - pathType: ImplementationSpecific @@ -28,7 +28,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: localhost + - host: {{ .Values.ingress.host }} http: paths: - pathType: Prefix diff --git a/docker/demo/helm/values.yaml b/docker/demo/helm/values.yaml index c1ad6603f..5322d4e3a 100644 --- a/docker/demo/helm/values.yaml +++ b/docker/demo/helm/values.yaml @@ -1,5 +1,10 @@ images: autosubmitDemo: image: as-demo + imagePullPolicy: Never autosubmitDemoGUI: image: as-gui-demo + imagePullPolicy: Never + +ingress: + host: localhost \ No newline at end of file -- GitLab