Skip to content

Commit

Permalink
feat: add multi-architecture mirroring
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong(cubxxw-openim) <[email protected]>
  • Loading branch information
cubxxw committed Jul 28, 2023
1 parent ee63487 commit f1989ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 50 deletions.
50 changes: 26 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# Use the official Golang image as a build environment
# docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/openimsdk/openim-chat:v1.0.1 . --push
# Use golang as the builder stage
FROM golang:1.20 as builder

FROM golang:1.20 AS builder

WORKDIR /app

ARG GOARCH
ARG GOOS
WORKDIR /workspace

ENV GOPROXY=https://goproxy.cn

# Copy go mod and go sum files then download dependencies
COPY go.mod go.sum ./
RUN go mod download

ARG GOARCH
ARG GOOS

# Copy source code files into the image
COPY . .

# Compile the source code
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_admin ./cmd/rpc/admin
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_admin_api ./cmd/api/admin_api
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_chat ./cmd/rpc/chat
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o open_im_chat_api ./cmd/api/chat_api
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_admin ./cmd/rpc/admin
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_admin_api ./cmd/api/admin_api
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_chat ./cmd/rpc/chat
RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o ./bin/open_im_chat_api ./cmd/api/chat_api

# Create a new image layer using scratch, copy the built binary files into it
FROM alpine:latest

# Create some directories for mounting, add execution permissions
RUN mkdir -p $WORKDIR/logs \
&& chmod +x $WORKDIR/bin/open_im_admin $WORKDIR/bin/open_im_chat $WORKDIR/bin/open_im_admin_api $WORKDIR/bin/open_im_chat_api \
&& apk --no-cache add ca-certificates curl
# Build the runtime stage
FROM debian

# Set fixed project path
ENV WORKDIR /chat
ENV CMDDIR $WORKDIR/scripts
ENV CONFIG_NAME $WORKDIR/config/config.yaml

COPY ./scripts $WORKDIR/scripts
COPY ./config/config.yaml $WORKDIR/config/config.yaml
COPY --from=builder /app/open_im_admin $WORKDIR/bin/open_im_admin
COPY --from=builder /app/open_im_admin_api $WORKDIR/bin/open_im_admin_api
COPY --from=builder /app/open_im_chat $WORKDIR/bin/open_im_chat
COPY --from=builder /app/open_im_chat_api $WORKDIR/bin/open_im_chat_api
# Copy the executable files to the target directory
COPY --from=builder /workspace/bin/open_im_admin $WORKDIR/bin/open_im_admin
COPY --from=builder /workspace/bin/open_im_admin_api $WORKDIR/bin/open_im_admin_api
COPY --from=builder /workspace/bin/open_im_chat $WORKDIR/bin/open_im_chat
COPY --from=builder /workspace/bin/open_im_chat_api $WORKDIR/bin/open_im_chat_api
COPY --from=builder /workspace/scripts $WORKDIR/scripts
COPY --from=builder /workspace/config/config.yaml $WORKDIR/config/config.yaml

# Create several directories for mounting and add executable permissions
RUN mkdir $WORKDIR/logs && \
chmod +x $WORKDIR/bin/open_im_admin $WORKDIR/bin/open_im_chat $WORKDIR/bin/open_im_admin_api $WORKDIR/bin/open_im_chat_api
RUN apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends ca-certificates curl

VOLUME ["/chat/logs","/chat/config","/chat/scripts"]

Expand Down
26 changes: 0 additions & 26 deletions Dockerfile_test

This file was deleted.

0 comments on commit f1989ab

Please sign in to comment.