diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..a4f668f5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,31 @@ +name: Build and push the latest image if needed + +on: + pull_request: + branches: + - master + - release-* + push: + branches: + - master + - release-* + +jobs: + build: + if: ${{ github.event_name == 'push' }} + runs-on: [ubuntu-18.04] + steps: + - uses: actions/checkout@v2 + - name: Build ipfix-collector Docker image + run: | + make collector + make docker-collector + - name: Push ipfix-collector Docker image to harbor registry + if: ${{ github.repository == 'vmware/go-ipfix' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} + env: + HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }} + HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} + HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }} + run: | + echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USERNAME" --password-stdin $HARBOR_REGISTRY + docker push goipfix/ipfix-collector:latest \ No newline at end of file diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml new file mode 100644 index 00000000..a97c8f9f --- /dev/null +++ b/.github/workflows/build_tag.yml @@ -0,0 +1,24 @@ +name: Build and push a release image + +on: + push: + tags: + - v* + +jobs: + build: + runs-on: [ubuntu-18.04] + steps: + - uses: actions/checkout@v2 + - name: Build go-ipfix Docker images and push to harbor registry + env: + HARBOR_REGISTRY: ${{ secrets.HARBOR_REGISTRY }} + HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }} + HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }} + TAG: ${{ github.ref }} + run: | + make collector + make docker-collector + echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USERNAME" --password-stdin $HARBOR_REGISTRY + docker tag goipfix/ipfix-collector goipfix/ipfix-collector:"${TAG:10}" + docker push goipfix/ipfix-collector:"${TAG:10}" diff --git a/Makefile b/Makefile index 80745bfd..3cfe73e3 100644 --- a/Makefile +++ b/Makefile @@ -22,3 +22,9 @@ golangci: collector: @mkdir -p $(BINDIR) GOOS=linux $(GO) build -o $(BINDIR) github.com/vmware/go-ipfix/cmd/collector/ + +### Docker images ### + +docker-collector: + @echo "===> Building goipfix/ipfix-collector Docker image <===" + docker build --pull -t goipfix/ipfix-collector -f build/images/Dockerfile.build.collector . diff --git a/build/images/Dockerfile.build.collector b/build/images/Dockerfile.build.collector new file mode 100644 index 00000000..1a6372ac --- /dev/null +++ b/build/images/Dockerfile.build.collector @@ -0,0 +1,21 @@ +FROM golang:1.15 as go-ipfix-build + +WORKDIR /go-ipfix + +COPY go.mod /go-ipfix/go.mod + +RUN go mod download + +COPY . /go-ipfix + +RUN make collector + + +FROM antrea/base-ubuntu:2.14.0 + +FROM ubuntu:18.04 + +LABEL maintainer="go-ipfix" +LABEL description="A Docker image based on Ubuntu 18.04 which contains a IPFIX collector" + +COPY --from=go-ipfix-build /go-ipfix/bin/collector /usr/local/bin/