-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
62 lines (53 loc) · 1.89 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.22.3 as builder
WORKDIR /dlza-manager-handler
ARG SSH_PUBLIC_KEY=$SSH_PUBLIC_KEY
ARG SSH_PRIVATE_KEY=$SSH_PRIVATE_KEY
# ARG GITLAB_USER=gitlab-ci-token
# ARG GITLAB_PASS=$CI_JOB_TOKEN
# ARG SSH_PRIVATE_KEY
# ARG SSH_PUBLIC_KEY
ENV GO111MODULE=on
ENV GOPRIVATE=gitlab.switch.ch/ub-unibas/*
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
COPY . .
# RUN cat go.mod
RUN apt-get update && \
apt-get install -y \
git \
openssh-client \
ca-certificates \
protobuf-compiler
# RUN apk add --no-cache ca-certificates git openssh-client
# RUN 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
RUN eval $(ssh-agent -s)
RUN mkdir -p ~/.ssh
RUN chmod 700 ~/.ssh
# #for CI/CD build
RUN echo "$SSH_PRIVATE_KEY" | base64 -d >> ~/.ssh/id_rsa
# #for local build
#RUN echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_rsa
RUN echo "$SSH_PUBLIC_KEY" | tr -d '\r' >> ~/.ssh/authorized_keys
# # set chmod 600 else bas permission it fails
RUN chmod 600 ~/.ssh/id_rsa
RUN chmod 644 ~/.ssh/authorized_keys
RUN ssh-keyscan gitlab.switch.ch >> ~/.ssh/known_hosts
RUN chmod 644 ~/.ssh/known_hosts
#RUN git config --global url."ssh://[email protected]/".insteadOf "https://gitlab.switch.ch/"
RUN git config --global --add url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.switch.ch".insteadOf "https://gitlab.switch.ch"
# RUN ssh -A -v -l git gitlab.switch.ch
# with DOCKER_BUILDKIT=1 for ssh
# RUN --mount=type=ssh go mod download
RUN go mod download
# RUN git clone https://${GITLAB_USER}:${GITLAB_PASS}@gitlab.switch.ch/ub-unibas/dlza/microservices/pbtypes /pbtypes
# RUN go get google.golang.org/protobuf/protoc-gen-go
RUN go get google.golang.org/protobuf
RUN go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
# RUN bash ./build.sh
RUN go build
FROM scratch
WORKDIR /
COPY --from=builder /dlza-manager-handler /
EXPOSE 8080
ENTRYPOINT ["/dlza-manager-handler"]