Skip to content

Commit

Permalink
feat(multiplatform): Improve multiplatform support (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjjaramillo authored Sep 11, 2023
1 parent 595a3df commit 7f46f49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

# Build stage
FROM golang:1.21 AS build
# Build stage: use native architecture and Go's cross-compilation
FROM --platform=$BUILDPLATFORM golang:1.21 AS build

# Set by docker automatically
ARG TARGETOS TARGETARCH
Expand All @@ -11,23 +11,21 @@ ARG GOARCH=$TARGETARCH
# Set destination for COPY
WORKDIR /app

# Download Go modules
# For better layer caching, copy and install dependencies first then build app
COPY go.mod go.sum ./
RUN go mod download

# Copy the source code. Note the slash at the end, as explained in
# Note the slash at the end, as explained in
# https://docs.docker.com/engine/reference/builder/#copy
COPY . ./

# Build
RUN CGO_ENABLED=0 go build -o ./bin/testbed ./src
RUN make build

# Final stage
FROM alpine:3.18

WORKDIR /bin

COPY --from=build /app/bin/testbed .
COPY --from=build /app/bin/testbed ./

# Run
CMD ["/bin/testbed", "--debug"]
ENTRYPOINT [ "/bin/testbed" ]
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
GO_DIR = ./src
BIN_DIR = ./bin
TMP_DIR = ./tmp

.PHONE: all
all: clean test build
all: clean format test build

.PHONY: clean
clean:
rm -rf $(BIN_DIR)
rm -f *.out
rm -rf $(BIN_DIR) $(TMP_DIR)
go mod tidy

.PHONY: format
Expand All @@ -21,11 +21,11 @@ test:

.PHONY: build
build:
go build -o $(BIN_DIR)/testbed $(GO_DIR)
CGO_ENABLED=0 go build -o $(BIN_DIR)/testbed $(GO_DIR)

.PHONY: coverprofile
coverprofile:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
go tool cover -func=coverage.out
rm -f coverage.out
mkdir $(TMP_DIR) || true
go test -coverprofile=$(TMP_DIR)/coverage.out ./...
go tool cover -html=$(TMP_DIR)/coverage.out
go tool cover -func=$(TMP_DIR)/coverage.out
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func parseFlags() *flagSet {
return &fs
}

// SetupLog shows a basic example on how to setup
// SetupLog shows a basic example on how to setup
// package zap to do structured, leveled logging in Go.
func setupLog(debug bool) (logger *zap.Logger) {
if debug {
Expand Down

0 comments on commit 7f46f49

Please sign in to comment.