Skip to content

Instantly share code, notes, and snippets.

@kirillkrylov
Last active September 28, 2023 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirillkrylov/b55451a1dcabd216f8f984eda53c0cd9 to your computer and use it in GitHub Desktop.
Save kirillkrylov/b55451a1dcabd216f8f984eda53c0cd9 to your computer and use it in GitHub Desktop.
Creation in Kubernetes with remote debugger through SSH

Image worker-dev

ARG NetCoreVersion=6.0
ARG AspEnvironment=Development

FROM mcr.microsoft.com/dotnet/sdk:${NetCoreVersion}
ENV ASPNETCORE_ENVIRONMENT=${AspEnvironment} TZ=Europe/Kiev

RUN apt-get update && apt-get -y install openssh-server unzip curl

# SSH SERVER CONFIGURATION REQUIRED FOR REMOTE DUGGING
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#Port 22/Port 22/' /etc/ssh/sshd_config
RUN sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config
RUN sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config
RUN sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

# RIDER - BUT IT DOES NOT WORK, YET
COPY ./RiderRemoteDebuggingTools /root/.local/share/JetBrains/RiderRemoteDebugger/2023.2.2
RUN mkdir -p /root/.local/share/JetBrains/RiderRemoteDebugger/2023.2.2

#VISUAL STUDIO
RUN mkdir /root/.vs-debugger
RUN chmod -R 777 /root 


RUN apt-get update && apt-get -y --no-install-recommends install \
    libgdiplus \
    libc6-dev \
    gss-ntlmssp && \
    apt-get clean all && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/* && \
    sed -i 's/openssl_conf/#openssl_conf/g' /etc/ssl/openssl.cnf

COPY entrypoint.sh entrypoint.sh
RUN chmod 777 entrypoint.sh
RUN mkdir /app && chmod -R 777 /app

WORKDIR / 
EXPOSE 22 5000 5002
ENTRYPOINT ["/entrypoint.sh"]

File: entrypoint.sh

#!/bin/sh

# start ssh server
service ssh start;

cd /app;

# start creatio app server
dotnet Terrasoft.WebHost.dll;

Image creatio/8.1.1.1351

FROM busybox

COPY init-entrypoint.sh init-entrypoint.sh
RUN chmod +x /init-entrypoint.sh
RUN mkdir app && chmod 777 app
COPY ./8.1.1.1351 /Data

File: init-entrypoint.sh

#!/bin/sh

SRC_DIR="/Data"
DEST_DIR="/app"

if [ -n "$(ls -A "$DEST_DIR")" ]; then
  echo "The directory '$DEST_DIR' is not empty. Do nothing"
  exit 0
else
  /bin/mv $SRC_DIR/* $DEST_DIR
  /bin/chmod -R 777 $DEST_DIR
  exit 0
fi

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: creatio
  namespace: clio-infrastructure
spec:
  selector:
    matchLabels:
      app: creatio
  replicas: 1
  template:
    metadata:
      labels:
        app: creatio
    spec:
      initContainers:
        - name: copy-volume-data
          imagePullPolicy: "Never"
          image: creatio/8.1.1.1351
          command: ["/bin/sh", "-c", "./init-entrypoint.sh"]
          volumeMounts:
            - mountPath: /app
              name: app
      containers:
        - name: creatio
          image: creatio/worker-dev:latest
          imagePullPolicy: "Never"
          resources:
            requests:
              cpu: "0.25"
              memory: "2Gi"
            limits:
              cpu: "2"
              memory: "4Gi"
          ports:
            - containerPort: 5000
              name: creatio-http
            - containerPort: 22
              name: creatio-ssh
          volumeMounts:
            - mountPath: /app
              name: app
      volumes:
      - name: app
        persistentVolumeClaim:
          claimName: creatio-app-pvc

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: creatio-app-pvc
  namespace: clio-infrastructure
  labels:
    app: creatio
spec:
  storageClassName: clio-storage
  accessModes:
    - ReadWriteOnce
  volumeName: creatio-app-pv
  resources:
    requests:
      storage: 5Gi

---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: creatio-app-pv
  labels:
    type: local
    app: creatio
spec:
  storageClassName: clio-storage
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/clio-infrastructure/creatio-worker"

---
apiVersion: v1
kind: Service
metadata:
  name: creatio
  namespace: clio-infrastructure
  labels:
    app: creatio
spec:
  selector:
    app: creatio
  type: NodePort
  ports:
   - port: 5000
     nodePort: 30500
     name: creatio-http
   - port: 22
     nodePort: 30522
     name: creatio-ssh
   - port: 23
     nodePort: 30523
     name: rider-debugger


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment