2022-08-03 23:36:13 +03:00
|
|
|
# syntax=docker/dockerfile:1
|
2020-08-17 17:20:02 +03:00
|
|
|
|
|
|
|
|
2020-09-22 13:13:00 +03:00
|
|
|
# Copyright 2020 Docker Compose CLI authors
|
2020-06-18 17:13:24 +03:00
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-09-22 13:13:00 +03:00
|
|
|
|
2022-09-07 00:41:55 +03:00
|
|
|
ARG GO_VERSION=1.19.1
|
2022-08-12 16:05:52 +03:00
|
|
|
ARG XX_VERSION=1.1.2
|
|
|
|
ARG GOLANGCI_LINT_VERSION=v1.47.3
|
|
|
|
ARG ADDLICENSE_VERSION=v1.0.0
|
|
|
|
|
|
|
|
ARG BUILD_TAGS="e2e,kube"
|
|
|
|
ARG DOCS_FORMATS="md,yaml"
|
|
|
|
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.go\|\.hcl\|\.sh\)"
|
|
|
|
|
|
|
|
# xx is a helper for cross-compilation
|
|
|
|
FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx
|
|
|
|
|
|
|
|
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
|
|
|
|
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
|
|
|
|
|
|
|
|
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS base
|
|
|
|
COPY --from=xx / /
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
docker \
|
|
|
|
file \
|
|
|
|
git \
|
2022-08-26 23:06:24 +03:00
|
|
|
make \
|
2022-08-12 16:05:52 +03:00
|
|
|
protoc \
|
|
|
|
protobuf-dev
|
|
|
|
WORKDIR /src
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
|
|
|
|
FROM base AS build-base
|
2020-05-29 12:30:12 +03:00
|
|
|
COPY go.* .
|
2020-09-23 18:13:27 +03:00
|
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
2021-05-19 17:59:21 +03:00
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
2020-09-23 18:13:27 +03:00
|
|
|
go mod download
|
2020-05-05 00:49:40 +03:00
|
|
|
|
2022-08-12 16:05:52 +03:00
|
|
|
FROM build-base AS vendored
|
|
|
|
RUN --mount=type=bind,target=.,rw \
|
2020-09-23 18:13:27 +03:00
|
|
|
--mount=type=cache,target=/go/pkg/mod \
|
2022-08-12 16:05:52 +03:00
|
|
|
go mod tidy && mkdir /out && cp go.mod go.sum /out
|
|
|
|
|
|
|
|
FROM scratch AS vendor-update
|
|
|
|
COPY --from=vendored /out /
|
|
|
|
|
|
|
|
FROM vendored AS vendor-validate
|
|
|
|
RUN --mount=type=bind,target=.,rw <<EOT
|
|
|
|
set -e
|
|
|
|
git add -A
|
|
|
|
cp -rf /out/* .
|
|
|
|
diff=$(git status --porcelain -- go.mod go.sum)
|
|
|
|
if [ -n "$diff" ]; then
|
|
|
|
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make go-mod-tidy"'
|
|
|
|
echo "$diff"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
EOT
|
|
|
|
|
|
|
|
FROM build-base AS build
|
2020-06-15 18:41:59 +03:00
|
|
|
ARG BUILD_TAGS
|
2022-08-12 16:05:52 +03:00
|
|
|
ARG TARGETPLATFORM
|
2022-08-26 23:06:24 +03:00
|
|
|
RUN xx-go --wrap
|
2022-08-12 16:05:52 +03:00
|
|
|
RUN --mount=type=bind,target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache \
|
2020-09-23 18:13:27 +03:00
|
|
|
--mount=type=cache,target=/go/pkg/mod \
|
2022-08-26 23:06:24 +03:00
|
|
|
make build GO_BUILDTAGS="$BUILD_TAGS" DESTDIR=/usr/bin && \
|
2022-08-12 16:05:52 +03:00
|
|
|
xx-verify --static /usr/bin/docker-compose
|
2021-05-27 13:10:37 +03:00
|
|
|
|
2022-08-12 16:05:52 +03:00
|
|
|
FROM build-base AS lint
|
|
|
|
ARG BUILD_TAGS
|
|
|
|
RUN --mount=type=bind,target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache \
|
|
|
|
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
|
|
|
|
golangci-lint run --build-tags "$BUILD_TAGS" ./...
|
2020-04-22 11:04:11 +03:00
|
|
|
|
2022-08-12 16:05:52 +03:00
|
|
|
FROM build-base AS test
|
|
|
|
ARG CGO_ENABLED=0
|
2020-07-07 16:48:09 +03:00
|
|
|
ARG BUILD_TAGS
|
2022-08-12 16:05:52 +03:00
|
|
|
RUN --mount=type=bind,target=. \
|
|
|
|
--mount=type=cache,target=/root/.cache \
|
2020-09-23 18:13:27 +03:00
|
|
|
--mount=type=cache,target=/go/pkg/mod \
|
2022-08-12 16:05:52 +03:00
|
|
|
go test -tags "$BUILD_TAGS" -v -coverprofile=/tmp/coverage.txt -covermode=atomic $(go list $(TAGS) ./... | grep -vE 'e2e') && \
|
|
|
|
go tool cover -func=/tmp/coverage.txt
|
|
|
|
|
|
|
|
FROM scratch AS test-coverage
|
|
|
|
COPY --from=test /tmp/coverage.txt /coverage.txt
|
|
|
|
|
|
|
|
FROM base AS license-set
|
|
|
|
ARG LICENSE_FILES
|
|
|
|
RUN --mount=type=bind,target=.,rw \
|
|
|
|
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
|
|
|
|
find . -regex "${LICENSE_FILES}" | xargs addlicense -c 'Docker Compose CLI' -l apache && \
|
|
|
|
mkdir /out && \
|
|
|
|
find . -regex "${LICENSE_FILES}" | cpio -pdm /out
|
|
|
|
|
|
|
|
FROM scratch AS license-update
|
|
|
|
COPY --from=set /out /
|
|
|
|
|
|
|
|
FROM base AS license-validate
|
|
|
|
ARG LICENSE_FILES
|
|
|
|
RUN --mount=type=bind,target=. \
|
|
|
|
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
|
|
|
|
find . -regex "${LICENSE_FILES}" | xargs addlicense -check -c 'Docker Compose CLI' -l apache -ignore validate -ignore testdata -ignore resolvepath -v
|
|
|
|
|
|
|
|
FROM base AS docsgen
|
|
|
|
WORKDIR /src
|
2020-08-17 16:18:47 +03:00
|
|
|
RUN --mount=target=. \
|
2022-08-12 16:05:52 +03:00
|
|
|
--mount=target=/root/.cache,type=cache \
|
|
|
|
go build -o /out/docsgen ./docs/yaml/main/generate.go
|
|
|
|
|
|
|
|
FROM --platform=${BUILDPLATFORM} alpine AS docs-build
|
|
|
|
RUN apk add --no-cache rsync git
|
|
|
|
WORKDIR /src
|
|
|
|
COPY --from=docsgen /out/docsgen /usr/bin
|
|
|
|
ARG DOCS_FORMATS
|
|
|
|
RUN --mount=target=/context \
|
|
|
|
--mount=target=.,type=tmpfs <<EOT
|
|
|
|
set -e
|
|
|
|
rsync -a /context/. .
|
|
|
|
docsgen --formats "$DOCS_FORMATS" --source "docs/reference"
|
|
|
|
mkdir /out
|
|
|
|
cp -r docs/reference /out
|
|
|
|
EOT
|
|
|
|
|
|
|
|
FROM scratch AS docs-update
|
|
|
|
COPY --from=docs-build /out /out
|
|
|
|
|
|
|
|
FROM docs-build AS docs-validate
|
|
|
|
RUN --mount=target=/context \
|
|
|
|
--mount=target=.,type=tmpfs <<EOT
|
|
|
|
set -e
|
|
|
|
rsync -a /context/. .
|
|
|
|
git add -A
|
|
|
|
rm -rf docs/reference/*
|
|
|
|
cp -rf /out/* ./docs/
|
|
|
|
if [ -n "$(git status --porcelain -- docs/reference)" ]; then
|
|
|
|
echo >&2 'ERROR: Docs result differs. Please update with "make docs"'
|
|
|
|
git status --porcelain -- docs/reference
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
EOT
|
|
|
|
|
|
|
|
FROM scratch AS binary-unix
|
|
|
|
COPY --link --from=build /usr/bin/docker-compose /
|
|
|
|
FROM binary-unix AS binary-darwin
|
|
|
|
FROM binary-unix AS binary-linux
|
|
|
|
FROM scratch AS binary-windows
|
|
|
|
COPY --link --from=build /usr/bin/docker-compose /docker-compose.exe
|
|
|
|
FROM binary-$TARGETOS AS binary
|
|
|
|
|
|
|
|
FROM --platform=$BUILDPLATFORM alpine AS releaser
|
|
|
|
WORKDIR /work
|
|
|
|
ARG TARGETOS
|
|
|
|
ARG TARGETARCH
|
|
|
|
ARG TARGETVARIANT
|
|
|
|
RUN --mount=from=binary \
|
|
|
|
mkdir -p /out && \
|
|
|
|
# TODO: should just use standard arch
|
|
|
|
TARGETARCH=$([ "$TARGETARCH" = "amd64" ] && echo "x86_64" || echo "$TARGETARCH"); \
|
|
|
|
TARGETARCH=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "$TARGETARCH"); \
|
2022-08-14 23:29:57 +03:00
|
|
|
cp docker-compose* "/out/docker-compose-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}$(ls docker-compose* | sed -e 's/^docker-compose//')"
|
2022-08-12 16:05:52 +03:00
|
|
|
|
|
|
|
FROM scratch AS release
|
|
|
|
COPY --from=releaser /out/ /
|
2022-06-24 19:40:04 +03:00
|
|
|
|
|
|
|
# docs-reference is a target used as remote context to update docs on release
|
|
|
|
# with latest changes on docker.github.io.
|
|
|
|
# see open-pr job in .github/workflows/docs.yml for more details
|
|
|
|
FROM scratch AS docs-reference
|
|
|
|
COPY docs/reference/*.yaml .
|