From 2d5f6fcfa22af4184793a22ca353731a02b54ca9 Mon Sep 17 00:00:00 2001 From: Paul Gier Date: Wed, 24 Aug 2022 00:35:37 -0500 Subject: [PATCH] ci: add makefile (#800) * ci: add makefile - add a Makefile with basic build, test, clean, etc. - simplify the Dockerfile by moving some scripts and conf files to directories - update README - allow easy setting of GOLANG version and PULSAR version for testing Signed-off-by: Paul Gier * dockerfile: copy individual conf files Copy individual config files instead of directory when building the Dockerfile to catch any missing/incorrect files. Signed-off-by: Paul Gier * update apache pulsar link in readme Signed-off-by: Paul Gier Signed-off-by: Paul Gier Makefiles are commonly used for building golang projects. - add a Makefile with basic build, test, clean, etc. - simplify the Dockerfile by moving some scripts and conf files to directories - update README - Allows easy overriding of pulsar version and golang version used during testing ### Motivation Add a Makefile to make it easier to remember the commands for building and testing the project. For example: * `make build` instead of `go build ./pulsar` * `make test` instead of `./docker-ci.sh` * `make lint` instead of `golangci-lint run` --- .github/workflows/project.yml | 5 ++- Dockerfile | 23 ++++++++------ docker-ci.sh => Makefile | 31 ++++++++++++------- README.md | 18 ++++++----- integration-tests/{ => conf}/.htpasswd | 0 integration-tests/{ => conf}/client.conf | 0 integration-tests/{ => conf}/standalone.conf | 0 .../pulsar-test-service-start.sh | 0 .../pulsar-test-service-stop.sh | 0 run-ci.sh => scripts/run-ci.sh | 6 ++-- 10 files changed, 49 insertions(+), 34 deletions(-) rename docker-ci.sh => Makefile (57%) mode change 100755 => 100644 rename integration-tests/{ => conf}/.htpasswd (100%) rename integration-tests/{ => conf}/client.conf (100%) rename integration-tests/{ => conf}/standalone.conf (100%) rename pulsar-test-service-start.sh => scripts/pulsar-test-service-start.sh (100%) rename pulsar-test-service-stop.sh => scripts/pulsar-test-service-stop.sh (100%) rename run-ci.sh => scripts/run-ci.sh (90%) diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index cd3d373cab..dc5a755440 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 - name: build - run: go build ./pulsar + run: make build lint: runs-on: ubuntu-latest @@ -34,5 +34,4 @@ jobs: uses: actions/checkout@v3 - name: Run Tests - run: | - ./docker-ci.sh ${{ matrix.go-version }} + run: make test GO_VERSION=${{ matrix.go-version }} diff --git a/Dockerfile b/Dockerfile index 6dd5817935..dcc6a26f7b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,21 +17,24 @@ # under the License. # -ARG GO_VERSION=golang:1.15 -FROM apachepulsar/pulsar:2.8.2 as pulsar -FROM $GO_VERSION as go +# Explicit version of Pulsar and Golang images should be +# set via the Makefile or CLI +ARG PULSAR_IMAGE=apachepulsar/pulsar:latest +ARG GOLANG_IMAGE=golang:latest + +FROM $PULSAR_IMAGE as pulsar +FROM $GOLANG_IMAGE RUN apt-get update && apt-get install -y openjdk-11-jre-headless ca-certificates COPY --from=pulsar /pulsar /pulsar -### Add test scripts +### Add pulsar config COPY integration-tests/certs /pulsar/certs COPY integration-tests/tokens /pulsar/tokens -COPY integration-tests/standalone.conf /pulsar/conf -COPY integration-tests/client.conf /pulsar/conf -COPY integration-tests/.htpasswd /pulsar/conf +COPY integration-tests/conf/.htpasswd \ + integration-tests/conf/client.conf \ + integration-tests/conf/standalone.conf \ + /pulsar/conf/ + ENV PULSAR_EXTRA_OPTS="-Dpulsar.auth.basic.conf=/pulsar/conf/.htpasswd" -COPY pulsar-test-service-start.sh /pulsar/bin -COPY pulsar-test-service-stop.sh /pulsar/bin -COPY run-ci.sh /pulsar/bin diff --git a/docker-ci.sh b/Makefile old mode 100755 new mode 100644 similarity index 57% rename from docker-ci.sh rename to Makefile index 37f97e7c7e..130057ec90 --- a/docker-ci.sh +++ b/Makefile @@ -1,4 +1,3 @@ -#!/bin/bash # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -18,17 +17,27 @@ # under the License. # -set -e -x +IMAGE_NAME = pulsar-client-go-test:latest +PULSAR_VERSION ?= 2.8.3 +PULSAR_IMAGE = apachepulsar/pulsar:$(PULSAR_VERSION) +GO_VERSION ?= 1.18 +GOLANG_IMAGE = golang:$(GO_VERSION) -SRC_DIR=$(git rev-parse --show-toplevel) -cd ${SRC_DIR} +build: + go build ./pulsar + go build -o bin/pulsar-perf ./perf -IMAGE_NAME=pulsar-client-go-test:latest +lint: + golangci-lint run -GO_VERSION=${1:-1.16} -docker rmi --force ${IMAGE_NAME} || true -docker rmi --force apachepulsar/pulsar:latest || true -docker build -t ${IMAGE_NAME} --build-arg GO_VERSION="golang:${GO_VERSION}" . +container: + docker build -t ${IMAGE_NAME} --build-arg GOLANG_IMAGE="${GOLANG_IMAGE}" \ + --build-arg PULSAR_IMAGE="${PULSAR_IMAGE}" . -docker run -i -v ${PWD}:/pulsar-client-go ${IMAGE_NAME} \ - bash -c "cd /pulsar-client-go && ./run-ci.sh" +test: container + docker run -i -v ${PWD}:/pulsar-client-go ${IMAGE_NAME} \ + bash -c "cd /pulsar-client-go && ./scripts/run-ci.sh" + +clean: + docker rmi --force $(IMAGE_NAME) || true + rm bin/* diff --git a/README.md b/README.md index a2276f58ef..9dff20553c 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ [![LICENSE](https://img.shields.io/hexpm/l/pulsar.svg)](https://github.com/apache/pulsar-client-go/blob/master/LICENSE) # Apache Pulsar Go Client Library -A Go client library for the [Apache Pulsar](https://pulsar.incubator.apache.org/) project. +A Go client library for [Apache Pulsar](https://pulsar.apache.org/). -## Goal +## Purpose -This projects is developing a pure-Go client library for Pulsar that does not +This project is a pure-Go client library for Pulsar that does not depend on the C++ Pulsar library. Once feature parity and stability are reached, this will supersede the current @@ -138,17 +138,21 @@ for reader.HasNext() { Build the sources: - go build ./pulsar + make build -Run the unit tests: +Run the tests: - ./docker-ci.sh + make test + +Run the tests with specific versions of GOLANG and PULSAR: + + make test GOLANG_VERSION=1.18 PULSAR_VERSION=2.10.0 ## Contributing Contributions are welcomed and greatly appreciated. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on submitting patches and the contribution workflow. -## Contact +## Community ##### Mailing lists diff --git a/integration-tests/.htpasswd b/integration-tests/conf/.htpasswd similarity index 100% rename from integration-tests/.htpasswd rename to integration-tests/conf/.htpasswd diff --git a/integration-tests/client.conf b/integration-tests/conf/client.conf similarity index 100% rename from integration-tests/client.conf rename to integration-tests/conf/client.conf diff --git a/integration-tests/standalone.conf b/integration-tests/conf/standalone.conf similarity index 100% rename from integration-tests/standalone.conf rename to integration-tests/conf/standalone.conf diff --git a/pulsar-test-service-start.sh b/scripts/pulsar-test-service-start.sh similarity index 100% rename from pulsar-test-service-start.sh rename to scripts/pulsar-test-service-start.sh diff --git a/pulsar-test-service-stop.sh b/scripts/pulsar-test-service-stop.sh similarity index 100% rename from pulsar-test-service-stop.sh rename to scripts/pulsar-test-service-stop.sh diff --git a/run-ci.sh b/scripts/run-ci.sh similarity index 90% rename from run-ci.sh rename to scripts/run-ci.sh index 2de0eee5d7..e9d768bb1f 100755 --- a/run-ci.sh +++ b/scripts/run-ci.sh @@ -27,12 +27,12 @@ go mod download # Basic compilation go build ./pulsar -go build -o pulsar-perf ./perf +go build -o bin/pulsar-perf ./perf -./pulsar-test-service-start.sh +scripts/pulsar-test-service-start.sh go test -race -coverprofile=/tmp/coverage -timeout=20m ./... go tool cover -html=/tmp/coverage -o coverage.html -./pulsar-test-service-stop.sh +scripts/pulsar-test-service-stop.sh