3cd34056 by Adam Heath

Moqui+postgresql+elasticsearch.

1 parent 7666e6b3
......@@ -5,7 +5,7 @@ FROM ${RUNTIME_IMAGE} AS moqui-base
RUN true \
&& apt-get update \
&& apt-get install unzip less \
&& apt-get install -y unzip less \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& groupadd -g 1000 moqui \
&& useradd -u 1000 -g 1000 -G 0 -d /opt/moqui moqui \
......@@ -13,6 +13,14 @@ RUN true \
&& chown moqui:moqui /opt/moqui \
&& true
FROM moqui-base AS moqui-jdbc-drivers
RUN true \
&& apt-get update \
&& apt-get install -y libpostgresql-jdbc-java \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& true
# build runs as root; attempting to chown all the copied-in files runs
# *very* slow
FROM moqui-base AS moqui-build
......@@ -29,7 +37,7 @@ WORKDIR /opt/moqui
USER moqui
RUN ["unzip", "-o", "/opt/moqui-build/moqui-plus-runtime.war"]
FROM moqui-base AS moqui-run
FROM moqui-base AS moqui-app
MAINTAINER Moqui Framework <moqui@googlegroups.com>
USER moqui
......@@ -39,7 +47,7 @@ COPY --from=moqui-build /opt/moqui/ /opt/moqui/
RUN ["ls", "-l", "/opt/moqui/"]
# create user for search and chown corresponding files
ARG search_name=opensearch
#ARG search_name=opensearch
# This is a fix for previous installs, not needed for new setups.
# upgrade fix #RUN if [ -d runtime/opensearch/bin ]; then echo "Installing OpenSearch User"; \
......@@ -59,8 +67,8 @@ ARG search_name=opensearch
RUN ["mkdir", "-p", "/opt/moqui/runtime/conf", "/opt/moqui/runtime/lib", "/opt/moqui/runtime/classes", "/opt/moqui/runtime/ecomponent"]
VOLUME ["/opt/moqui/runtime/conf", "/opt/moqui/runtime/lib", "/opt/moqui/runtime/classes", "/opt/moqui/runtime/ecomponent"]
# exposed as volumes to persist data outside the container, recommended
RUN ["mkdir", "-p", "/opt/moqui/runtime/log", "/opt/moqui/runtime/txlog", "/opt/moqui/runtime/sessions", "/opt/moqui/runtime/db", "/opt/moqui/runtime/$search_name"]
VOLUME ["/opt/moqui/runtime/log", "/opt/moqui/runtime/txlog", "/opt/moqui/runtime/sessions", "/opt/moqui/runtime/db", "/opt/moqui/runtime/$search_name"]
RUN ["mkdir", "-p", "/opt/moqui/runtime/log", "/opt/moqui/runtime/txlog", "/opt/moqui/runtime/sessions", "/opt/moqui/runtime/db"]
VOLUME ["/opt/moqui/runtime/log", "/opt/moqui/runtime/txlog", "/opt/moqui/runtime/sessions", "/opt/moqui/runtime/db"]
# Main Servlet Container Port
EXPOSE 8080
......
#!/bin/bash
TAG=test-latest
APP=moqui-app
PUSH_TO=docker://5.161.91.120:31234
declare -a images=(moqui-jdbc-drivers moqui-app moqui-jdbc-drivers)
_build() {
for image in "${images[@]}"; do
docker build -f Dockerfile --tag "${image}:${TAG}" --target "${image}" "${APP}"
done
}
_push() {
for image in "${images[@]}"; do
skopeo copy --dest-tls-verify=false "docker-daemon:${image}:${TAG}" "${PUSH_TO}/${image}:${TAG}"
done
}
case "$1" in
(build)
_build
;;
(push)
_push
;;
("")
_build
_push
;;
esac
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: moqui
spec:
version: 8.2.3
nodeSets:
- name: default
count: 2
config:
node.store.allow_mmap: false
---
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: moqui
spec:
version: 8.2.3
count: 1
elasticsearchRef:
name: moqui
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./elasticsearch.yaml
#!/bin/sh
cp -a /usr/share/java/postgresql* /mnt/jdbc-drivers
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./moqui.yaml
configMapGenerator:
- name: moqui-scripts
files:
- ./pg_isready
- ./copy-jdbc-drivers
options:
disableNameSuffixHash: true
---
apiVersion: v1
kind: ConfigMap
metadata:
name: moqui
data:
instance_purpose: production
default_locale: en_US
default_time_zone: US/Central
database_time_zone: US/Central
entity_ds_db_conf: postgres
entity_ds_host: postgresql
entity_ds_port: "5432"
entity_ds_database: moqui
entity_ds_schema: public
_entity_add_missing_runtime: "true"
moqui_load_types: seed,seed-initial,install
---
apiVersion: v1
kind: Secret
metadata:
name: moqui
stringData:
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: moqui-log
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: moqui-txlog
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: moqui-sessions
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Service
metadata:
name: moqui
spec:
type: ClusterIP
selector:
app: moqui
ports:
- name: http-moqui
protocol: TCP
port: 8080
targetPort: 8080
- name: http-hazelcast
protocol: TCP
port: 5701
targetPort: 5701
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: moqui
labels:
app: moqui
spec:
selector:
matchLabels:
app: moqui
template:
metadata:
labels:
app: moqui
spec:
restartPolicy: Always
securityContext:
runAsUser: 0
runAsGroup: 0
volumes:
- name: log
persistentVolumeClaim:
claimName: moqui-log
- name: txlog
persistentVolumeClaim:
claimName: moqui-txlog
- name: sessions
persistentVolumeClaim:
claimName: moqui-sessions
- name: scripts
configMap:
name: moqui-scripts
defaultMode: 0755
- name: lib
emptyDir: {}
initContainers:
- name: copy-jdbc-drivers
image: moqui-jdbc-drivers:latest
command: ["/scripts/copy-jdbc-drivers"]
volumeMounts:
- name: scripts
mountPath: /scripts
- name: lib
mountPath: /mnt/jdbc-drivers
containers:
- name: moqui
image: moqui-app:latest
envFrom:
- configMapRef:
name: moqui
- secretRef:
name: moqui
volumeMounts:
- name: lib
mountPath: /opt/moqui/runtime/lib
- name: log
mountPath: /opt/moqui/runtime/log
- name: txlog
mountPath: /opt/moqui/runtime/txlog
- name: sessions
mountPath: /opt/moqui/runtime/sessions
#!/bin/sh
set -ex
check_pg() {
pg_isready -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" -p 5432
}
while ! check_pg; do
echo "Waiting for database" 1>&2
sleep 1
count=5
while [ $count -gt 0 ] && ! check_pg; do
count=$(($count - 1))
sleep 1
done
done
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./postgresql.yaml
---
apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
name: moqui-postgresql
spec:
enableLogicalBackup: true
teamId: "moqui"
volume:
size: 1Gi
numberOfInstances: 2
users:
zalando: # database owner
- superuser
- createdb
moqui:
- login
databases:
moqui: moqui
postgresql:
version: "14"
---
name: test
namespace: default
elasticsearch:
enabled: true
postgresql:
enabled: true
clone: {}
numberOfInstances: 2
volume:
size: 1Gi
version: "14"
environments:
{{ .Environment.Name }}:
missingFileHandler: Debug
values:
- environments/default-values.yaml
{{- if ne .Environment.Name "default" }}
- environments/{{ .Environment.Name }}-values.yaml
{{- end }}
---
releases:
- name: {{ .Values.name }}-moqui-elasticsearch
condition: elasticsearch.enabled
chart: charts/elasticsearch
namespace: {{ .Values.namespace }}
values:
- namePrefix: {{ .Values.name }}-
- name: {{ .Values.name }}-moqui-postgresql
condition: postgresql.enabled
chart: charts/postgresql
namespace: {{ .Values.namespace }}
values:
- namePrefix: {{ .Values.name }}-
strategicMergePatches:
- apiVersion: acid.zalan.do/v1
kind: postgresql
metadata:
name: {{ .Values.name }}-moqui-postgresql
namespace: {{ .Values.namespace }}
spec:
teamId: {{ .Values.name }}-moqui
volume:
size: {{ .Values.postgresql.volume.size | quote }}
postgresql:
version: {{ .Values.postgresql.version | quote }}
{{- if .Values | get "postgresql.clone.uid" nil }}
clone:
{{ merge .Values.postgresql.clone ( dict "cluster" ( print .Values.name "-moqui-postgresql" ) ) | toYaml | nindent 12 }}
{{- end }}
- name: {{ .Values.name }}-moqui-app
chart: charts/moqui
namespace: {{ .Values.namespace }}
values:
- namePrefix: {{ .Values.name }}-
images:
- name: moqui-app
newName: localhost:31234/moqui-app
newTag: test-latest
- name: moqui-jdbc-drivers
newName: localhost:31234/moqui-jdbc-drivers
newTag: test-latest
strategicMergePatches:
- apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.name }}-moqui
namespace: {{ .Values.namespace }}
labels:
app: {{ .Values.name }}-moqui
spec:
selector:
matchLabels:
app: {{ .Values.name }}-moqui
template:
metadata:
labels:
app: {{ .Values.name }}-moqui
spec:
restartPolicy: Always
securityContext:
runAsUser: 0
runAsGroup: 0
containers:
- name: moqui
env:
{{- if .Values.elasticsearch.enabled }}
- name: elasticsearch_url
value: https://{{ .Values.name }}-moqui-es-http:9200
- name: elasticsearch_user
value: elastic
- name: elasticsearch_password
valueFrom:
secretKeyRef:
name: {{ .Values.name }}-moqui-es-elastic-user
key: elastic
{{- end }}
{{- if .Values.postgresql.enabled }}
- name: entity_ds_db_conf
value: postgres
- name: entity_ds_host
value: {{ .Values.name }}-moqui-postgresql
- name: entity_ds_port
value: "5432"
- name: entity_ds_user
valueFrom:
secretKeyRef:
name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do
key: username
- name: entity_ds_password
valueFrom:
secretKeyRef:
name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do
key: password
- name: entity_ds_database
value: moqui
- name: entity_ds_schema
value: public
{{- end }}