From 6aa1bd5d18d7cb1197a63ce7541f5469f93cbf80 Mon Sep 17 00:00:00 2001 From: Liran BG Date: Wed, 20 Mar 2024 09:10:03 +0200 Subject: [PATCH] Enhance build for multi platform (#1) --- .gitignore | 1 + Dockerfile | 8 ++++---- Makefile | 33 +++++++++++++++++++++++++++++++++ go.mod | 3 +++ main.go | 5 +++-- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 go.mod diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/Dockerfile b/Dockerfile index a53bf18..bedde4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,17 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.10 as builder +FROM golang:1.22 as builder -ARG ARCH=amd64 +ARG GOARCH=amd64 ARG SRC_DIR=/go/src/github.com/nuclio/uhttpc # copy source to source dir -COPY . ${SRC_DIR} +COPY go.mod main.go ${SRC_DIR}/ # make the processor binary RUN mkdir -p /home/nuclio/bin \ - && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-s -w" -o /home/nuclio/bin/uhttpc ${SRC_DIR}/main.go + && GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-s -w" -o /home/nuclio/bin/uhttpc ${SRC_DIR}/main.go FROM scratch diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b885b64 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +# Variables +DOCKER_IMAGE_NAME := quay.io/nuclio/uhttpc +DOCKER_IMAGE_TAG := 0.0.1 +DOCKER_BUILD_ARGS := --build-arg GOARCH=amd64 +DOCKER_BUILD_ARGS_ARMHF := --build-arg GOARCH=arm +DOCKER_BUILD_ARGS_ARM64 := --build-arg GOARCH=arm64 +MAKEFLAGS += -j3 + +build-amd64: + docker build --platform linux/amd64 $(DOCKER_BUILD_ARGS) -t $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)-amd64 . + +build-armhf: + docker build --platform linux/arm/v7 $(DOCKER_BUILD_ARGS_ARMHF) -t $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)-armhf . + +build-arm64: + docker build --platform linux/arm64 $(DOCKER_BUILD_ARGS_ARM64) -t $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)-arm64 . + +build-all: build-amd64 build-armhf build-arm64 + +.PHONY: build-amd64 build-armhf build-arm64 build-all + +push-amd64: + docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)-amd64 + +push-armhf: + docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)-armhf + +push-arm64: + docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)-arm64 + +push-all: push-amd64 push-armhf push-arm64 + +.PHONY: push-amd64 push-armhf push-arm64 push-all diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e6eee6b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/nuclio/uhttpc + +go 1.21.6 diff --git a/main.go b/main.go index 477078f..4adffb7 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* -Copyright 2017 The Nuclio Authors. +Copyright 2024 The Nuclio Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import ( "fmt" "net/http" "os" + "time" ) func sendRequest(url string) error { @@ -29,6 +30,7 @@ func sendRequest(url string) error { return errors.New("URL must be set") } + http.DefaultClient.Timeout = time.Second * 60 resp, err := http.Get(url) if err != nil { return err @@ -39,7 +41,6 @@ func sendRequest(url string) error { return nil } - func main() { url := flag.String("url", "", "Remote URL (e.g. localhost:8070)")