Skip to content

Commit

Permalink
add Dockerfile target to build from source
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
  • Loading branch information
fenollp committed Apr 14, 2023
1 parent badbb00 commit e1e0907
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
@@ -1,8 +1,33 @@
# syntax=docker.io/docker/dockerfile:1.3-labs@sha256:250ce669e1aeeb5ffb892b18039c3f0801466536cb4210c8eb2638e628859bfd

FROM --platform=$BUILDPLATFORM docker.io/library/alpine:3.17 AS alpine
FROM --platform=$BUILDPLATFORM docker.io/library/golang@sha256:403f48633fb5ebd49f9a2b6ad6719f912df23dae44974a0c9445be331e72ff5e AS golang
FROM --platform=$BUILDPLATFORM gcr.io/distroless/base:nonroot@sha256:e406b1da09bc455495417a809efe48a03c48011a89f6eb57b0ab882508021c0d AS distroless


FROM golang AS builder
WORKDIR /app
ARG TARGETOS TARGETARCH
ENV CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH
COPY go.??? .
RUN \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build <<EOF
set -eux
go mod download
EOF
COPY . .
RUN \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build <<EOF
set -eux
go build -mod=readonly -o ./dist/ghz -a -installsuffix cgo -ldflags '-w -s -extldflags "-static"' ./cmd/ghz/...
EOF

FROM scratch AS ghz-binary-built
COPY --from=builder /app/dist/ghz /


FROM alpine AS osmap-linux
RUN echo linux >/os
FROM alpine AS osmap-macos
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -59,6 +59,12 @@ go build .
go install github.com/bojand/ghz/cmd/ghz@latest
```

**Install using Docker**

```sh
DOCKER_BUILDKIT=1 docker build --output=/usr/local/bin --target=ghz-binary-built https://github.com/bojand/ghz.git
```

## Usage

```
Expand Down

0 comments on commit e1e0907

Please sign in to comment.