mirror of
https://github.com/kerberos-io/agent.git
synced 2026-08-23 15:08:32 +00:00
155 lines
4.7 KiB
Docker
155 lines
4.7 KiB
Docker
FROM kerberos/base:37a6e69 AS build
|
|
LABEL AUTHOR=Kerberos.io
|
|
|
|
ENV GOROOT=/usr/local/go
|
|
ENV GOPATH=/go
|
|
ENV PATH=$GOPATH/bin:$GOROOT/bin:/usr/local/lib:$PATH
|
|
ENV GOSUMDB=off
|
|
|
|
##########################################
|
|
# Installing some additional dependencies.
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
git build-essential cmake pkg-config unzip libgtk2.0-dev \
|
|
curl ca-certificates libcurl4-openssl-dev libssl-dev libjpeg62-turbo-dev && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
##############################################################################
|
|
# Copy all the relevant source code in the Docker image, so we can build this.
|
|
|
|
RUN mkdir -p /go/src/github.com/kerberos-io/agent
|
|
COPY machinery /go/src/github.com/kerberos-io/agent/machinery
|
|
COPY ui /go/src/github.com/kerberos-io/agent/ui
|
|
|
|
##################################################################
|
|
# Get the latest commit hash, so we know which version we're running
|
|
COPY .git /go/src/github.com/kerberos-io/agent/.git
|
|
RUN cd /go/src/github.com/kerberos-io/agent/.git && git log --format="%H" -n 1 | head -c7 > /go/src/github.com/kerberos-io/agent/machinery/version
|
|
RUN cat /go/src/github.com/kerberos-io/agent/machinery/version
|
|
|
|
########################
|
|
# Download NPM and Yarns
|
|
|
|
RUN mkdir /usr/local/nvm
|
|
ENV NVM_DIR /usr/local/nvm
|
|
ENV NODE_VERSION 16.17.0
|
|
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
|
|
&& . $NVM_DIR/nvm.sh \
|
|
&& nvm install $NODE_VERSION \
|
|
&& nvm alias default $NODE_VERSION \
|
|
&& nvm use default
|
|
|
|
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
|
|
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
|
|
|
|
RUN wget https://github.com/yarnpkg/yarn/releases/download/v1.22.19/yarn_1.22.19_all.deb && \
|
|
dpkg -i yarn_1.22.19_all.deb
|
|
|
|
##################################################################
|
|
# Build Web
|
|
# this will move the /build directory to ../machinery/www
|
|
|
|
RUN cd /go/src/github.com/kerberos-io/agent/ui && yarn && yarn build
|
|
|
|
##################
|
|
# Build Machinery
|
|
|
|
RUN cd /go/src/github.com/kerberos-io/agent/machinery && \
|
|
go mod download && \
|
|
go build -tags timetzdata --ldflags '-s -w -extldflags "-static -latomic"' main.go && \
|
|
mkdir -p /agent && \
|
|
mv main /agent && \
|
|
mv www /agent && \
|
|
mv version /agent && \
|
|
mv data /agent && \
|
|
mkdir -p /agent/data/cloud && \
|
|
mkdir -p /agent/data/snapshots && \
|
|
mkdir -p /agent/data/log && \
|
|
mkdir -p /agent/data/recordings && \
|
|
mkdir -p /agent/data/capture-test && \
|
|
mkdir -p /agent/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 /agent ./
|
|
|
|
####################################################################################
|
|
# This will collect dependent libraries so they're later copied to the final image.
|
|
|
|
RUN /agent/main version
|
|
|
|
###############################################
|
|
# Build Bento4 -> we want fragmented mp4 files
|
|
|
|
ENV BENTO4_VERSION 1.6.0-639
|
|
RUN cd /tmp && git clone https://github.com/axiomatic-systems/Bento4 && cd Bento4 && \
|
|
git checkout tags/v${BENTO4_VERSION} && \
|
|
cd Build && \
|
|
cmake -DCMAKE_BUILD_TYPE=Release .. && \
|
|
make && \
|
|
mv /tmp/Bento4/Build/mp4fragment /dist/ && \
|
|
rm -rf /tmp/Bento4
|
|
|
|
############################################
|
|
# Publish main binary to GitHub release
|
|
|
|
FROM alpine:latest
|
|
|
|
############################
|
|
# Protect by non-root user.
|
|
|
|
RUN addgroup -S kerberosio && adduser -S agent -G kerberosio && addgroup agent video
|
|
|
|
#################################
|
|
# Copy files from previous images
|
|
|
|
COPY --chown=0:0 --from=build /dist /
|
|
|
|
RUN apk update && apk add ca-certificates curl libstdc++ libc6-compat --no-cache && rm -rf /var/cache/apk/*
|
|
RUN mv /mp4fragment /usr/local/bin/
|
|
|
|
##################
|
|
# Try running agent
|
|
|
|
RUN mv /agent/* /home/agent/
|
|
RUN /home/agent/main version
|
|
|
|
#######################
|
|
# Make template config
|
|
|
|
RUN cp /home/agent/data/config/config.json /home/agent/data/config.template.json
|
|
|
|
###########################
|
|
# Set permissions correctly
|
|
|
|
RUN chown -R agent:kerberosio /home/agent/data
|
|
|
|
###########################
|
|
# Grant the necessary root capabilities to the process trying to bind to the privileged port
|
|
RUN apk add libcap && setcap 'cap_net_bind_service=+ep' /home/agent/main
|
|
|
|
###################
|
|
# Run non-root user
|
|
|
|
USER agent
|
|
|
|
######################################
|
|
# By default the app runs on port 80
|
|
|
|
EXPOSE 80
|
|
|
|
######################################
|
|
# Check if agent is still running
|
|
|
|
HEALTHCHECK CMD curl --fail http://localhost:80 || exit 1
|
|
|
|
###################################################
|
|
# Leeeeettttt'ssss goooooo!!!
|
|
# Run the shizzle from the right working directory.
|
|
WORKDIR /home/agent
|
|
CMD ["./main", "run", "opensource", "80"]
|