dockerfile: native cross-compilation
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>master
							parent
							
								
									020bcce59d
								
							
						
					
					
						commit
						f13d1e02fe
					
				
							
								
								
									
										51
									
								
								Dockerfile
								
								
								
								
							
							
						
						
									
										51
									
								
								Dockerfile
								
								
								
								
							|  | @ -1,31 +1,44 @@ | ||||||
|  | # syntax=docker/dockerfile:1.3 | ||||||
|  | 
 | ||||||
| ARG GO_VERSION=1.17 | ARG GO_VERSION=1.17 | ||||||
|  | ARG GORELEASER_XX_VERSION=1.2.5 | ||||||
| 
 | 
 | ||||||
| FROM golang:${GO_VERSION}-alpine3.14 AS build | FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:${GORELEASER_XX_VERSION} AS goreleaser-xx | ||||||
|  | FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base | ||||||
|  | COPY --from=goreleaser-xx / / | ||||||
|  | RUN apk add --no-cache file git | ||||||
|  | WORKDIR /src | ||||||
| 
 | 
 | ||||||
|  | FROM base AS build | ||||||
| ENV GO111MODULE=auto | ENV GO111MODULE=auto | ||||||
| ENV DISTRIBUTION_DIR /go/src/github.com/distribution/distribution | ENV CGO_ENABLED=0 | ||||||
| ENV BUILDTAGS include_oss include_gcs | ARG TARGETPLATFORM | ||||||
|  | ARG PKG="github.com/distribution/distribution/v3" | ||||||
|  | ARG BUILDTAGS="include_oss include_gcs" | ||||||
|  | RUN --mount=type=bind,target=/src,rw \ | ||||||
|  |   --mount=type=cache,target=/root/.cache/go-build \ | ||||||
|  |   --mount=target=/go/pkg/mod,type=cache \ | ||||||
|  |   goreleaser-xx --debug \ | ||||||
|  |     --name="registry" \ | ||||||
|  |     --dist="/out" \ | ||||||
|  |     --main="./cmd/registry" \ | ||||||
|  |     --flags="-v" \ | ||||||
|  |     --ldflags="-s -w -X '$PKG/version.Version={{.Version}}' -X '$PKG/version.Revision={{.Commit}}' -X '$PKG/version.Package=$PKG'" \ | ||||||
|  |     --tags="$BUILDTAGS" \ | ||||||
|  |     --files="LICENSE" \ | ||||||
|  |     --files="README.md" | ||||||
| 
 | 
 | ||||||
| ARG GOOS=linux | FROM scratch AS artifacts | ||||||
| ARG GOARCH=amd64 | COPY --from=build /out/*.tar.gz / | ||||||
| ARG GOARM=6 | COPY --from=build /out/*.zip / | ||||||
| ARG VERSION |  | ||||||
| ARG REVISION |  | ||||||
| 
 | 
 | ||||||
| RUN set -ex \ | FROM scratch AS binary | ||||||
|     && apk add --no-cache make git file | COPY --from=build /usr/local/bin/registry* / | ||||||
| 
 |  | ||||||
| WORKDIR $DISTRIBUTION_DIR |  | ||||||
| COPY . $DISTRIBUTION_DIR |  | ||||||
| RUN CGO_ENABLED=0 make PREFIX=/go clean binaries && file ./bin/registry | grep "statically linked" |  | ||||||
| 
 | 
 | ||||||
| FROM alpine:3.14 | FROM alpine:3.14 | ||||||
| 
 | RUN apk add --no-cache ca-certificates | ||||||
| RUN set -ex \ |  | ||||||
|     && apk add --no-cache ca-certificates |  | ||||||
| 
 |  | ||||||
| COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml | COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml | ||||||
| COPY --from=build /go/src/github.com/distribution/distribution/bin/registry /bin/registry | COPY --from=build /usr/local/bin/registry /bin/registry | ||||||
| VOLUME ["/var/lib/registry"] | VOLUME ["/var/lib/registry"] | ||||||
| EXPOSE 5000 | EXPOSE 5000 | ||||||
| ENTRYPOINT ["registry"] | ENTRYPOINT ["registry"] | ||||||
|  |  | ||||||
|  | @ -0,0 +1,54 @@ | ||||||
|  | group "default" { | ||||||
|  |   targets = ["image-local"] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // Special target: https://github.com/docker/metadata-action#bake-definition | ||||||
|  | target "docker-metadata-action" { | ||||||
|  |   tags = ["registry:local"] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | target "binary" { | ||||||
|  |   target = "binary" | ||||||
|  |   output = ["./bin"] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | target "artifact" { | ||||||
|  |   target = "artifacts" | ||||||
|  |   output = ["./bin"] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | target "artifact-all" { | ||||||
|  |   inherits = ["artifact"] | ||||||
|  |   platforms = [ | ||||||
|  |     "darwin/amd64", | ||||||
|  |     "darwin/arm64", | ||||||
|  |     "linux/amd64", | ||||||
|  |     "linux/arm/v5", | ||||||
|  |     "linux/arm/v6", | ||||||
|  |     "linux/arm/v7", | ||||||
|  |     "linux/arm64", | ||||||
|  |     "linux/ppc64le", | ||||||
|  |     "linux/s390x" | ||||||
|  |   ] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | target "image" { | ||||||
|  |   inherits = ["docker-metadata-action"] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | target "image-local" { | ||||||
|  |   inherits = ["image"] | ||||||
|  |   output = ["type=docker"] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | target "image-all" { | ||||||
|  |   inherits = ["image"] | ||||||
|  |   platforms = [ | ||||||
|  |     "linux/amd64", | ||||||
|  |     "linux/arm/v6", | ||||||
|  |     "linux/arm/v7", | ||||||
|  |     "linux/arm64", | ||||||
|  |     "linux/ppc64le", | ||||||
|  |     "linux/s390x" | ||||||
|  |   ] | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue