Skip to content

Commit

Permalink
Enhance build for multi platform (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg authored Mar 20, 2024
1 parent cc89c1a commit 6aa1bd5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/nuclio/uhttpc

go 1.21.6
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,13 +22,15 @@ import (
"fmt"
"net/http"
"os"
"time"
)

func sendRequest(url string) error {
if url == "" {
return errors.New("URL must be set")
}

http.DefaultClient.Timeout = time.Second * 60
resp, err := http.Get(url)
if err != nil {
return err
Expand All @@ -39,7 +41,6 @@ func sendRequest(url string) error {
return nil
}


func main() {
url := flag.String("url", "", "Remote URL (e.g. localhost:8070)")

Expand Down

0 comments on commit 6aa1bd5

Please sign in to comment.