diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c54c4888..ea291d83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,4 +73,62 @@ jobs: key: golangci-lint-${{ steps.golangci-lint-cache-info.outputs.version }}-go-${{ steps.setup-go.outputs.go-version }}-mod-${{ hashFiles('go.sum') }} - name: Run golangci-lint - run: make go-lint \ No newline at end of file + run: make go-lint + + build: + if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id + name: Build (${{ matrix.os }}/${{ matrix.arch }}) + strategy: + matrix: + os: [ linux ] + arch: [ amd64, arm64 ] + include: + - os: linux + runner: ubuntu-latest + fail-fast: true + runs-on: ${{ matrix.runner }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Go + uses: ./.github/actions/setup-go + with: + cache-prefix: build-${{ matrix.os }}-${{ matrix.arch }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker metadata + id: docker-metadata + uses: docker/metadata-action@v5 + with: + images: yunikorn-history-server + tags: | + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=edge + + - name: Build software distribution + run: make dist + env: + GOOS: ${{ matrix.os }} + GOARCH: ${{ matrix.arch }} + DOCKER_METADATA: ${{ steps.docker-metadata.outputs.json }} + DOCKER_OUTPUT: type=oci,dest=yunikorn-history-server-oci-${{ matrix.arch }}.tar + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: yunikorn-history-server-archives-${{ matrix.os }}-${{ matrix.arch }} + path: build/* + + - name: Upload Docker artifact + uses: actions/upload-artifact@v4 + with: + name: yunikorn-history-server-oci-images-${{ matrix.arch }} + path: yunikorn-history-server-oci-*.tar \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3297f916 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:3.19 + +COPY yhs.yml . +COPY build/event-collector /usr/local/bin/ + +ENTRYPOINT ["event-collector"] +CMD ["yhs.yml"] diff --git a/Makefile b/Makefile index 100d4afd..822aeaee 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ TOOLS_DIR=tools # Force Go modules even when checked out inside GOPATH GO111MODULE := on export GO111MODULE +GO_LDFLAGS=-s -w -X github.com/G-Research/yunikorn-history-server/pkg/version.Version=$(VERSION) # Build the example binaries for dev and test .PHONY: commands @@ -73,4 +74,35 @@ go-lint: ## run go linters. .PHONY: install-tools install-tools: ## install tools. @echo '>>> Installing tools.' - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 \ No newline at end of file + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 + + +DOCKER_OUTPUT?=type=docker +ifneq ($(origin DOCKER_METADATA), undefined) + # If DOCKER_METADATA is defined, use it to set the tags and labels. + # DOCKER_METADATA should be a JSON object with the following structure: + # { + # "tags": ["image:tag1", "image:tag2"], + # "labels": { + # "label1": "value1", + # "label2": "value2" + # } + # } + DOCKER_TAGS=$(shell echo $$DOCKER_METADATA | jq -r '.tags | map("--tag \(.)") | join(" ")') + DOCKER_LABELS=$(shell echo $$DOCKER_METADATA | jq -r '.labels | to_entries | map("--label \(.key)=\"\(.value)\"") | join(" ")') +else + # Otherwise, use DOCKER_TAGS if defined, otherwise use the default. + # DOCKER_TAGS should be a space-separated list of tags. + # e.g. DOCKER_TAGS="image:tag1 image:tag2" + # We do not set DOCKER_LABELS because of the way make handles spaces + # in variable values. Use DOCKER_METADATA if you need to set labels. + DOCKER_TAGS?=yunikorn-history-server:$(VERSION) yunikorn-history-server:latest + DOCKER_TAGS:=$(addprefix --tag ,$(DOCKER_TAGS)) +endif +.PHONY: docker-dist +docker-dist: build/event-collector ## build docker image. + @echo ">>> Building Docker image." + @docker buildx build --provenance false --sbom false --platform linux/$(shell go env GOARCH) --output $(DOCKER_OUTPUT) $(DOCKER_TAGS) $(DOCKER_LABELS) . + +.PHONY: dist +dist: build/event-collector docker-dist ## build the software archives. \ No newline at end of file