Skip to content

Commit

Permalink
#SDSV-24 - Add k8s files for kubernetes deployment using codefresh an…
Browse files Browse the repository at this point in the history
…d metacell cluster.
  • Loading branch information
jrmartin committed Mar 8, 2024
1 parent f454c25 commit c83471c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 31 deletions.
34 changes: 23 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# node-sass 4.14.1 requires node version <= 14 for Alpine Linux
# See: https://github.com/sass/node-sass/releases/tag/v4.14.1
FROM node:16-alpine as build-deps
WORKDIR /usr/src/app
RUN pwd && ls
COPY yarn.lock ./
ARG NODE_PARENT=node:16-alpine

FROM ${NODE_PARENT} as frontend

ENV BUILDDIR=/app

RUN apk add git
RUN npm i -g @craco/craco

WORKDIR ${BUILDDIR}
COPY package.json ${BUILDDIR}
COPY yarn.lock ${BUILDDIR}
COPY nginx/default.conf ${BUILDDIR}

RUN yarn install
COPY . ./
COPY . ${BUILDDIR}
RUN yarn build

COPY public/ ./public/
COPY src/ ./src/
FROM nginx:1.19.3-alpine

RUN cat /etc/nginx/conf.d/default.conf

COPY --from=frontend /app/default.conf /etc/nginx/conf.d/default.conf

COPY --from=frontend /app/build /usr/share/nginx/html/

EXPOSE 3000
CMD yarn run start
EXPOSE 80
35 changes: 35 additions & 0 deletions deploy/k8s/codefresh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "1.0"
stages:
- "clone"
- "build"
- "deploy"
steps:
clone:
stage: "clone"
title: "Cloning SDS Viewer"
type: "git-clone"
repo: "metacell/sds-viewer"
revision: "${{CF_BRANCH}}"
build:
stage: "build"
title: "Building SDS Viewer"
type: "build"
image_name: "sds-viewer"
tag: "${{CF_BUILD_ID}}"
dockerfile: Dockerfile
working_directory: ./sds-viewer
buildkit: true
registry: "${{CODEFRESH_REGISTRY}}"
deploy:
stage: "deploy"
title: "Deploying SDS Viewer"
image: codefresh/kubectl
working_directory: ./sds-viewer/deploy/k8s
commands:
- export CLUSTER_NAME="${{CLUSTER_NAME}}"
- export NAMESPACE="${{NAMESPACE}}"
- export CF_BUILD_ID="${{CF_BUILD_ID}}"
- export REGISTRY="${{REGISTRY}}/"
- export DOMAIN="${{DOMAIN}}"
- chmod +x ./deploy.sh
- ./deploy.sh
14 changes: 7 additions & 7 deletions deploy/k8s/ingress_tpl.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
name: 'letsencrypt-sds_viewer'
name: 'letsencrypt-sdsviewer'
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: [email protected]
privateKeySecretRef:
name: letsencrypt-sds_viewer
name: letsencrypt-sdsviewer
solvers:
- http01:
ingress:
ingressName: sds_viewer
ingressName: sds-viewer
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
cert-manager.io/issuer: letsencrypt-sds_viewer
cert-manager.io/issuer: letsencrypt-sdsviewer
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: 'true'
nginx.ingress.kubernetes.io/ssl-redirect: 'true'
nginx.ingress.kubernetes.io/proxy-body-size: 512m
nginx.ingress.kubernetes.io/from-to-www-redirect: 'true'
name: sds_viewer
name: sds-viewer
spec:
rules:
- host: "{{DOMAIN}}"
http:
paths:
- backend:
service:
name: sds_viewer
name: sds-viewer
port:
number: 80
path: /
pathType: ImplementationSpecific
tls:
- hosts:
- "{{DOMAIN}}"
secretName: sds_viewer-tls
secretName: sds-viewer-tls
24 changes: 12 additions & 12 deletions deploy/k8s/sds_viewer_tpl.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: sds_viewer
name: sds-viewer
spec:
selector:
matchLabels:
app: sds_viewer
app: sds-viewer
replicas: 1
template:
metadata:
labels:
app: sds_viewer
app: sds-viewer
spec:
containers:
- name: sds_viewer
image: "{{REGISTRY}}sds_viewer:{{TAG}}"
- name: sds-viewer
image: "{{REGISTRY}}sds-viewer:{{TAG}}"
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "25m"
limits:
memory: "128Mi"
cpu: "100m"
cpu: 1500m
memory: 768Mi
requests:
cpu: 500m
memory: 768Mi
---
apiVersion: v1
kind: Service
metadata:
name: sds_viewer
name: sds-viewer
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: sds_viewer
app: sds-viewer
32 changes: 32 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
upstream sds-viewer {
server sds-viewer:8000;
}

server {
listen 80;

location / {
root /usr/share/nginx/html/;
# index index.html index.htm;
try_files $uri /index.html;
}

location /sds-viewer/ {
root /usr/share/nginx/html/;
# index index.html index.htm;
try_files $uri /index.html;
}

location ~* ^/(admin|api|logged-out|login|sds-viewer|complete|disconnect|__debug__)/.*$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_pass http://sds-viewer;
}

location /static/ {
autoindex on;
alias /usr/share/nginx/html/static/;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"license": "MIT",
"private": true,
"homepage": "http://metacell.github.io/sds-viewer",
"homepage": "./",
"dependencies": {
"@craco/craco": "^6.1.2",
"@frogcat/ttl2jsonld": "^0.0.7",
Expand Down

0 comments on commit c83471c

Please sign in to comment.