1
+ # Build Stage
1
2
FROM golang as build
2
3
3
- # go mod Installation source, container environment variable addition will override the default variable value
4
- ENV GO111MODULE=on
5
- ENV GOPROXY=https://goproxy.cn,direct
4
+ # Set go mod installation source and proxy
5
+ ARG GO111MODULE=on
6
+ ARG GOPROXY=https://goproxy.cn,direct
7
+ ENV GO111MODULE=$GO111MODULE
8
+ ENV GOPROXY=$GOPROXY
6
9
7
10
# Set up the working directory
8
11
WORKDIR /Open-IM-Server
9
- # add all files to the container
10
- COPY . .
11
12
12
- WORKDIR /Open-IM-Server/scripts
13
- RUN chmod +x *.sh
14
-
15
- RUN /bin/sh -c ./build_all_service.sh
13
+ # Copy all files to the container
14
+ ADD . .
16
15
17
- # Blank image Multi-Stage Build
18
- FROM ubuntu
16
+ RUN /bin/sh -c "make build"
19
17
20
- RUN rm -rf /var/lib/apt/lists/*
21
- RUN apt-get update && apt-get install apt-transport-https && apt-get install procps\
22
- &&apt-get install net-tools
23
- # Non-interactive operation
24
- ENV DEBIAN_FRONTEND=noninteractive
25
- RUN apt-get install -y vim curl tzdata gawk
26
- # Time zone adjusted to East eighth District
27
- RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
18
+ # Production Stage
19
+ FROM alpine
28
20
21
+ RUN apk --no-cache add tzdata
29
22
30
- # set directory to map logs,config file, scripts file.
31
- VOLUME ["/Open-IM-Server/logs" ,"/Open-IM-Server/config" ,"/Open-IM-Server/scripts" ,"/Open-IM-Server/db/sdk" ]
23
+ # Set directory to map logs, config files, scripts, and SDK
24
+ VOLUME ["/Open-IM-Server/logs" , "/Open-IM-Server/config" , "/Open-IM-Server/scripts" , "/Open-IM-Server/db/sdk" ]
32
25
33
- # Copy scripts files and binary files to the blank image
26
+ # Copy scripts and binary files to the production image
34
27
COPY --from=build /Open-IM-Server/scripts /Open-IM-Server/scripts
35
- COPY --from=build /Open-IM-Server/_output/bin/platforms/linux/amd64 /Open-IM-Server/_output/bin/platforms/linux/amd64
28
+ COPY --from=build /Open-IM-Server/_output/bin/platforms/linux/arm64 /Open-IM-Server/_output/bin/platforms/linux/arm64
36
29
37
30
WORKDIR /Open-IM-Server/scripts
38
31
39
32
CMD ["./docker_start_all.sh" ]
33
+
34
+ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
35
+ .PHONY: docker-buildx
36
+ docker-buildx: test ## Build and push docker image for the manager for cross-platform support
37
+ # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
38
+ sed -e '1 s/\( ^FROM\) /FROM --platform=\$ $\{ BUILDPLATFORM\} /; t' -e ' 1,// s//FROM --platform=\$ $\{ BUILDPLATFORM\} /' Dockerfile > Dockerfile.cross
39
+ - $(CONTAINER_TOOL) buildx create --name project-v3-builder
40
+ $(CONTAINER_TOOL) buildx use project-v3-builder
41
+ - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
42
+ - $(CONTAINER_TOOL) buildx rm project-v3-builder
43
+ rm Dockerfile.cross
0 commit comments