-
Notifications
You must be signed in to change notification settings - Fork 11
/
Dockerfile
62 lines (44 loc) · 1.51 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
FROM golang:1.21.6-alpine3.19 as base
WORKDIR /go/src/github.com/codefresh-io/cli-v2
RUN apk -U add --no-cache git ca-certificates && update-ca-certificates
RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/codefresh" \
--shell "/sbin/nologin" \
--no-create-home \
--uid 10001 \
codefresh
RUN --mount=type=secret,id=GITHUB_TOKEN \
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) \
git config \
--global \
url."https://github:${GITHUB_TOKEN}@github.com".insteadOf \
"https://github.com"
COPY go.mod .
COPY go.sum .
RUN go mod download -x
RUN go mod verify
############################### CLI ###############################
### Compile
FROM golang:1.21.6-alpine3.19 as codefresh-build
WORKDIR /go/src/github.com/codefresh-io/cli-v2
RUN apk -U add --no-cache git make bash
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=base /go/pkg/mod /go/pkg/mod
COPY . .
ENV GOPATH /go
ENV GOBIN /go/bin
ARG SEGMENT_WRITE_KEY
RUN make local DEV_MODE=false SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
### Run
FROM alpine:3.19 as codefresh
WORKDIR /go/src/github.com/codefresh-io/cli-v2
RUN apk -U add --no-cache git
# copy ca-certs and user details
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=base /etc/passwd /etc/passwd
COPY --from=base /etc/group /etc/group
COPY --chown=codefresh:codefresh --from=codefresh-build /go/src/github.com/codefresh-io/cli-v2/dist/* /usr/local/bin/cf
USER codefresh:codefresh
ENTRYPOINT [ "cf" ]