diff --git a/api/.dockerignore b/.dockerignore similarity index 89% rename from api/.dockerignore rename to .dockerignore index 5f5b607e8..464de808c 100644 --- a/api/.dockerignore +++ b/.dockerignore @@ -14,3 +14,4 @@ LICENSE .git/ .github/ build/ +**/node_modules/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..19fdf3004 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +FROM node:14-slim AS site-build + +WORKDIR /ui-build + +COPY ui ./ +RUN npm i +RUN npm run build + + +FROM golang:1.16-alpine AS builder +# Set necessary environment variables needed for our image. +ENV CGO_ENABLED=1 GOOS=linux GOARCH=amd64 + +RUN apk add libpcap-dev gcc g++ make + +# Move to tapper working directory (/tap-build). +WORKDIR /tap-build +COPY tap/go.mod tap/go.sum ./ +RUN go mod download +# Copy and build tapper code +COPY tap/src ./ +RUN go build -ldflags="-s -w" -o passivetapper . + +# Move to api working directory (/api-build). +WORKDIR /api-build +COPY api/go.mod api/go.sum ./ +RUN go mod download +# Copy and build api code +COPY api . +RUN go build -ldflags="-s -w" -o apiserver . + + +FROM alpine:3.13.5 +RUN apk add parallel libpcap-dev +RUN apk add tcpdump +# Copy binary and config files from /build to root folder of scratch container. +COPY --from=builder ["/api-build/apiserver", "/"] +COPY --from=builder ["/tap-build/passivetapper", "/"] +COPY --from=site-build ["/ui-build/build", "/site"] + +# parallel will exit if one of the executables exits, ensuring this container does not run without one of the processes + +ENV HOST_MODE="1" +CMD parallel --halt now,done=1 ::: './apiserver' './passivetapper -i any -hardump -hardir /tmp/up9hars -harentriesperfile 10' \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile deleted file mode 100644 index 5fac361f5..000000000 --- a/api/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -FROM golang:1.16 AS builder - -# Move to working directory (/site). -WORKDIR /build - -# Copy and download dependency using go mod. -COPY go.mod go.sum ./ -RUN go mod download - -# Copy the code into the container. -COPY . . - -# Set necessary environmet variables needed for our image and site the API server. -ENV GOOS=linux GOARCH=amd64 -RUN go build -ldflags="-s -w" -o apiserver . - -FROM golang:1.16 - -# Copy binary and config files from /site to root folder of scratch container. -COPY --from=builder ["/build/apiserver", "/"] - -# Export necessary port. -EXPOSE 8899 - -COPY site /go/site -COPY entries.db /go/entries.db - -# Command to run when starting the container. -ENTRYPOINT ["/apiserver"] diff --git a/api/pkg/inserter/main.go b/api/pkg/inserter/main.go index 16969afbc..b9d61e1dd 100644 --- a/api/pkg/inserter/main.go +++ b/api/pkg/inserter/main.go @@ -41,6 +41,7 @@ func StartReadingFiles(workingDir string) { utils.CheckErr(decErr) for _, entry := range inputHar.Log.Entries { + time.Sleep(time.Millisecond * 250) SaveHarToDb(*entry, "") } rmErr := os.Remove(inputFilePath) diff --git a/tap/src/tcp_stream_factory.go b/tap/src/tcp_stream_factory.go index bf69f2622..ae37896ef 100644 --- a/tap/src/tcp_stream_factory.go +++ b/tap/src/tcp_stream_factory.go @@ -84,6 +84,8 @@ func (factory *tcpStreamFactory) WaitGoRoutines() { } func (factory *tcpStreamFactory) shouldTap(dstIP string, dstPort int) bool { + return true + if hostMode { return inArrayString(hostAppAddresses, fmt.Sprintf("%s:%d", dstIP, dstPort)) } else {