mirror of
https://github.com/docker/compose.git
synced 2026-11-17 13:45:39 +00:00
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / ci-ok (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run
The release updates errcheck (1.20 to 1.30) and gocognit (1.2.1 to 1.3.0). errcheck now reports the receives from an error channel whose value is dropped on purpose, in three places: waiting for the attach copy to end after the context is done, draining the container wait channel of a failed hook, and waiting for Up to return in a test. Say why on each, rather than handling an error nobody can act on. gocognit's new count is handled by the previous commit. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
235 lines
7.7 KiB
Docker
235 lines
7.7 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
|
|
# Copyright 2020 Docker Compose CLI authors
|
|
|
|
# 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.
|
|
|
|
ARG GO_VERSION=1.26.10
|
|
ARG XX_VERSION=1.9.0
|
|
ARG GOLANGCI_LINT_VERSION=v2.15.0
|
|
ARG ADDLICENSE_VERSION=v1.0.0
|
|
# Keep in sync with GOTESTSUM_VERSION in the Makefile
|
|
ARG GOTESTSUM_VERSION=v1.13.0
|
|
|
|
ARG BUILD_TAGS="e2e"
|
|
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
|
|
|
|
# osxcross contains the MacOSX cross toolchain for xx
|
|
FROM crazymax/osxcross:15.5-alpine AS osxcross
|
|
|
|
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}-alpine3.23 AS base
|
|
COPY --from=xx / /
|
|
RUN apk add --no-cache \
|
|
clang \
|
|
docker \
|
|
file \
|
|
findutils \
|
|
git \
|
|
make \
|
|
protoc \
|
|
protobuf-dev
|
|
WORKDIR /src
|
|
ENV CGO_ENABLED=0
|
|
|
|
FROM base AS build-base
|
|
COPY go.* .
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
go mod download
|
|
|
|
FROM build-base AS vendored
|
|
RUN --mount=type=bind,target=.,rw \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
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 mocks-generate
|
|
RUN --mount=type=bind,target=.,rw \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
make mocks && mkdir /out && cp pkg/mocks/*.go /out
|
|
|
|
FROM mocks-generate AS mocks-validate
|
|
RUN --mount=type=bind,target=.,rw <<EOT
|
|
set -e
|
|
git add -A
|
|
cp -f /out/* pkg/mocks/
|
|
diff=$(git status --porcelain -- pkg/mocks)
|
|
if [ -n "$diff" ]; then
|
|
echo >&2 'ERROR: Generated mocks differ. Please regenerate them with "make mocks"'
|
|
echo "$diff"
|
|
exit 1
|
|
fi
|
|
EOT
|
|
|
|
FROM build-base AS build
|
|
ARG BUILD_TAGS
|
|
ARG BUILD_FLAGS
|
|
ARG TARGETPLATFORM
|
|
ARG MACOSX_VERSION_MIN=11.0
|
|
RUN --mount=type=bind,target=. \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
|
|
xx-go --wrap && \
|
|
if [ "$(xx-info os)" == "darwin" ]; then export CGO_ENABLED=1; export BUILD_TAGS=fsnotify,$BUILD_TAGS; fi && \
|
|
make build GO_BUILDTAGS="$BUILD_TAGS" DESTDIR=/out && \
|
|
xx-verify --static /out/docker-compose
|
|
|
|
FROM build-base AS lint
|
|
ARG BUILD_TAGS
|
|
ENV GOLANGCI_LINT_CACHE=/cache/golangci-lint
|
|
RUN --mount=type=bind,target=. \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=cache,target=/cache/golangci-lint \
|
|
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
|
|
golangci-lint cache status && \
|
|
golangci-lint run --build-tags "$BUILD_TAGS" ./...
|
|
|
|
FROM build-base AS test
|
|
# the race detector requires cgo (ENV: base sets CGO_ENABLED=0, which an ARG can't override)
|
|
ENV CGO_ENABLED=1
|
|
ARG BUILD_TAGS
|
|
ARG GOTESTSUM_VERSION
|
|
RUN apk add --no-cache gcc musl-dev
|
|
RUN --mount=type=bind,target=. \
|
|
--mount=type=cache,target=/root/.cache \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
rm -rf /tmp/coverage && \
|
|
mkdir -p /tmp/coverage && \
|
|
rm -rf /tmp/report && \
|
|
mkdir -p /tmp/report && \
|
|
go run gotest.tools/gotestsum@${GOTESTSUM_VERSION} --format testname --junitfile "/tmp/report/report.xml" -- -tags "$BUILD_TAGS" -v -race -cover -covermode=atomic $(go list $(TAGS) ./... | grep -vE 'e2e') -args -test.gocoverdir="/tmp/coverage" && \
|
|
go tool covdata percent -i=/tmp/coverage
|
|
|
|
FROM scratch AS test-coverage
|
|
COPY --from=test --link /tmp/coverage /
|
|
COPY --from=test --link /tmp/report /
|
|
|
|
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 -ignore validate -ignore testdata -ignore '**/testdata/**' -ignore resolvepath && \
|
|
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 '**/testdata/**' -ignore resolvepath -v
|
|
|
|
FROM base AS docsgen
|
|
WORKDIR /src
|
|
RUN --mount=target=. \
|
|
--mount=target=/root/.cache,type=cache \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
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 /out/docker-compose /
|
|
FROM binary-unix AS binary-darwin
|
|
FROM binary-unix AS binary-linux
|
|
FROM scratch AS binary-windows
|
|
COPY --link --from=build /out/docker-compose /docker-compose.exe
|
|
FROM binary-$TARGETOS AS binary
|
|
# enable scanning for this stage
|
|
ARG BUILDKIT_SBOM_SCAN_STAGE=true
|
|
|
|
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"); \
|
|
cp docker-compose* "/out/docker-compose-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}$(ls docker-compose* | sed -e 's/^docker-compose//')"
|
|
|
|
FROM scratch AS release
|
|
COPY --from=releaser /out/ /
|
|
|
|
FROM --platform=$BUILDPLATFORM alpine AS module-releaser
|
|
WORKDIR /work
|
|
ARG TARGETOS
|
|
RUN --mount=from=binary \
|
|
mkdir -p /cli-plugins/compose/$TARGETOS && \
|
|
cp docker-compose* "/cli-plugins/compose/$TARGETOS/docker-compose$(ls docker-compose* | sed -e 's/^docker-compose//')"
|
|
|
|
FROM scratch AS module
|
|
ARG TARGETOS
|
|
COPY --from=module-releaser /cli-plugins/compose/$TARGETOS /cli-plugins/compose/$TARGETOS
|
|
COPY ./desktop-module/module-metadata.json /
|
|
COPY LICENSE /
|