Skip to content

Commit b64f94e

Browse files
committed
fixing dockerfile
1 parent 4e0a7e3 commit b64f94e

File tree

3 files changed

+102
-31
lines changed

3 files changed

+102
-31
lines changed

Dockerfile

+29-30
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,19 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
ARG GO_VERSION=1.19.4
18+
ARG GO_VERSION=1.19.4-alpine
1919
ARG XX_VERSION=1.1.2
2020
ARG GOLANGCI_LINT_VERSION=v1.49.0
2121
ARG ADDLICENSE_VERSION=v1.0.0
2222

23-
ARG BUILD_TAGS="e2e,kube"
24-
ARG DOCS_FORMATS="md,yaml"
25-
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.go\|\.hcl\|\.sh\)"
26-
27-
# xx is a helper for cross-compilation
28-
FROM --platform=${BUILDPLATFORM} tonistiigi/xx:${XX_VERSION} AS xx
29-
30-
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
31-
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
32-
33-
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS base
34-
COPY --from=xx / /
35-
RUN apk add --no-cache \
36-
docker \
37-
file \
23+
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS base
24+
WORKDIR /compose-cli
25+
RUN apk add --no-cache -vv \
3826
git \
27+
docker \
3928
make \
4029
protoc \
4130
protobuf-dev
42-
WORKDIR /src
43-
ENV CGO_ENABLED=0
44-
45-
FROM base AS build-base
4631
COPY go.* .
4732
RUN --mount=type=cache,target=/go/pkg/mod \
4833
--mount=type=cache,target=/root/.cache/go-build \
@@ -52,19 +37,33 @@ FROM base AS make-compose-plugin
5237
ENV CGO_ENABLED=0
5338
ARG TARGETOS
5439
ARG TARGETARCH
55-
ARG TARGETVARIANT
56-
RUN --mount=from=binary \
57-
mkdir -p /out && \
58-
# TODO: should just use standard arch
59-
TARGETARCH=$([ "$TARGETARCH" = "amd64" ] && echo "x86_64" || echo "$TARGETARCH"); \
60-
TARGETARCH=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "$TARGETARCH"); \
61-
cp docker-compose* "/out/docker-compose-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}$(ls docker-compose* | sed -e 's/^docker-compose//')"
40+
ARG BUILD_TAGS
41+
ARG GIT_TAG
42+
RUN --mount=target=. \
43+
--mount=type=cache,target=/go/pkg/mod \
44+
--mount=type=cache,target=/root/.cache/go-build \
45+
GOOS=${TARGETOS} \
46+
GOARCH=${TARGETARCH} \
47+
BUILD_TAGS=${BUILD_TAGS} \
48+
GIT_TAG=${GIT_TAG} \
49+
make COMPOSE_BINARY=/out/docker-compose -f builder.Makefile compose-plugin
6250

6351
FROM debian:bullseye-slim AS compose-plugin
64-
WORKDIR /root
52+
6553
COPY --from=make-compose-plugin /out/* /usr/local/bin/
54+
# add user
55+
RUN addgroup --gid 3000 compose && \
56+
adduser --uid 3000 --gecos "" --disabled-password \
57+
--ingroup compose \
58+
--home /home/compose \
59+
--shell /bin/bash compose
60+
61+
WORKDIR /home/compose
62+
63+
RUN chown -R compose:compose /home/compose && \
64+
chmod 755 /home/compose
65+
6666

67-
RUN adduser --gecos "" --disabled-password --home /home/cfu --shell /bin/bash cfu
68-
USER cfu
67+
USER compose:compose
6968

7069
ENTRYPOINT [ "docker-compose" ]

builder.Makefile

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
GOOS?=$(shell go env GOOS)
16+
GOARCH?=$(shell go env GOARCH)
17+
18+
PKG_NAME := github.com/docker/compose/v2
19+
20+
EXTENSION:=
21+
ifeq ($(GOOS),windows)
22+
EXTENSION:=.exe
23+
endif
24+
25+
STATIC_FLAGS=CGO_ENABLED=0
26+
27+
GIT_TAG?=$(shell git describe --tags --match "v[0-9]*")
28+
29+
LDFLAGS="-s -w -X $(PKG_NAME)/internal.Version=${GIT_TAG}"
30+
GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
31+
32+
COMPOSE_BINARY?=bin/docker-compose
33+
COMPOSE_BINARY_WITH_EXTENSION=$(COMPOSE_BINARY)$(EXTENSION)
34+
35+
WORK_DIR:=$(shell mktemp -d)
36+
37+
TAGS:=
38+
ifdef BUILD_TAGS
39+
TAGS=-tags $(BUILD_TAGS)
40+
LINT_TAGS=--build-tags $(BUILD_TAGS)
41+
endif
42+
43+
.PHONY: compose-plugin
44+
compose-plugin:
45+
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY_WITH_EXTENSION) ./cmd
46+
47+
.PHONY: cross
48+
cross:
49+
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-x86_64 ./cmd
50+
GOOS=linux GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-aarch64 ./cmd
51+
GOOS=linux GOARM=6 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv6 ./cmd
52+
GOOS=linux GOARM=7 GOARCH=arm $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-armv7 ./cmd
53+
GOOS=linux GOARCH=s390x $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-linux-s390x ./cmd
54+
GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-x86_64 ./cmd
55+
GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-darwin-aarch64 ./cmd
56+
GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(COMPOSE_BINARY)-windows-x86_64.exe ./cmd
57+
58+
.PHONY: test
59+
test:
60+
go test $(TAGS) -cover $(shell go list $(TAGS) ./... | grep -vE 'e2e')
61+
62+
.PHONY: lint
63+
lint:
64+
golangci-lint run $(LINT_TAGS) --timeout 10m0s ./...
65+
66+
.PHONY: check-license-headers
67+
check-license-headers:
68+
./scripts/validate/fileheader
69+
70+
.PHONY: check-go-mod
71+
check-go-mod:
72+
./scripts/validate/check-go-mod

service.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version: 1.2.9
1+
version: 1.3.0

0 commit comments

Comments
 (0)