diff --git a/Dockerfile b/Dockerfile index 97f9e87..83c03fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/deploy/k8s/codefresh.yaml b/deploy/k8s/codefresh.yaml new file mode 100644 index 0000000..444f4b6 --- /dev/null +++ b/deploy/k8s/codefresh.yaml @@ -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 \ No newline at end of file diff --git a/deploy/k8s/ingress_tpl.yaml b/deploy/k8s/ingress_tpl.yaml index befd530..9faf5d0 100755 --- a/deploy/k8s/ingress_tpl.yaml +++ b/deploy/k8s/ingress_tpl.yaml @@ -1,29 +1,29 @@ 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: filippo@metacell.us 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}}" @@ -31,7 +31,7 @@ spec: paths: - backend: service: - name: sds_viewer + name: sds-viewer port: number: 80 path: / @@ -39,4 +39,4 @@ spec: tls: - hosts: - "{{DOMAIN}}" - secretName: sds_viewer-tls + secretName: sds-viewer-tls diff --git a/deploy/k8s/sds_viewer_tpl.yaml b/deploy/k8s/sds_viewer_tpl.yaml index 95bb514..b7be103 100755 --- a/deploy/k8s/sds_viewer_tpl.yaml +++ b/deploy/k8s/sds_viewer_tpl.yaml @@ -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 diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..8c5795f --- /dev/null +++ b/nginx/default.conf @@ -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/; + } +} \ No newline at end of file diff --git a/package.json b/package.json index b98a9e7..c6376f4 100644 --- a/package.json +++ b/package.json @@ -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",