Skip to content

Commit

Permalink
Prepare for building multiple output binaries
Browse files Browse the repository at this point in the history
Signed-off-by: Heathcliff <[email protected]>
  • Loading branch information
heathcliff26 committed Dec 23, 2024
1 parent 58ce5a5 commit 16375c4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY cmd ./cmd
COPY pkg ./pkg
COPY hack ./hack

RUN --mount=type=bind,target=/app/.git,source=.git GOOS=linux GOARCH="${TARGETARCH}" hack/build.sh
RUN --mount=type=bind,target=/app/.git,source=.git GOOS=linux GOARCH="${TARGETARCH}" hack/build.sh fleetlock

#
# END build-stage
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ REPOSITORY ?= localhost
CONTAINER_NAME ?= fleetlock
TAG ?= latest

default: build
build: build-fleetctl build-fleetlock

build:
hack/build.sh
build-fleetctl:
hack/build.sh fleetctl

build-fleetlock:
hack/build.sh fleetlock

image:
podman build -t $(REPOSITORY)/$(CONTAINER_NAME):$(TAG) .
Expand Down
7 changes: 7 additions & 0 deletions cmd/fleetlock/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/heathcliff26/fleetlock/pkg/fleetlock"

func main() {
fleetlock.Execute()
}
7 changes: 0 additions & 7 deletions cmd/main.go

This file was deleted.

11 changes: 9 additions & 2 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ base_dir="$(dirname "${BASH_SOURCE[0]}" | xargs realpath)/.."

bin_dir="${base_dir}/bin"

target="${1}"

GOOS="${GOOS:-$(go env GOOS)}"
GOARCH="${GOARCH:-$(go env GOARCH)}"

Expand All @@ -16,12 +18,17 @@ if [ "${RELEASE_VERSION}" != "" ]; then
GO_LD_FLAGS+=" -X github.com/heathcliff26/fleetlock/pkg/version.version=${RELEASE_VERSION}"
fi

output_name="${bin_dir}/fleetlock"
output_name="${bin_dir}/${target}"

if [ "${2}" != "" ]; then
output_name="${bin_dir}/${2}"
fi

if [ "${GOOS}" == "windows" ]; then
output_name="${output_name}.exe"
fi

pushd "${base_dir}" >/dev/null

echo "Building $(basename "${output_name}")"
GOOS="${GOOS}" GOARCH="${GOARCH}" CGO_ENABLED=0 go build -ldflags="${GO_LD_FLAGS}" -o "${output_name}" ./cmd/...
GOOS="${GOOS}" GOARCH="${GOARCH}" CGO_ENABLED=0 go build -ldflags="${GO_LD_FLAGS}" -o "${output_name}" "./cmd/${target}"
2 changes: 1 addition & 1 deletion pkg/cmd/root.go → pkg/fleetlock/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package fleetlock

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root_test.go → pkg/fleetlock/root_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package fleetlock

import (
"testing"
Expand Down

0 comments on commit 16375c4

Please sign in to comment.