From bd2ec7eb1b43c064d2e5ccc1264fab8f8e05c534 Mon Sep 17 00:00:00 2001 From: Dmitry Zolotarev Date: Sun, 23 Aug 2020 04:38:52 +0300 Subject: [PATCH] k8s --- .dockerignore | 2 ++ .gitignore | 1 + deploy/Dockerfile | 16 ++++++++++ deploy/build.sh | 9 ++++++ deploy/config.example.nginx | 10 ++++++ deploy/deployment.yaml | 62 +++++++++++++++++++++++++++++++++++++ deploy/example.env | 6 ++++ src/App.js | 14 +++++---- 8 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 deploy/Dockerfile create mode 100755 deploy/build.sh create mode 100644 deploy/config.example.nginx create mode 100644 deploy/deployment.yaml create mode 100644 deploy/example.env diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eb79dd5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.idea diff --git a/.gitignore b/.gitignore index 2986dd9..92e3ca3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +local.env diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..964298a --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,16 @@ +#FROM node:12.18.3-alpine3.10 as builder +# +#COPY . /src +#WORKDIR /src +# +#ENV PUBLIC_URL /service/ +#RUN npm i && npm run build + +#EXPOSE 3000 + +#CMD ["npm", "start", "--prefix", "/src"] + +FROM nginx:1.19.2-alpine + +COPY ./build /usr/share/nginx/html +COPY ./deploy/config.example.nginx /etc/nginx/conf.d/default.conf diff --git a/deploy/build.sh b/deploy/build.sh new file mode 100755 index 0000000..aec65c4 --- /dev/null +++ b/deploy/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +DOCKER_IMAGE="${DOCKER_REGISTRY}/angry-lab/admin-front:latest" + +echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USER}" --password-stdin "${DOCKER_REGISTRY}" + +docker build -t "${DOCKER_IMAGE}" -f ./deploy/Dockerfile . +docker tag "${DOCKER_IMAGE}" admin-front:latest +docker push "${DOCKER_IMAGE}" diff --git a/deploy/config.example.nginx b/deploy/config.example.nginx new file mode 100644 index 0000000..e1d8192 --- /dev/null +++ b/deploy/config.example.nginx @@ -0,0 +1,10 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } +} diff --git a/deploy/deployment.yaml b/deploy/deployment.yaml new file mode 100644 index 0000000..2d994e3 --- /dev/null +++ b/deploy/deployment.yaml @@ -0,0 +1,62 @@ +kind: Namespace +apiVersion: v1 +metadata: + name: angry +--- +kind: Service +apiVersion: v1 +metadata: + name: admin-front-svc + namespace: angry +spec: + selector: + app: admin-front + ports: + - port: 80 + targetPort: 80 + protocol: TCP +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: admin-front + namespace: angry +spec: + selector: + matchLabels: + app: admin-front + template: + metadata: + labels: + app: admin-front + spec: + containers: + - name: admin-front + image: r.golangpro.ru/angry-lab/admin-front:latest + imagePullPolicy: Always + resources: + limits: + cpu: 1000m + imagePullSecrets: + - name: r-golang-pro-registry +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: admin-front-ingress + namespace: angry + annotations: + kubernetes.io/ingress.class: "nginx" + nginx.ingress.kubernetes.io/ssl-redirect: "true" + nginx.ingress.kubernetes.io/force-ssl-redirect: "true" + nginx.ingress.kubernetes.io/use-regex: "true" + nginx.ingress.kubernetes.io/rewrite-target: /$1 +spec: + rules: + - host: api.golangpro.ru + http: + paths: + - path: "/service/(.*)" + backend: + serviceName: admin-front-svc + servicePort: 80 diff --git a/deploy/example.env b/deploy/example.env new file mode 100644 index 0000000..49b81d2 --- /dev/null +++ b/deploy/example.env @@ -0,0 +1,6 @@ +DOCKER_REGISTRY= +DOCKER_USER= +DOCKER_PASSWORD= +DOCKER_EMAIL= + +PUBLIC_URL=/service/ \ No newline at end of file diff --git a/src/App.js b/src/App.js index 138edbe..322ff83 100644 --- a/src/App.js +++ b/src/App.js @@ -9,6 +9,8 @@ import Dashboard from './pages/dashboard/Dashboard'; // import { loginRequest } from "./thunks"; // import { getIsLogged } from "./actions/getIsLogged"; +const baseURL = process.env.PUBLIC_URL; +console.log(baseURL); const App = (props) => { //const { isLogged } = props; @@ -16,13 +18,13 @@ const App = (props) => { // login не действителен return ( - - + + - - - - + + + + ); };