Skip to content

Commit

Permalink
Merge pull request #30 from gr-oss-devops/add-build-docker-images
Browse files Browse the repository at this point in the history
Add build docker images
  • Loading branch information
pavlovic-ivan authored Jun 5, 2024
2 parents 9db5d4f + 4d5e7ef commit 1902ca9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
60 changes: 59 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.19

COPY yhs.yml .
COPY build/event-collector /usr/local/bin/

ENTRYPOINT ["event-collector"]
CMD ["yhs.yml"]
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/[email protected]
@go install github.com/golangci/golangci-lint/cmd/[email protected]


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.

0 comments on commit 1902ca9

Please sign in to comment.