diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9a4183e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +kube/ +api/bruno/ +LICENSE +README.md +# Ignore the other Dockerfile when building one +docker/*.Dockerfile +skaffold.yaml diff --git a/api/bruno/environments/LOCAL.bru b/api/bruno/environments/LOCAL.bru index 379db24..7923dab 100644 --- a/api/bruno/environments/LOCAL.bru +++ b/api/bruno/environments/LOCAL.bru @@ -1,5 +1,5 @@ vars { - BASE_URL: http://localhost:3000 + BASE_URL: http://localhost:30000 } vars:secret [ USERNAME, diff --git a/Dockerfile b/docker/api.Dockerfile similarity index 100% rename from Dockerfile rename to docker/api.Dockerfile diff --git a/docker/api.Dockerfile.dockerignore b/docker/api.Dockerfile.dockerignore new file mode 100644 index 0000000..1b968a4 --- /dev/null +++ b/docker/api.Dockerfile.dockerignore @@ -0,0 +1,9 @@ +kube +.vscode +.secrets +.github +migrations +docker +.env +kube +api diff --git a/docker/migrator.Dockerfile b/docker/migrator.Dockerfile new file mode 100644 index 0000000..1958016 --- /dev/null +++ b/docker/migrator.Dockerfile @@ -0,0 +1,9 @@ +FROM neo4j:community-trixie + +WORKDIR /migrator + +RUN mkdir migrations + +COPY ./migrations ./migrations + +CMD [ "cypher-shell", "--help" ] diff --git a/docker/migrator.Dockerfile.dockeringore b/docker/migrator.Dockerfile.dockeringore new file mode 100644 index 0000000..a6635f6 --- /dev/null +++ b/docker/migrator.Dockerfile.dockeringore @@ -0,0 +1,8 @@ +kube +docker +internal +cmd +.backups +.github +.secrets +api diff --git a/kube/api/api.configmap.yaml b/kube/api/api.configmap.yaml new file mode 100644 index 0000000..dc671cb --- /dev/null +++ b/kube/api/api.configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: dotpen-api.cfg +data: + NEO4J_URI: bolt://gopen-db + NEO4J_USERNAME: neo4j + NEO4J_PASSWORD: testpassword + JWT_SIGN: 74JkywUHV3tmT9Yj7r4gsH22Md5Df45n \ No newline at end of file diff --git a/kube/api/api.deployment.yaml b/kube/api/api.deployment.yaml new file mode 100644 index 0000000..a82679d --- /dev/null +++ b/kube/api/api.deployment.yaml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + deployment.kubernetes.io/revision: "1" + labels: + app: gopen + name: gopen-api +spec: + progressDeadlineSeconds: 30 + replicas: 3 + revisionHistoryLimit: 6 + selector: + matchLabels: + app: gopen-api + strategy: + rollingUpdate: + maxSurge: 2 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + app: gopen-api + spec: + containers: + - image: gopen-api:latest + imagePullPolicy: IfNotPresent + name: gopen-api + envFrom: + - configMapRef: + name: dotpen-api.cfg + ports: + - containerPort: 3000 + protocol: TCP + livenessProbe: + httpGet: + path: health + port: 3000 + initialDelaySeconds: 2 + failureThreshold: 1 + successThreshold: 1 + resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 500m + memory: 512Mi + restartPolicy: Always diff --git a/kube/api/api.service.yaml b/kube/api/api.service.yaml new file mode 100644 index 0000000..a6ac908 --- /dev/null +++ b/kube/api/api.service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: gopen + name: gopen-api +spec: + ports: + - nodePort: 30000 + port: 3000 + protocol: TCP + targetPort: 3000 + selector: + app: gopen-api + type: NodePort diff --git a/kube/db/data.pvc.yaml b/kube/db/data.pvc.yaml new file mode 100644 index 0000000..a63a849 --- /dev/null +++ b/kube/db/data.pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: gopen-data.pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 500Mi \ No newline at end of file diff --git a/kube/db/db.configmap.yaml b/kube/db/db.configmap.yaml new file mode 100644 index 0000000..4bd37bd --- /dev/null +++ b/kube/db/db.configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: gopen-db.cfg +data: + NEO4J_AUTH: neo4j/testpassword diff --git a/kube/db/db.deployment.yaml b/kube/db/db.deployment.yaml new file mode 100644 index 0000000..364d0ce --- /dev/null +++ b/kube/db/db.deployment.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + deployment.kubernetes.io/revision: "1" + labels: + app: gopen + name: gopen-db +spec: + replicas: 1 + revisionHistoryLimit: 1 + selector: + matchLabels: + app: gopen-db + template: + metadata: + labels: + app: gopen-db + spec: + volumes: + - name: gopen-data-volume + persistentVolumeClaim: + claimName: gopen-data.pvc + containers: + - image: neo4j:community-trixie + name: gopen-db + envFrom: + - configMapRef: + name: gopen-db.cfg + ports: + - containerPort: 7687 + protocol: TCP + volumeMounts: + - mountPath: /data + name: gopen-data-volume + readinessProbe: + exec: + command: + [ + "cypher-shell", + "-u", + "neo4j", + "-p", + "testpassword", + "--access-mode=read", + "RETURN 0", + ] + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 60 + resources: + requests: + memory: "512Mi" + cpu: "250m" + limits: + memory: "1Gi" + cpu: "500m" + restartPolicy: Always diff --git a/kube/db/db.service.yaml b/kube/db/db.service.yaml new file mode 100644 index 0000000..a91042d --- /dev/null +++ b/kube/db/db.service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: gopen + name: gopen-db +spec: + selector: + app: gopen-db + ports: + - nodePort: 31000 + port: 7687 + protocol: TCP + targetPort: 7687 + type: NodePort diff --git a/kube/jobs/jobs.yaml b/kube/jobs/jobs.yaml new file mode 100644 index 0000000..faf52a1 --- /dev/null +++ b/kube/jobs/jobs.yaml @@ -0,0 +1,82 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: gopen-db-setup +spec: + template: + spec: + containers: + - name: setup + image: gopen-db-migrator + imagePullPolicy: IfNotPresent + command: + [ + "cypher-shell", + "-a", + "bolt://gopen-db", + "-u", + "neo4j", + "-p", + "testpassword", + "-f", + "/migrator/migrations/setup.cypher", + ] + readinessProbe: + exec: + command: + [ + "cypher-shell", + "-a", + "bolt://gopen-db", + "-u", + "neo4j", + "-p", + "testpassword", + "--access-mode=read", + "RETURN 0", + ] + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 60 + restartPolicy: Never + backoffLimit: 4 +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: gopen-db-hydrate +spec: + template: + spec: + containers: + - name: hydrate + image: gopen-db-migrator + imagePullPolicy: IfNotPresent + command: + [ + "cypher-shell", + "-a", + "bolt://gopen-db", + "-u", + "neo4j", + "-p", + "testpassword", + "-f", + "/migrator/migrations/test_docs.cypher", + ] + readinessProbe: + exec: + command: + [ + "cypher-shell", + "-a", + "bolt://gopen-db", + "-u", + "neo4j", + "-p", + "testpassword", + "--access-mode=read", + "RETURN 0", + ] + restartPolicy: Never + backoffLimit: 4 diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..e579f75 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,15 @@ +apiVersion: skaffold/v4beta13 +kind: Config +metadata: + name: gopen-api +build: + artifacts: + - image: gopen-api + docker: + dockerfile: ./docker/api.Dockerfile + - image: gopen-db-migrator + docker: + dockerfile: ./docker/migrator.Dockerfile +manifests: + rawYaml: + - kube/**/*.yaml