Skip to content

Commit

Permalink
[feat] add agent full (#2315)
Browse files Browse the repository at this point in the history
[feat] add agent full (#2315)
  • Loading branch information
etaques authored Apr 21, 2023
1 parent f7f0379 commit c99b202
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 1 deletion.
85 changes: 84 additions & 1 deletion .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ on:
inputs:
pktvisor_tag:
description: 'pktvisor agent docker tag to package'
required: true
default: "develop"
diode_tag:
description: 'diode agent docker tag to package'
default: "develop"
orb_tag:
description: 'orb agent docker tag to package'
default: "develop"

repository_dispatch:
types: [build-agent]
Expand Down Expand Up @@ -131,3 +137,80 @@ jobs:
- name: Push agent container orbcommunity
if: github.event_name != 'pull_request'
run: docker push -a orbcommunity/orb-agent


package-agent-full:
needs: package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Get branch name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

- name: Debug branch name
run: echo ${{ env.BRANCH_NAME }}

- name: Generate ref tag (main)
if: ${{ env.BRANCH_NAME == 'main' || github.event.client_payload.branch_name == 'main' }}
run: |
echo "REF_TAG=latest" >> $GITHUB_ENV
- name: Generate ref tag (develop)
if: ${{ env.BRANCH_NAME == 'develop' || github.event.client_payload.branch_name == 'develop' }}
run: |
echo "REF_TAG=develop" >> $GITHUB_ENV
- name: Debug ref tag
run: echo ${{ env.REF_TAG }}

- name: Append suffix on VERSION file for develop build
if: ${{ env.BRANCH_NAME == 'develop' || github.event.client_payload.branch_name == 'develop' }}
run: |
echo "`cat ${{github.workspace}}/VERSION`-${{ env.REF_TAG }}" > VERSION
- name: Get VERSION
run: |
echo "VERSION=`cat ${{github.workspace}}/VERSION`" >> $GITHUB_ENV
- name: Debug version
run: echo ${{ env.VERSION }}

- name: Replace crashpad and geo-db params
run: |
ESCAPED_REPLACE_LINE1_NEW=$(printf '%s\n' "pvOptions = append(pvOptions, \"--cp-token\", \"${{ secrets.CRASHPAD_TOKEN }}\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE2_NEW=$(printf '%s\n' "pvOptions = append(pvOptions, \"--cp-url\", \"${{ secrets.CRASHPAD_URL }}\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE3_NEW=$(printf '%s\n' "pvOptions = append(pvOptions, \"--cp-path\", \"/usr/local/sbin/crashpad_handler\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE4_NEW=$(printf '%s\n' "pvOptions = append(pvOptions, \"--default-geo-city\", \"/geo-db/city.mmdb\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE5_NEW=$(printf '%s\n' "pvOptions = append(pvOptions, \"--default-geo-asn\", \"/geo-db/asn.mmdb\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE6_NEW=$(printf '%s\n' "pvOptions = append(pvOptions, \"--default-service-registry\", \"/iana/custom-iana.csv\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE1_OLD=$(printf '%s\n' "// pvOptions = append(pvOptions, \"--cp-token\", PKTVISOR_CP_TOKEN)" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE2_OLD=$(printf '%s\n' "// pvOptions = append(pvOptions, \"--cp-url\", PKTVISOR_CP_URL)" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE3_OLD=$(printf '%s\n' "// pvOptions = append(pvOptions, \"--cp-path\", PKTVISOR_CP_PATH)" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE4_OLD=$(printf '%s\n' "// pvOptions = append(pvOptions, \"--default-geo-city\", \"/geo-db/city.mmdb\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE5_OLD=$(printf '%s\n' "// pvOptions = append(pvOptions, \"--default-geo-asn\", \"/geo-db/asn.mmdb\")" | sed -e 's/[\/&]/\\&/g')
ESCAPED_REPLACE_LINE6_OLD=$(printf '%s\n' "// pvOptions = append(pvOptions, \"--default-service-registry\", \"/iana/custom-iana.csv\")" | sed -e 's/[\/&]/\\&/g')
sed -i -e "s/$ESCAPED_REPLACE_LINE1_OLD/$ESCAPED_REPLACE_LINE1_NEW/g" agent/backend/pktvisor/pktvisor.go
sed -i -e "s/$ESCAPED_REPLACE_LINE2_OLD/$ESCAPED_REPLACE_LINE2_NEW/g" agent/backend/pktvisor/pktvisor.go
sed -i -e "s/$ESCAPED_REPLACE_LINE3_OLD/$ESCAPED_REPLACE_LINE3_NEW/g" agent/backend/pktvisor/pktvisor.go
sed -i -e "s/$ESCAPED_REPLACE_LINE4_OLD/$ESCAPED_REPLACE_LINE4_NEW/g" agent/backend/pktvisor/pktvisor.go
sed -i -e "s/$ESCAPED_REPLACE_LINE5_OLD/$ESCAPED_REPLACE_LINE5_NEW/g" agent/backend/pktvisor/pktvisor.go
sed -i -e "s/$ESCAPED_REPLACE_LINE6_OLD/$ESCAPED_REPLACE_LINE6_NEW/g" agent/backend/pktvisor/pktvisor.go
- name: Build orb-agent full
shell: bash
run: |
DIODE_TAG=${{ github.event.inputs.diode_tag }} PKTVISOR_TAG=${{ github.event.inputs.pktvisor_tag }} ORB_TAG=${{ github.event.inputs.orb_tag }} make agent_full
- name: Login to Docker Hub orbcommunity
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.ORB_DOCKERHUB_USERNAME }}
password: ${{ secrets.ORB_DOCKERHUB_TOKEN }}

- name: Push agent container orbcommunity
if: github.event_name != 'pull_request'
run: docker push -a orbcommunity/orb-agent-full
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ agent:
--tag=$(ORB_DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-agent:$(ORB_VERSION) \
--tag=$(ORB_DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-agent:$(ORB_VERSION)-$(COMMIT_HASH) \
-f agent/docker/Dockerfile .

agent_full:
docker build --no-cache \
--build-arg PKTVISOR_TAG=$(PKTVISOR_TAG) \
--build-arg DIODE_TAG=$(DIODE_TAG) \
--build-arg ORB_TAG=${ORB_TAG} \
--tag=$(ORB_DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-agent-full:$(REF_TAG) \
--tag=$(ORB_DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-agent-full:$(ORB_VERSION) \
--tag=$(ORB_DOCKERHUB_REPO)/$(DOCKER_IMAGE_NAME_PREFIX)-agent-full:$(ORB_VERSION)-$(COMMIT_HASH) \
-f agent/docker/Dockerfile.full .

agent_debug:
docker build \
Expand Down
34 changes: 34 additions & 0 deletions agent/docker/Dockerfile.full
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PKTVISOR_TAG=develop
ARG DIODE_TAG=develop
ARG ORB_TAG=develop
FROM orbcommunity/orb-agent:${ORB_TAG} AS orb

FROM orbcommunity/diode-agent:${DIODE_TAG} AS diode
RUN SQPATH=$(pip show suzieq | sed -n 's/Location: \(.*\)/\1/p') \
&& cp -rf "$SQPATH/suzieq" "/tmp/suzieq-patched"

FROM orbcommunity/pktvisor:${PKTVISOR_TAG}
# adding orb-agent
RUN mkdir /opt/orb
COPY --from=orb /usr/local/bin/orb-agent /usr/local/bin/orb-agent
COPY --from=orb /opt/orb/agent_default.yaml /opt/orb/agent_default.yaml
COPY --from=orb /usr/local/bin/orb-agent-entry.sh /usr/local/bin/orb-agent-entry.sh
COPY --from=orb /run-agent.sh /run-agent.sh

# adding diode-agent
COPY --from=diode /usr/local/bin/diode-agent /usr/local/bin/diode-agent

# adding suzieq
RUN apt-get update && apt-get install -y python3 python3-pip
RUN python3 -m pip install --upgrade pip && pip install suzieq==0.20.1

# adding suzieq patched
COPY --from=diode /root/.suzieq /root/.suzieq
COPY --from=diode /tmp/suzieq-patched /tmp/suzieq-patched
RUN SQPATH=$(pip show suzieq | sed -n 's/Location: \(.*\)/\1/p') \
&& cp -rf /tmp/suzieq-patched/* "$SQPATH/suzieq/" \
&& rm -rf /tmp/suzieq-patched

RUN chmod a+x /run-agent.sh

ENTRYPOINT [ "/usr/local/bin/orb-agent-entry.sh" ]

0 comments on commit c99b202

Please sign in to comment.