From e6dc73c57fcdf3a596c44fc0f1ccd4c823ba7be1 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 20:37:01 +0100 Subject: [PATCH 01/43] initial commit backend --- Dockerfile | 110 ++++++++++++++++++++++++++++++++ backend/data/config/config.json | 86 +++++++++++++++++++++++++ backend/go.mod | 3 + backend/main.go | 10 +++ backend/src/models/config.go | 66 +++++++++++++++++++ scripts/run.sh | 20 ++++++ scripts/supervisor.conf | 39 +++++++++++ 7 files changed, 334 insertions(+) create mode 100644 Dockerfile create mode 100644 backend/data/config/config.json create mode 100644 backend/go.mod create mode 100644 backend/main.go create mode 100644 backend/src/models/config.go create mode 100644 scripts/run.sh create mode 100644 scripts/supervisor.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fdf6bdc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,110 @@ +FROM debian:buster AS builder +MAINTAINER Kerberos.io + +################################# +# Surpress Upstart errors/warning + +RUN dpkg-divert --local --rename --add /sbin/initctl +RUN ln -sf /bin/true /sbin/initctl + +############################################# +# Let the container know that there is no tty + +ENV DEBIAN_FRONTEND noninteractive + +################################# +# Clone and build FFMpeg & OpenCV + +RUN apt-get update && apt-get upgrade -y && apt-get -y --no-install-recommends install git cmake wget dh-autoreconf autotools-dev autoconf automake gcc build-essential libtool make ca-certificates supervisor nasm zlib1g-dev tar libx264. unzip wget pkg-config libavresample-dev && \ + git clone https://github.com/FFmpeg/FFmpeg && \ + cd FFmpeg && git checkout remotes/origin/release/4.0 && \ + ./configure --prefix=/usr/local --target-os=linux --enable-nonfree --enable-libx264 --enable-gpl --enable-shared && \ + make -j8 && \ + make install && \ + cd .. && rm -rf FFmpeg +RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip && \ + unzip opencv.zip && mv opencv-4.0.0 opencv && cd opencv && mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D CMAKE_INSTALL_PREFIX=/usr/ \ + -D OPENCV_GENERATE_PKGCONFIG=YES \ + -D BUILD_TESTS=OFF \ + -D OPENCV_ENABLE_NONFREE=ON \ + #-D BUILD_opencv_dnn=OFF \ + -D BUILD_opencv_ml=OFF \ + -D BUILD_opencv_stitching=OFF \ + -D BUILD_opencv_ts=OFF \ + -D BUILD_opencv_java_bindings_generator=OFF \ + -D BUILD_opencv_python_bindings_generator=OFF \ + -D INSTALL_PYTHON_EXAMPLES=OFF \ + -D BUILD_EXAMPLES=OFF .. && make -j8 && make install && cd ../.. && rm -rf opencv* + +############################ +# Build gGlang + +ENV GOROOT=/usr/local/go +ENV GOPATH=/go +ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH + +RUN apt-get install -y git +RUN ARCH=$([ "$(uname -m)" = "armv7l" ] && echo "armv6l" || echo "amd64") && wget "https://dl.google.com/go/go1.14.2.linux-$ARCH.tar.gz" && \ + tar -xvf "go1.14.2.linux-$ARCH.tar.gz" && \ + mv go /usr/local + +ENV GO111MODULE=on \ + CGO_ENABLED=1 + +RUN mkdir -p /go/src/github.com/kerberos-io/opensource +COPY backend /go/src/github.com/kerberos-io/opensource +RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ + go mod download && \ + go build -o main && \ + mkdir -p /opensource && \ + mv main /opensource && \ + mkdir -p /opensource/data/cloud && \ + mkdir -p /opensource/data/snapshots && \ + mkdir -p /opensource/data/log && \ + mkdir -p /opensource/data/recordings && \ + mkdir -p /opensource/data/config && \ + rm -rf /go/src/gitlab.com/ + + # Let's create a /dist folder containing just the files necessary for runtime. + # Later, it will be copied as the / (root) of the output image. + WORKDIR /dist + RUN cp -r /opensource ./ + + # Optional: in case your application uses dynamic linking (often the case with CGO), + # this will collect dependent libraries so they're later copied to the final image + # NOTE: make sure you honor the license terms of the libraries you copy and distribute + RUN ldd /opensource/main | tr -s '[:blank:]' '\n' | grep '^/' | \ + xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;' + RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/ + RUN cp -r /usr/local/lib/libavcodec* ./usr/lib && \ + cp -r /usr/local/lib/libavformat* ./usr/lib && \ + cp -r /usr/local/lib/libswscale* ./usr/lib && \ + cp -r /usr/local/lib/libswresample* ./usr/lib + RUN ldd /opensource/main + + FROM alpine:latest + + ################################# + # Copy files from previous images + + COPY --chown=0:0 --from=builder /dist / + COPY --chown=0:0 --from=builder /usr/local/go/lib/time/zoneinfo.zip /zoneinfo.zip + + ENV ZONEINFO=/zoneinfo.zip + + RUN apk update && apk add ca-certificates && \ + apk add --no-cache tzdata && rm -rf /var/cache/apk/* + + #################################### + # ADD supervisor and STARTUP script + + RUN apk add supervisor && mkdir -p /var/log/supervisor/ + ADD ./scripts/supervisor.conf /etc/supervisord.conf + ADD ./scripts/run.sh /run.sh + RUN chmod 755 /run.sh && chmod +x /run.sh + + EXPOSE 8080 + + CMD ["sh", "/run.sh"] diff --git a/backend/data/config/config.json b/backend/data/config/config.json new file mode 100644 index 0000000..a06b465 --- /dev/null +++ b/backend/data/config/config.json @@ -0,0 +1,86 @@ +{ + "type": "template", + "key": "", + "name": "camera", + "capture": { + "id": "ipcamera", + "ipcamera": { + "rtsp": "", + "fps": "" + }, + "usbcamera": { + "rtsp": "", + "fps": "" + }, + "raspicamera": { + "rtsp": "", + "fps": "" + }, + "continuous": "false", + "postrecording": 10, + "prerecording": 5, + "maxlengthrecording": 10 + }, + "timetable": [ + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 69840, + "start2": 70080, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + }, + { + "start1": 0, + "end1": 43199, + "start2": 43200, + "end2": 86400 + } + ], + "region": { + "rectangle": { + "x1": 0, + "y1": 0, + "x2": 800, + "y2": 640 + }, + "polygon": [] + }, + "cloud": "kstorage", + "kstorage": { + "uri": "", + "cloud_key": "", + "access_key": "", + "secret_access_key": "", + "provider": "", + "directory": "" + } +} diff --git a/backend/go.mod b/backend/go.mod new file mode 100644 index 0000000..e6211ac --- /dev/null +++ b/backend/go.mod @@ -0,0 +1,3 @@ +module github.com/kerberos-io/opensource/backend + +go 1.15 diff --git a/backend/main.go b/backend/main.go new file mode 100644 index 0000000..ce7435c --- /dev/null +++ b/backend/main.go @@ -0,0 +1,10 @@ +package main + +import ( + "fmt" +) + +func main(){ + fmt.Println("So is the first line of Kerberos Open Source v3") + return +} diff --git a/backend/src/models/config.go b/backend/src/models/config.go new file mode 100644 index 0000000..4bb4ba9 --- /dev/null +++ b/backend/src/models/config.go @@ -0,0 +1,66 @@ +package models + +type Config struct { + Type string `json:"type" binding:"required"` + Key string `json:"key"` + Name string `json:"name"` + Timezone string `json:"timezone,omitempty" bson:"timezone,omitempty"` + Capture Capture `json:"capture"` + Timetable []*Timetable `json:"timetable"` + Region *Region `json:"region"` + Cloud string `json:"cloud,omitempty" bson:"cloud,omitempty"` + KStorage *KStorage `json:"kstorage,omitempty" bson:"kstorage,omitempty"` + MQTTURI string `json:"mqtturi,omitempty" bson:"mqtturi,omitempty"` +} + +type Capture struct { + Id string `json:"id"` + IPCamera IPCamera `json:"ipcamera"` + Continuous string `json:"continuous,omitempty"` + PostRecording int64 `json:"postrecording"` + PreRecording int `json:"prerecording"` + MaxLengthRecording int64 `json:"maxlengthrecording"` +} + +type IPCamera struct { + RTSP string `json:"rtsp"` + FPS string `json:"fps"` +} + +type Region struct { + Rectangle Rectangle `json:"rectangle"` + Polygon []Polygon `json:"polygon"` +} + +type Rectangle struct { + X1 int `json:"x1"` + Y1 int `json:"y1"` + X2 int `json:"x2"` + Y2 int `json:"y2"` +} + +type Polygon struct { + Id string `json:"id"` + Coordinates []Coordinate `json:"coordinates"` +} + +type Coordinate struct { + X float64 `json:"x"` + Y float64 `json:"y"` +} + +type Timetable struct { + Start1 int `json:"start1"` + End1 int `json:"end1"` + Start2 int `json:"start2"` + End2 int `json:"end2"` +} + +type KStorage struct { + URI string `json:"uri,omitempty" bson:"uri,omitempty"` + CloudKey string `json:"cloud_key,omitempty" bson:"cloud_key,omitempty"` + AccessKey string `json:"access_key,omitempty" bson:"access_key,omitempty"` + SecretAccessKey string `json:"secret_access_key,omitempty" bson:"secret_access_key,omitempty"` + Provider string `json:"provider,omitempty" bson:"provider,omitempty"` + Directory string `json:"directory,omitempty" bson:"directory,omitempty"` +} diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 0000000..755a07d --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +autoremoval() { + partition=/dev/ + imagedir=/opensource/data/recordings + clouddir=/opensource/data/cloud + + while : + do + #find $imagedir -type f -mtime +2 -exec rm {} \; + #find $clouddir -type f -mtime +2 -exec rm {} \; + sleep 60 + done +} + +export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib && ldconfig + +autoremoval & + +/usr/bin/supervisord -n -c /etc/supervisord.conf diff --git a/scripts/supervisor.conf b/scripts/supervisor.conf new file mode 100644 index 0000000..6efd3af --- /dev/null +++ b/scripts/supervisor.conf @@ -0,0 +1,39 @@ +; supervisor config file + +[unix_http_server] +file=/var/run/supervisor.sock ; (the path to the socket file) +chmod=0700 ; sockef file mode (default 0700) + +[supervisord] +logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) +pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) +childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) + +; the below section must remain in the config file for RPC +; (supervisorctl/web interface) to work, additional interfaces may be +; added by defining them in separate rpcinterface: sections +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket + +; The [include] section can just contain the "files" setting. This +; setting can list multiple files (separated by whitespace or +; newlines). It can also contain wildcards. The filenames are +; interpreted as relative to this file. Included files *cannot* +; include files themselves. + +[include] +files = /etc/supervisor/conf.d/*.conf + +[program:opensource] +command=/opensource/main run opensource 8080 +directory=/opensource +autostart = true +autorestart = true +user = root +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 From 4deaa287c774efa182ccf654e224f1e9db005504 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 20:38:17 +0100 Subject: [PATCH 02/43] typos --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index fdf6bdc..7d9eff0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip && \ -D BUILD_EXAMPLES=OFF .. && make -j8 && make install && cd ../.. && rm -rf opencv* ############################ -# Build gGlang +# Build Golang ENV GOROOT=/usr/local/go ENV GOPATH=/go @@ -50,9 +50,6 @@ RUN ARCH=$([ "$(uname -m)" = "armv7l" ] && echo "armv6l" || echo "amd64") && wge tar -xvf "go1.14.2.linux-$ARCH.tar.gz" && \ mv go /usr/local -ENV GO111MODULE=on \ - CGO_ENABLED=1 - RUN mkdir -p /go/src/github.com/kerberos-io/opensource COPY backend /go/src/github.com/kerberos-io/opensource RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ From e13254ec97bbd119a7a73301acd444fb64a43316 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:03:37 +0100 Subject: [PATCH 03/43] Create build.sh --- build.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 build.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..b3aadd2 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +export version=0.0.1 +export name=opensource + +docker tag $name kerberos/$name:$version +docker push kerberos/$name:$version + +docker tag $name kerberos/$name:latest +docker push kerberos/$name:latest From 2bde9f733e44b363cb384e380b842aa8878a34d8 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:05:45 +0100 Subject: [PATCH 04/43] Update build.sh --- build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.sh b/build.sh index b3aadd2..74a6931 100644 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ export version=0.0.1 export name=opensource +docker build -t $name . + docker tag $name kerberos/$name:$version docker push kerberos/$name:$version From 2e078ec04b172362d096a9fca60993b2b63ca519 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:07:35 +0100 Subject: [PATCH 05/43] Update Dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7d9eff0..ede82c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ RUN ARCH=$([ "$(uname -m)" = "armv7l" ] && echo "armv6l" || echo "amd64") && wge mv go /usr/local RUN mkdir -p /go/src/github.com/kerberos-io/opensource -COPY backend /go/src/github.com/kerberos-io/opensource +COPY backend /go/src/github.com/kerberos-io/opensource/backend RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ go mod download && \ go build -o main && \ @@ -75,6 +75,7 @@ RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ RUN ldd /opensource/main | tr -s '[:blank:]' '\n' | grep '^/' | \ xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;' RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/ + RUN mkdir ./usr/lib RUN cp -r /usr/local/lib/libavcodec* ./usr/lib && \ cp -r /usr/local/lib/libavformat* ./usr/lib && \ cp -r /usr/local/lib/libswscale* ./usr/lib && \ From bdb9b090018f8e92a81c3636e544b7fbe627df01 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:21:13 +0100 Subject: [PATCH 06/43] Update Dockerfile --- Dockerfile | 53 ++++++----------------------------------------------- 1 file changed, 6 insertions(+), 47 deletions(-) diff --git a/Dockerfile b/Dockerfile index ede82c1..cd44637 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,60 +1,19 @@ -FROM debian:buster AS builder +FROM kerberos/debian-opencv-ffmpeg:1.0.0 AS builder MAINTAINER Kerberos.io -################################# -# Surpress Upstart errors/warning - -RUN dpkg-divert --local --rename --add /sbin/initctl -RUN ln -sf /bin/true /sbin/initctl - -############################################# -# Let the container know that there is no tty - -ENV DEBIAN_FRONTEND noninteractive - -################################# -# Clone and build FFMpeg & OpenCV - -RUN apt-get update && apt-get upgrade -y && apt-get -y --no-install-recommends install git cmake wget dh-autoreconf autotools-dev autoconf automake gcc build-essential libtool make ca-certificates supervisor nasm zlib1g-dev tar libx264. unzip wget pkg-config libavresample-dev && \ - git clone https://github.com/FFmpeg/FFmpeg && \ - cd FFmpeg && git checkout remotes/origin/release/4.0 && \ - ./configure --prefix=/usr/local --target-os=linux --enable-nonfree --enable-libx264 --enable-gpl --enable-shared && \ - make -j8 && \ - make install && \ - cd .. && rm -rf FFmpeg -RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip && \ - unzip opencv.zip && mv opencv-4.0.0 opencv && cd opencv && mkdir build && cd build && \ - cmake -D CMAKE_BUILD_TYPE=RELEASE \ - -D CMAKE_INSTALL_PREFIX=/usr/ \ - -D OPENCV_GENERATE_PKGCONFIG=YES \ - -D BUILD_TESTS=OFF \ - -D OPENCV_ENABLE_NONFREE=ON \ - #-D BUILD_opencv_dnn=OFF \ - -D BUILD_opencv_ml=OFF \ - -D BUILD_opencv_stitching=OFF \ - -D BUILD_opencv_ts=OFF \ - -D BUILD_opencv_java_bindings_generator=OFF \ - -D BUILD_opencv_python_bindings_generator=OFF \ - -D INSTALL_PYTHON_EXAMPLES=OFF \ - -D BUILD_EXAMPLES=OFF .. && make -j8 && make install && cd ../.. && rm -rf opencv* - -############################ -# Build Golang +ARG gitlab_id +ARG gitlab_token ENV GOROOT=/usr/local/go ENV GOPATH=/go ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH - -RUN apt-get install -y git -RUN ARCH=$([ "$(uname -m)" = "armv7l" ] && echo "armv6l" || echo "amd64") && wget "https://dl.google.com/go/go1.14.2.linux-$ARCH.tar.gz" && \ - tar -xvf "go1.14.2.linux-$ARCH.tar.gz" && \ - mv go /usr/local +ENV GOSUMDB=off RUN mkdir -p /go/src/github.com/kerberos-io/opensource COPY backend /go/src/github.com/kerberos-io/opensource/backend RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ go mod download && \ - go build -o main && \ + go build main.go && \ mkdir -p /opensource && \ mv main /opensource && \ mkdir -p /opensource/data/cloud && \ @@ -75,7 +34,7 @@ RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ RUN ldd /opensource/main | tr -s '[:blank:]' '\n' | grep '^/' | \ xargs -I % sh -c 'mkdir -p $(dirname ./%); cp % ./%;' RUN mkdir -p lib64 && cp /lib64/ld-linux-x86-64.so.2 lib64/ - RUN mkdir ./usr/lib + RUN mkdir -p ./usr/lib RUN cp -r /usr/local/lib/libavcodec* ./usr/lib && \ cp -r /usr/local/lib/libavformat* ./usr/lib && \ cp -r /usr/local/lib/libswscale* ./usr/lib && \ From 7c4f50bf894edb1614c5ce78dce01b79cba6b03b Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:24:10 +0100 Subject: [PATCH 07/43] Update main.go --- backend/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/main.go b/backend/main.go index ce7435c..6b862f1 100644 --- a/backend/main.go +++ b/backend/main.go @@ -2,9 +2,11 @@ package main import ( "fmt" + "os" ) func main(){ + fmt.Println(os.Getenv("HELLO_WORLD")) fmt.Println("So is the first line of Kerberos Open Source v3") return } From 2920754128e0a0a7902de9d0895a95caadae664d Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:46:27 +0100 Subject: [PATCH 08/43] add goland configuration --- .idea/modules.xml | 8 +++ .idea/opensource.iml | 9 +++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 97 +++++++++++++++++++++++++ backend/go.mod | 7 ++ backend/go.sum | 83 +++++++++++++++++++++ backend/main.go | 143 +++++++++++++++++++++++++++++++++++-- backend/src/models/user.go | 7 ++ 8 files changed, 355 insertions(+), 5 deletions(-) create mode 100644 .idea/modules.xml create mode 100644 .idea/opensource.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 backend/go.sum create mode 100644 backend/src/models/user.go diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..32009a5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/opensource.iml b/.idea/opensource.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/opensource.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..07374c9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/go.mod b/backend/go.mod index e6211ac..3bf885a 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,3 +1,10 @@ module github.com/kerberos-io/opensource/backend go 1.15 + +require ( + github.com/appleboy/gin-jwt/v2 v2.6.4 + github.com/gin-contrib/cors v1.3.1 + github.com/gin-contrib/pprof v1.3.0 + github.com/gin-gonic/gin v1.6.3 +) diff --git a/backend/go.sum b/backend/go.sum new file mode 100644 index 0000000..007ead2 --- /dev/null +++ b/backend/go.sum @@ -0,0 +1,83 @@ +github.com/appleboy/gin-jwt/v2 v2.6.4 h1:4YlMh3AjCFnuIRiL27b7TXns7nLx8tU/TiSgh40RRUI= +github.com/appleboy/gin-jwt/v2 v2.6.4/go.mod h1:CZpq1cRw+kqi0+yD2CwVw7VGXrrx4AqBdeZnwxVmoAs= +github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= +github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA= +github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= +github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0= +github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= +github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= +github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= +github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= +github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= +github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= +github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/backend/main.go b/backend/main.go index 6b862f1..ed2104a 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1,12 +1,145 @@ package main import ( - "fmt" - "os" + "os" + "fmt" + "log" + "time" + "github.com/gin-gonic/gin" + "github.com/gin-contrib/cors" + "github.com/appleboy/gin-jwt/v2" + "github.com/gin-contrib/pprof" + "github.com/kerberos-io/opensource/backend/src/models" ) func main(){ - fmt.Println(os.Getenv("HELLO_WORLD")) - fmt.Println("So is the first line of Kerberos Open Source v3") - return + + const VERSION = 3.0 + action := os.Args[1] + + switch action { + + case "version": + + log.Printf("%s: %0.1f\n", "You are currrently running Kerberos Open Source", VERSION) + + case "pending-upload": + + name := os.Args[2] + fmt.Println(name) + //cloud.PendingUpload(log, name) + + case "discover": + + timeout := os.Args[2] + fmt.Println(timeout) + //duration, _ := strconv.Atoi(timeout) + //capture.Discover(log, time.Duration(duration)) + + case "run": { + + name := os.Args[2] + port := os.Args[3] + fmt.Println(name) + + // Initialize REST API + r := gin.Default() + + // Profile + pprof.Register(r) + + // Setup CORS + r.Use(cors.New(cors.Config{ + AllowOrigins: []string{"*"}, + AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"}, + AllowHeaders: []string{"Origin", "Content-Type", "authorization", "multipart/form-data", "x-requested-with"}, + ExposeHeaders: []string{"Content-Length"}, + AllowCredentials: true, + MaxAge: 12 * time.Hour, + })) + + // the jwt middleware + identityKey := "id" + myKey := "TOBECHANGED" + authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{ + Realm: "kerberosio", + Key: []byte(myKey), + Timeout: time.Hour * 24, + MaxRefresh: time.Hour * 24 * 7, + IdentityKey: identityKey, + PayloadFunc: func(data interface{}) jwt.MapClaims { + if v, ok := data.(*models.User); ok { + return jwt.MapClaims{ + identityKey: v, + } + } + return jwt.MapClaims{} + }, + IdentityHandler: func(c *gin.Context) interface{} { + claims := jwt.ExtractClaims(c) + user := claims["id"].(map[string]interface {}) + return &models.User{ + Username: user["username"].(string), + Role: user["role"].(string), + } + }, + Authorizator: func(data interface{}, c *gin.Context) bool { + if _, ok := data.(*models.User); ok { //&& v.Username == "admin" { + return true + } + return false + }, + Unauthorized: func(c *gin.Context, code int, message string) { + c.AbortWithStatusJSON(code, gin.H{ + "code": code, + "message": message, + }) + }, + // TokenLookup is a string in the form of ":" that is used + // to extract token from the request. + // Optional. Default value "header:Authorization". + // Possible values: + // - "header:" + // - "query:" + // - "cookie:" + // - "param:" + TokenLookup: "header: Authorization, query: token, cookie: jwt", + // TokenLookup: "query:token", + // TokenLookup: "cookie:token", + + // TokenHeadName is a string in the header. Default value is "Bearer" + TokenHeadName: "Bearer", + + // TimeFunc provides the current time. You can override it to use another time value. This is useful for testing or if your server uses a different time zone than your tokens. + TimeFunc: time.Now, + }) + + if err != nil { + log.Fatal("JWT Error:" + err.Error()) + } + + r.GET("/restart", func(c *gin.Context) { + c.JSON(200, gin.H{ + "restart": true, + }) + }) + + r.GET("/motion", func(c *gin.Context) { + c.JSON(200, gin.H{ + "data": "☄ Simulate motion", + }) + }) + + r.Use(authMiddleware.MiddlewareFunc()) + { + + } + + r.Run(":" + port) + + } + default: + fmt.Println("Sorry I don't understand :(") + } + return } diff --git a/backend/src/models/user.go b/backend/src/models/user.go new file mode 100644 index 0000000..6644cd1 --- /dev/null +++ b/backend/src/models/user.go @@ -0,0 +1,7 @@ +package models + +type User struct { + Username string `json:"username" bson:"username"` + Password string `json:"password" bson:"password"` + Role string `json:"role" bson:"role"` +} From a112d9dad5c06885d9767b379a28ec213d955881 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 21:57:56 +0100 Subject: [PATCH 09/43] add links --- .idea/workspace.xml | 19 +++++++++---------- README.md | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 07374c9..a479e5c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,7 @@ - - + \ No newline at end of file diff --git a/README.md b/README.md index 2f8d15a..b464788 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Kerberos Open Source +[**Docker Hub**](https://hub.docker.com/r/kerberos/opensource) | [**Documentation**](https://doc.kerberos.io) + Kerberos Open source (v3) is a cutting edge video surveillance management system made available as Open source (Apache 2.0) with a Commons Clause License on top. This means that all the source code is available for you or your company, and you can use and transform it as long it is for non commercial usage. Read more about the license at the bottom of this page. ## Previous releases From 2d4672cde21a6d10be911fe1ae09b8e34ed40193 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 22:04:02 +0100 Subject: [PATCH 10/43] add license --- .idea/workspace.xml | 36 +++++++++++++++++++++++++++++++++++- LICENSE | 13 +++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 LICENSE diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a479e5c..c26a667 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,8 +1,27 @@ + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 0d38451d61bc4df0ad87cc0e172e925d4297d2f0 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 22:58:57 +0100 Subject: [PATCH 21/43] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 77aba79..c27f774 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ frontend/node_modules -frontend/build \ No newline at end of file +frontend/build +.idea \ No newline at end of file From a9999e303b4b5cb170c20141534020812dede013 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 23:00:49 +0100 Subject: [PATCH 22/43] Update Dockerfile --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cb5d863..bee32ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,10 @@ COPY backend /go/src/github.com/kerberos-io/opensource/backend COPY frontend /go/src/github.com/kerberos-io/opensource/frontend # Build react -RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_14.x | bash - +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list && \ + apt update && apt install yarn + RUN cd /go/src/github.com/kerberos-io/opensource/frontend && \ yarn build From 7c4e52c6164f0d40ff45c57c53a74cf0237109e4 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 23:01:29 +0100 Subject: [PATCH 23/43] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index bee32ec..131eee6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,8 @@ COPY backend /go/src/github.com/kerberos-io/opensource/backend COPY frontend /go/src/github.com/kerberos-io/opensource/frontend # Build react -RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - && \ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list && \ +RUN apt-get install curl && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt update && apt install yarn RUN cd /go/src/github.com/kerberos-io/opensource/frontend && \ From cef5579d4dcc9246faef39dc7965b9fef7b9bd21 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 23:01:56 +0100 Subject: [PATCH 24/43] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 131eee6..26571d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY frontend /go/src/github.com/kerberos-io/opensource/frontend # Build react RUN apt-get install curl && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ - apt update && apt install yarn + apt update && apt install yarn -y RUN cd /go/src/github.com/kerberos-io/opensource/frontend && \ yarn build From 6f98fb354042a75edcfdd1e2b2d6ec8f9d99fa37 Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 23:03:56 +0100 Subject: [PATCH 25/43] Update Dockerfile --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 26571d4..795d2cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,12 +14,13 @@ COPY backend /go/src/github.com/kerberos-io/opensource/backend COPY frontend /go/src/github.com/kerberos-io/opensource/frontend # Build react -RUN apt-get install curl && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ +RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ apt update && apt install yarn -y RUN cd /go/src/github.com/kerberos-io/opensource/frontend && \ - yarn build + npm install && yarn build # Build golang RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ From a3b0d1bcdb8b77273d7f5a7b521a638eba6f4aeb Mon Sep 17 00:00:00 2001 From: cedricve Date: Sun, 27 Dec 2020 23:13:42 +0100 Subject: [PATCH 26/43] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 795d2cc..a6d65ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,7 @@ RUN cd /go/src/github.com/kerberos-io/opensource/backend && \ go build main.go && \ mkdir -p /opensource && \ mv main /opensource && \ + mv www /opensource && \ mkdir -p /opensource/data/cloud && \ mkdir -p /opensource/data/snapshots && \ mkdir -p /opensource/data/log && \ From 103b183071639ba8ef7421cbbf4b856c8eeb6537 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 13:52:44 +0100 Subject: [PATCH 27/43] add .circleci --- .circleci/config.yml | 27 +++++++++++++++++++++++++++ backend/main.go | 6 ++++++ 2 files changed, 33 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..8a7216f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,27 @@ +# Golang CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-go/ for more details +version: 2 +jobs: + build: + docker: + # specify the version + - image: circleci/golang:1.15 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/postgres:9.4 + + #### TEMPLATE_NOTE: go expects specific checkout path representing url + #### expecting it in the form of + #### /go/src/github.com/circleci/go-tool + #### /go/src/bitbucket.org/circleci/go-tool + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + steps: + - checkout + + # specify any bash command here prefixed with `run: ` + - run: cd backend + - run: go get -v -t -d ./... + - run: go test -v ./... diff --git a/backend/main.go b/backend/main.go index 1819780..1b99b8e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -62,6 +62,12 @@ func main(){ api := r.Group("/api") { + api.GET("/configure", func(c *gin.Context) { + c.JSON(200, gin.H{ + "restart": true, + }) + }) + api.GET("/restart", func(c *gin.Context) { c.JSON(200, gin.H{ "restart": true, From 1c17badb5f67bbc219677d42fdbd1fd0f2805dfd Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 13:55:48 +0100 Subject: [PATCH 28/43] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8a7216f..b947dc5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,5 +23,5 @@ jobs: # specify any bash command here prefixed with `run: ` - run: cd backend - - run: go get -v -t -d ./... + - run: go mod download - run: go test -v ./... From 233b457990769fdf4a02b442d74f0a4f5fad4a45 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 13:56:31 +0100 Subject: [PATCH 29/43] Update config.yml --- .circleci/config.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b947dc5..98282c1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,6 +22,5 @@ jobs: - checkout # specify any bash command here prefixed with `run: ` - - run: cd backend - - run: go mod download - - run: go test -v ./... + - run: cd backend && go mod download + - run: cd backend && go test -v ./... From 4bcd63291d7e9f989a137fa278ebf01fee3544f6 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 13:59:02 +0100 Subject: [PATCH 30/43] add go vetting --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 98282c1..44e1e14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,3 +24,4 @@ jobs: # specify any bash command here prefixed with `run: ` - run: cd backend && go mod download - run: cd backend && go test -v ./... + - run: cd backend && go vet From e9bdd45e84f582516606304cfe0817b8a39e468d Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 13:59:46 +0100 Subject: [PATCH 31/43] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 44e1e14..aa91f2d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,4 +24,4 @@ jobs: # specify any bash command here prefixed with `run: ` - run: cd backend && go mod download - run: cd backend && go test -v ./... - - run: cd backend && go vet + - run: go vet From cd91aa678d2f1604dc667ce1faacf65742e5d66a Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:00:42 +0100 Subject: [PATCH 32/43] make typo by purpose --- .circleci/config.yml | 2 +- backend/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index aa91f2d..44e1e14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,4 +24,4 @@ jobs: # specify any bash command here prefixed with `run: ` - run: cd backend && go mod download - run: cd backend && go test -v ./... - - run: go vet + - run: cd backend && go vet diff --git a/backend/main.go b/backend/main.go index 1b99b8e..d3b5457 100644 --- a/backend/main.go +++ b/backend/main.go @@ -84,7 +84,7 @@ func main(){ { } - } + } typoooo r.Run(":" + port) From 819da93e70ffd5fd0f321d279413b90e0e3d019e Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:02:24 +0100 Subject: [PATCH 33/43] Update main.go --- backend/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/main.go b/backend/main.go index d3b5457..4d04577 100644 --- a/backend/main.go +++ b/backend/main.go @@ -84,7 +84,9 @@ func main(){ { } - } typoooo + } + + yolo := "ok" r.Run(":" + port) From d328940926ab6775f88340bf136f3f787c067044 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:05:23 +0100 Subject: [PATCH 34/43] build frontend --- .circleci/config.yml | 25 +++++++++++-------------- backend/main.go | 2 -- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 44e1e14..f1bdd6b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,25 +3,22 @@ # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2 jobs: - build: + backend: docker: - # specify the version - image: circleci/golang:1.15 - - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/postgres:9.4 - - #### TEMPLATE_NOTE: go expects specific checkout path representing url - #### expecting it in the form of - #### /go/src/github.com/circleci/go-tool - #### /go/src/bitbucket.org/circleci/go-tool working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} steps: - checkout - - # specify any bash command here prefixed with `run: ` - run: cd backend && go mod download - run: cd backend && go test -v ./... - run: cd backend && go vet + + frontend: + docker: + - image: cimg/node:15.5.0 + steps: + - checkout + - run: node --version + - run: yarn build + + diff --git a/backend/main.go b/backend/main.go index 4d04577..1b99b8e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -86,8 +86,6 @@ func main(){ } } - yolo := "ok" - r.Run(":" + port) } From 6cc6e4b8e8f1ab0835957d2327496dd2e303104d Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:06:24 +0100 Subject: [PATCH 35/43] Update config.yml --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f1bdd6b..d54ce52 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,9 +16,9 @@ jobs: frontend: docker: - image: cimg/node:15.5.0 - steps: - - checkout - - run: node --version - - run: yarn build + steps: + - checkout + - run: node --version + - run: yarn build From c2b5b1e8588692fd643dc78fa65b21b943d29066 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:07:56 +0100 Subject: [PATCH 36/43] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d54ce52..976599e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2 jobs: - backend: + build: docker: - image: circleci/golang:1.15 working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} From e21089cdd9c06532c42ce211efd53a12ca236e2c Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:13:20 +0100 Subject: [PATCH 37/43] Update config.yml --- .circleci/config.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 976599e..d0b146f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2 jobs: - build: + backend: docker: - image: circleci/golang:1.15 working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} @@ -22,3 +22,8 @@ jobs: - run: yarn build +workflows: + backend_and_frontend: + jobs: + - backend + - frontend \ No newline at end of file From 75b567e3f41610a6f8601091c1297bfba6664f8c Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:14:09 +0100 Subject: [PATCH 38/43] Update config.yml --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d0b146f..bab131c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,6 +23,7 @@ jobs: workflows: + version: 2 backend_and_frontend: jobs: - backend From 05fa4a04eec0a636a985e2b230e6eefb0c98a32c Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:15:46 +0100 Subject: [PATCH 39/43] Update config.yml --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bab131c..67c1a93 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,9 @@ jobs: steps: - checkout - run: node --version - - run: yarn build + - run: cd frontend && yarn + - run: cd frontend && yarn test + - run: cd frontend && yarn build workflows: From c58a82ec5ec2d9e6ef3a0e71bda3b1ab1a3cf126 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:16:04 +0100 Subject: [PATCH 40/43] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 67c1a93..e3308a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ jobs: workflows: version: 2 - backend_and_frontend: + build: jobs: - backend - frontend \ No newline at end of file From 99385c708334a3e7adf2e08a4769f6b7824144f6 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:23:39 +0100 Subject: [PATCH 41/43] Update main.go --- backend/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/main.go b/backend/main.go index 1b99b8e..e1ec4f8 100644 --- a/backend/main.go +++ b/backend/main.go @@ -85,7 +85,7 @@ func main(){ } } - + fmt.Println(":" + port) r.Run(":" + port) } From 11c696fedc8c958c1429a7431a30c139317571d3 Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:28:30 +0100 Subject: [PATCH 42/43] Update README.md --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d6432eb..3dd93b2 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ # Kerberos Open Source -

- Kerberos Open Source - Twitter Widget -
- Build Status - PkgGoDev - Coverage Status - License: Commons Clause -

+Kerberos Open Source +Twitter Widget +
+ +Build Status +PkgGoDev +Coverage Status +License: Commons Clause [**Docker Hub**](https://hub.docker.com/r/kerberos/opensource) | [**Documentation**](https://doc.kerberos.io) From 06a771af5887324186aea543679276769da635ae Mon Sep 17 00:00:00 2001 From: cedricve Date: Mon, 28 Dec 2020 14:29:35 +0100 Subject: [PATCH 43/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3dd93b2..51f0c4d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Kerberos Open Source Twitter Widget
- + Build Status PkgGoDev Coverage Status