2024-12-07 17:35:42 +08:00
|
|
|
# Use Go 1.22 Alpine as the base image for building the application
|
|
|
|
|
FROM golang:1.22-alpine AS builder
|
|
|
|
|
# Define the base directory for the application as an environment variable
|
|
|
|
|
ENV SERVER_DIR=/openim-server
|
2023-08-04 21:38:30 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Set the working directory inside the container based on the environment variable
|
|
|
|
|
WORKDIR $SERVER_DIR
|
2023-08-04 19:13:22 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Set the Go proxy to improve dependency resolution speed
|
2023-08-04 19:13:22 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
#ENV GOPROXY=https://goproxy.io,direct
|
2023-08-04 19:13:22 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Copy all files from the current directory into the container
|
|
|
|
|
COPY . .
|
2023-08-04 19:13:22 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
RUN go mod tidy
|
2023-08-04 19:13:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
RUN go build -o _output/openim-crontask ./cmd/openim-crontask
|
|
|
|
|
|
2023-08-04 19:13:22 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Using Alpine Linux for the final image
|
|
|
|
|
FROM alpine:latest
|
2023-08-04 19:13:22 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Install necessary packages, such as bash
|
|
|
|
|
RUN apk add --no-cache bash
|
2023-10-21 15:23:33 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Set the environment and work directory
|
|
|
|
|
ENV SERVER_DIR=/openim-server
|
|
|
|
|
WORKDIR $SERVER_DIR
|
2023-08-04 19:13:22 +08:00
|
|
|
|
|
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Copy the compiled binaries and mage from the builder image to the final image
|
|
|
|
|
COPY --from=builder $SERVER_DIR/_output $SERVER_DIR/_output
|
|
|
|
|
# COPY --from=builder $SERVER_DIR/config $SERVER_DIR/config
|
2023-09-05 16:31:40 +08:00
|
|
|
|
2024-12-07 17:35:42 +08:00
|
|
|
# Set the command to run when the container starts
|
|
|
|
|
ENTRYPOINT ["sh", "-c", "_output/openim-crontask"]
|