Skip to content

Commit

Permalink
improve Makefile
Browse files Browse the repository at this point in the history
* switch to the right image registry
* allow to add golang flags

Signed-off-by: Sebastian Sch <[email protected]>
  • Loading branch information
SchSeba committed Sep 4, 2024
1 parent d4be6f7 commit 4268a38
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
83 changes: 83 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Temporary Build Files
build/
bin/
testbin/
env
.env
.cache
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
projectile-bookmarks.eld
# directory configuration
.dir-locals.el
# saveplace
places
# url cache
url/cache/
# cedet
ede-projects.el
# smex
smex-items
# company-statistics
company-statistics-cache.el
# anaconda-mode
anaconda-mode/
### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with 'go test -c'
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
### Vim ###
# swap
.sw[a-p]
.*.sw[a-p]
# session
Session.vim
# temporary
.netrwhist
# auto-generated tag files
tags
### VisualStudioCode ###
.vscode/*
.history
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
#IDE (GoLand) specific
.idea/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /usr/src/sriov-network-metrics-exporter
RUN make clean && make build

FROM docker.io/alpine:3.16
COPY --from=builder /usr/src/sriov-network-metrics-exporter/bin/* /usr/bin/
COPY --from=builder /usr/src/sriov-network-metrics-exporter/build/* /usr/bin/
RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates && apk add --no-cache openssl
EXPOSE 9808
ENTRYPOINT ["sriov-exporter"]
22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
IMAGE_REGISTRY?=localhost:5000/
IMAGE_REGISTRY?=ghcr.io/k8snetworkplumbingwg/
IMAGE_VERSION?=latest

IMAGE_NAME?=$(IMAGE_REGISTRY)sriov-metrics-exporter:$(IMAGE_VERSION)
IMAGE_NAME?=$(IMAGE_REGISTRY)sriov-network-metrics-exporter:$(IMAGE_VERSION)
IMAGE_BUILDER?=docker

# Package related
BINARY_NAME=sriov-exporter
BUILDDIR=$(CURDIR)/build

DOCKERARGS?=
ifdef HTTP_PROXY
DOCKERARGS += --build-arg http_proxy=$(HTTP_PROXY)
Expand All @@ -12,14 +16,26 @@ ifdef HTTPS_PROXY
DOCKERARGS += --build-arg https_proxy=$(HTTPS_PROXY)
endif

# Go settings
GO = go
GO_BUILD_OPTS ?=CGO_ENABLED=0
GO_LDFLAGS ?= -s -w
GO_FLAGS ?=
GO_TAGS ?=-tags no_openssl
export GOPATH?=$(shell go env GOPATH)

# debug
V ?= 0
Q = $(if $(filter 1,$V),,@)

all: build image-build test

clean:
rm -rf bin
go clean -modcache -testcache

build:
GO111MODULE=on go build -ldflags "-s -w" -buildmode=pie -o bin/sriov-exporter cmd/sriov-network-metrics-exporter.go
$Q cd $(CURDIR)/cmd && $(GO_BUILD_OPTS) go build -ldflags '$(GO_LDFLAGS)' $(GO_FLAGS) -o $(BUILDDIR)/$(BINARY_NAME) $(GO_TAGS) -v

image-build:
@echo "Bulding container image $(IMAGE_NAME)"
Expand Down

0 comments on commit 4268a38

Please sign in to comment.