Skip to content

Commit

Permalink
add tensorflow filter (#951)
Browse files Browse the repository at this point in the history
* add tensorflow filter

Signed-off-by: kpango <kpango@vdaas.org>

* add tensorflow install command to dockerfile

Signed-off-by: kpango <kpango@vdaas.org>

* fix tensorflow-ingress-filter

Signed-off-by: datelier <57349093+datelier@users.noreply.github.com>

* fix dockerfile & docker commnad

Signed-off-by: datelier <57349093+datelier@users.noreply.github.com>

* fix workflow

Signed-off-by: datelier <57349093+datelier@users.noreply.github.com>

* fix the image-ref field in vulnerability scanner sections

Signed-off-by: datelier <57349093+datelier@users.noreply.github.com>

Co-authored-by: datelier <57349093+datelier@users.noreply.github.com>
  • Loading branch information
kpango and datelier committed Apr 7, 2021
1 parent 0d7d51e commit 619ddeb
Show file tree
Hide file tree
Showing 31 changed files with 3,138 additions and 83 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/dockers-filter-ingress-tensorflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#
# Copyright (C) 2019-2021 vdaas.org vald team <vald@vdaas.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Build docker image: filter-ingress-tensorflow"
on:
push:
branches:
- master
tags:
- "*.*.*"
- "v*.*.*"
- "*.*.*-*"
- "v*.*.*-*"
paths:
- "go.mod"
- "go.sum"
- "internal/**"
- "!internal/**/*_test.go"
- "!internal/**/*_mock.go"
- "!internal/db/**"
- "!internal/k8s/**"
- "apis/grpc/**"
- "pkg/filter/ingress/tensorflow/**"
- "cmd/filter/ingress/tensorflow/**"
- "dockers/base/Dockerfile"
- "dockers/filter/ingress/tensorflow/Dockerfile"
- "versions/GO_VERSION"
pull_request:
paths:
- "go.mod"
- "go.sum"
- "internal/**"
- "!internal/**/*_test.go"
- "!internal/**/*_mock.go"
- "!internal/db/**"
- "!internal/k8s/**"
- "apis/grpc/**"
- "pkg/filter/ingress/tensorflow/**"
- "cmd/filter/ingress/tensorflow/**"
- "dockers/base/Dockerfile"
- "dockers/filter/ingress/tensorflow/Dockerfile"
- "versions/GO_VERSION"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: "--debug"
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASS }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.PACKAGE_USER }}
password: ${{ secrets.PACKAGE_TOKEN }}
- name: Build and Publish
id: build_and_publish
uses: ./.github/actions/docker-build
with:
target: filter-ingress-tensorflow
builder: ${{ steps.buildx.outputs.name }}
- name: Initialize CodeQL
if: startsWith( github.ref, 'refs/tags/')
uses: github/codeql-action/init@v1
- name: Run vulnerability scanner (table)
if: startsWith( github.ref, 'refs/tags/')
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ steps.build_and_publish.outputs.IMAGE_NAME }}:${{ steps.build_and_publish.outputs.PRIMARY_TAG }}"
format: "table"
- name: Run vulnerability scanner (sarif)
if: startsWith( github.ref, 'refs/tags/')
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ steps.build_and_publish.outputs.IMAGE_NAME }}:${{ steps.build_and_publish.outputs.PRIMARY_TAG }}"
format: "template"
template: "@/contrib/sarif.tpl"
output: "trivy-results.sarif"
- name: Upload Trivy scan results to Security tab
if: startsWith( github.ref, 'refs/tags/')
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: "trivy-results.sarif"
slack:
name: Slack notification
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || startsWith( github.ref, 'refs/tags/')
steps:
- uses: technote-space/workflow-conclusion-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: 8398a7/action-slack@v2
with:
author_name: vald-filter-ingress-tensorflow image build
status: ${{ env.WORKFLOW_CONCLUSION }}
only_mention_fail: channel
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFY_WEBHOOK_URL }}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CI_CONTAINER_IMAGE = $(NAME)-ci-container
DEV_CONTAINER_IMAGE = $(NAME)-dev-container
DISCOVERER_IMAGE = $(NAME)-discoverer-k8s
FILTER_GATEWAY_IMAGE = $(NAME)-filter-gateway
FILTER_INGRESS_TF_IMAGE = $(NAME)-filter-ingress-tensorflow
GATEWAY_IMAGE = $(NAME)-gateway
HELM_OPERATOR_IMAGE = $(NAME)-helm-operator
LB_GATEWAY_IMAGE = $(NAME)-lb-gateway
Expand Down
41 changes: 41 additions & 0 deletions Makefile.d/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ binary/build: \
cmd/manager/backup/mysql/backup \
cmd/manager/backup/cassandra/backup \
cmd/manager/compressor/compressor \
cmd/filter/ingress/tensorflow/tensorflow \
cmd/manager/index/index

cmd/agent/core/ngt/ngt: \
Expand Down Expand Up @@ -472,6 +473,39 @@ cmd/manager/replication/controller/controller: \
-o $@ \
$(dir $@)main.go

cmd/filter/ingress/tensorflow/tensorflow: \
tensorflow/install \
$(GO_SOURCES_INTERNAL) \
$(PBGOS) \
$(shell find ./cmd/filter/ingress/tensorflow -type f -name '*.go' -not -name '*_test.go' -not -name 'doc.go') \
$(shell find ./pkg/filter/ingress/tensorflow -type f -name '*.go' -not -name '*_test.go' -not -name 'doc.go')
CFLAGS="$(CFLAGS)" \
CXXFLAGS="$(CXXFLAGS)" \
CGO_ENABLED=1 \
CGO_CXXFLAGS="-g -Ofast -march=native" \
CGO_FFLAGS="-g -Ofast -march=native" \
CGO_LDFLAGS="-g -Ofast -march=native" \
GO111MODULE=on \
GOPRIVATE=$(GOPRIVATE) \
go build \
--ldflags "-s -w \
-extldflags '-pthread -fopenmp -std=gnu++2a -lstdc++ -lm $(EXTLDFLAGS)' \
-X '$(GOPKG)/internal/info.Version=$(VERSION)' \
-X '$(GOPKG)/internal/info.GitCommit=$(GIT_COMMIT)' \
-X '$(GOPKG)/internal/info.BuildTime=$(DATETIME)' \
-X '$(GOPKG)/internal/info.GoVersion=$(GO_VERSION)' \
-X '$(GOPKG)/internal/info.GoOS=$(GOOS)' \
-X '$(GOPKG)/internal/info.GoArch=$(GOARCH)' \
-X '$(GOPKG)/internal/info.CGOEnabled=$${CGO_ENABLED}' \
-X '$(GOPKG)/internal/info.NGTVersion=$(NGT_VERSION)' \
-X '$(GOPKG)/internal/info.BuildCPUInfoFlags=$(CPU_INFO_FLAGS)' \
-buildid=" \
-a \
-tags "cgo osusergo netgo static_build" \
-trimpath \
-o $@ \
$(dir $@)main.go

.PHONY: binary/build/zip
## build all binaries and zip them
binary/build/zip: \
Expand All @@ -481,6 +515,7 @@ binary/build/zip: \
artifacts/vald-gateway-$(GOOS)-$(GOARCH).zip \
artifacts/vald-lb-gateway-$(GOOS)-$(GOARCH).zip \
artifacts/vald-meta-gateway-$(GOOS)-$(GOARCH).zip \
artifacts/vald-filter-ingress-tensorflow-$(GOOS)-$(GOARCH).zip \
artifacts/vald-backup-gateway-$(GOOS)-$(GOARCH).zip \
artifacts/vald-meta-redis-$(GOOS)-$(GOARCH).zip \
artifacts/vald-meta-cassandra-$(GOOS)-$(GOARCH).zip \
Expand Down Expand Up @@ -544,3 +579,9 @@ artifacts/vald-manager-compressor-$(GOOS)-$(GOARCH).zip: cmd/manager/compressor/
artifacts/vald-manager-index-$(GOOS)-$(GOARCH).zip: cmd/manager/index/index
$(call mkdir, $(dir $@))
zip --junk-paths $@ $<


artifacts/vald-filter-ingress-tensorflow-$(GOOS)-$(GOARCH).zip: cmd/filter/ingress/tensorflow/tensorflow
$(call mkdir, $(dir $@))
zip --junk-paths $@ $<

16 changes: 16 additions & 0 deletions Makefile.d/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ docker/build: \
docker/build/backup-manager-cassandra \
docker/build/manager-compressor \
docker/build/manager-index \
docker/build/filter-ingress-tensorflow \
docker/build/helm-operator

.PHONY: docker/name/org
Expand Down Expand Up @@ -279,6 +280,21 @@ docker/build/manager-index:
--build-arg MAINTAINER=$(MAINTAINER) \
--build-arg UPX_OPTIONS=$(UPX_OPTIONS)

.PHONY: docker/name/filter-ingress-tensorflow
docker/name/filter-ingress-tensorflow:
@echo "$(ORG)/$(FILTER_INGRESS_TF_IMAGE)"

.PHONY: docker/build/filter-ingress-tensorflow
## build filter-ingress-tensorflow image
docker/build/filter-ingress-tensorflow:
$(DOCKER) build \
$(DOCKER_OPTS) \
-f dockers/filter/ingress/tensorflow/Dockerfile \
-t $(ORG)/$(FILTER_INGRESS_TF_IMAGE):$(TAG) . \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg DISTROLESS_IMAGE_TAG=$(DISTROLESS_IMAGE_TAG) \
--build-arg MAINTAINER=$(MAINTAINER)

.PHONY: docker/name/ci-container
docker/name/ci-container:
@echo "$(ORG)/$(CI_CONTAINER_IMAGE)"
Expand Down
59 changes: 59 additions & 0 deletions cmd/filter/ingress/tensorflow/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Copyright (C) 2019-2021 vdaas.org vald team <vald@vdaas.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package main provides program main
package main

import (
"context"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/info"
"github.com/vdaas/vald/internal/log"
"github.com/vdaas/vald/internal/runner"
"github.com/vdaas/vald/internal/safety"
"github.com/vdaas/vald/pkg/filter/ingress/tensorflow/config"
"github.com/vdaas/vald/pkg/filter/ingress/tensorflow/usecase"
)

const (
maxVersion = "v0.0.10"
minVersion = "v0.0.0"
name = "tensorflow ingress filter"
)

func main() {
if err := safety.RecoverFunc(func() error {
return runner.Do(
context.Background(),
runner.WithName(name),
runner.WithVersion(info.Version, maxVersion, minVersion),
runner.WithConfigLoader(func(path string) (interface{}, *config.GlobalConfig, error) {
cfg, err := config.NewConfig(path)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to load "+name+"'s configuration")
}
return cfg, &cfg.GlobalConfig, nil
}),
runner.WithDaemonInitializer(func(cfg interface{}) (runner.Runner, error) {
return usecase.New(cfg.(*config.Data))
}),
)
})(); err != nil {
log.Fatal(err, info.Get())
return
}
}
Empty file.
92 changes: 92 additions & 0 deletions dockers/filter/ingress/tensorflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# Copyright (C) 2019-2021 vdaas.org vald team <vald@vdaas.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ARG GO_VERSION=latest
ARG DISTROLESS_IMAGE=gcr.io/distroless/cc
ARG DISTROLESS_IMAGE_TAG=nonroot
ARG MAINTAINER="vdaas.org vald team <vald@vdaas.org>"

FROM golang:${GO_VERSION} AS builder

ENV GO111MODULE on
ENV DEBIAN_FRONTEND noninteractive
ENV INITRD No
ENV LANG en_US.UTF-8
ENV ORG vdaas
ENV REPO vald
ENV PKG filter/ingress/tensorflow
ENV APP_NAME tensorflow

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
build-essential \
cmake \
upx \
curl \
unzip \
git \
gcc \
g++ \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p $GOPATH/src

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}

COPY go.mod .
COPY go.sum .

RUN go mod download

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/internal
COPY internal .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/apis/grpc
COPY apis/grpc .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/pkg/${PKG}
COPY pkg/${PKG} .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/cmd/${PKG}
COPY cmd/${PKG} .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/versions
COPY versions .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}/Makefile.d
COPY Makefile.d .

WORKDIR ${GOPATH}/src/github.com/${ORG}/${REPO}
COPY Makefile .
COPY .git .

RUN make REPO=${ORG} NAME=${REPO} cmd/${PKG}/${APP_NAME} \
&& cp "cmd/${PKG}/${APP_NAME}" "/usr/bin/${APP_NAME}"

FROM ${DISTROLESS_IMAGE}:${DISTROLESS_IMAGE_TAG}
LABEL maintainer "${MAINTAINER}"

ENV APP_NAME tensorflow

COPY --from=builder /usr/bin/${APP_NAME} /go/bin/${APP_NAME}
COPY --from=builder /usr/local/lib/libtensorflow* /usr/local/lib/

ENV LD_LIBRARY_PATH /usr/local/lib

USER nonroot:nonroot

ENTRYPOINT ["/go/bin/tensorflow"]
Loading

0 comments on commit 619ddeb

Please sign in to comment.