Skip to content

Commit

Permalink
ci: add makefile (apache#800)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

* update apache pulsar link in readme

Signed-off-by: Paul Gier <[email protected]>

Signed-off-by: Paul Gier <[email protected]>

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`
  • Loading branch information
pgier authored Aug 24, 2022
1 parent da24461 commit 2d5f6fc
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 34 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 20 additions & 11 deletions docker-ci.sh → Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
Expand All @@ -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/*
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions run-ci.sh → scripts/run-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2d5f6fc

Please sign in to comment.