Skip to content

Commit

Permalink
Changes to compilation to support linux (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans authored Mar 14, 2024
1 parent a099f52 commit 6c9a942
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.builder
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ARG BUILD_DATE

COPY . ./

RUN GOOS=linux GOARCH=amd64 go build -o /usr/sbin/conditionorc \
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/sbin/conditionorc \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
Expand Down
66 changes: 32 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ lint:

## Go test
test: lint
CGO_ENABLED=0 go test -timeout 1m -v -covermode=atomic ./...

go test -timeout 1m -v -covermode=atomic ./...

## generate mock store - invoke when changes are made to the store interface
gen-store-mock:
Expand All @@ -29,40 +28,36 @@ gen-store-mock:

## build osx bin
build-osx:
ifeq ($(GO_VERSION), 0)
ifeq (${GO_VERSION}, 0)
$(error build requies go version 1.17.n or higher)
endif
GOOS=darwin GOARCH=amd64 go build -o conditionorc \
-ldflags \
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"


CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o conditionorc \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
-X ${LDFLAG_LOCATION}.GitSummary=${GIT_SUMMARY} \
-X ${LDFLAG_LOCATION}.AppVersion=${VERSION} \
-X ${LDFLAG_LOCATION}.BuildDate=${BUILD_DATE}"

## Build linux bin
build-linux:
ifeq ($(GO_VERSION), 0)
ifeq (${GO_VERSION}, 0)
$(error build requies go version 1.16.n or higher)
endif
GOOS=linux GOARCH=amd64 go build -o conditionorc \
-ldflags \
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o conditionorc \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
-X ${LDFLAG_LOCATION}.GitSummary=${GIT_SUMMARY} \
-X ${LDFLAG_LOCATION}.AppVersion=${VERSION} \
-X ${LDFLAG_LOCATION}.BuildDate=${BUILD_DATE}"

## build docker image and tag as ghcr.io/metal-toolbox/conditionorc:latest
build-image: build-linux
@echo ">>>> NOTE: You may want to execute 'make build-image-nocache' depending on the Docker stages changed"
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) \
--label org.label-schema.vcs-url=$(REPO)
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=${GIT_COMMIT_FULL} \
--label org.label-schema.vcs-url=${REPO}

## build and push devel docker image to KIND image repo
push-image-devel: build-image
Expand All @@ -74,7 +69,6 @@ push-image-devel: build-image
push-image:
docker push ${DOCKER_IMAGE}:latest


SWAG_INSTALLED := $(shell command -v swag 2> /dev/null)

## generate swagger docs for api
Expand All @@ -88,10 +82,14 @@ endif
# experimental
multistage-image:
docker build -f Dockerfile.builder -t ${DOCKER_IMAGE}:latest . \
--build-arg GIT_COMMIT=$(GIT_COMMIT) --build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg GIT_SUMMARY=$(GIT_SUMMARY) --build-arg VERSION=$(VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) --label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) --label=org.label-schema.vcs-url=$(REPO)
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg GIT_BRANCH=${GIT_BRANCH} \
--build-arg GIT_SUMMARY=${GIT_SUMMARY} \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=${BUILD_DATE} \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=${GIT_COMMIT_FULL} \
--label org.label-schema.vcs-url=${REPO}

push-ms-devel: multistage-image
docker tag ${DOCKER_IMAGE}:latest localhost:5001/conditionorc:latest
Expand All @@ -105,8 +103,8 @@ YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)


TARGET_MAX_CHAR_NUM=20

## Show help
help:
@echo ''
Expand All @@ -119,7 +117,7 @@ help:
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
printf " ${YELLOW}%-${TARGET_MAX_CHAR_NUM}s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
{ lastLine = $$0 }' ${MAKEFILE_LIST}

0 comments on commit 6c9a942

Please sign in to comment.