-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ARM64 Support and Optimize Build Process (#145)
* Add ARM64 Support and Optimize Build Process --------- Co-authored-by: Sam Lin <[email protected]>
- Loading branch information
1 parent
10348e6
commit 89790e9
Showing
7 changed files
with
265 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,103 @@ | ||
# Define build arguments with default values | ||
ARG MONGODB_TOOLS_VERSION=100.8.0 | ||
ARG EN_AWS_CLI=false | ||
ARG AWS_CLI_VERSION=1.29.44 | ||
ARG EN_AZURE=false | ||
ARG AZURE_CLI_VERSION=2.52.0 | ||
ARG AZURE_CLI_VERSION=2.63.0 | ||
ARG EN_GCLOUD=false | ||
ARG GOOGLE_CLOUD_SDK_VERSION=445.0.0 | ||
ARG GOOGLE_CLOUD_SDK_VERSION=499.0.0 | ||
ARG EN_GPG=true | ||
ARG GNUPG_VERSION="2.4.4-r0" | ||
ARG EN_MINIO=false | ||
ARG EN_RCLONE=false | ||
ARG VERSION | ||
|
||
# Stage 1: tools-builder stage for MongoDB tools | ||
FROM maxisam/mongo-tool:${MONGODB_TOOLS_VERSION} AS tools-builder | ||
|
||
FROM golang:1.21 AS mgob-builder | ||
# Stage 2: mgob-builder stage for the mgob binary | ||
FROM --platform=$BUILDPLATFORM golang:1.21 AS mgob-builder | ||
ARG VERSION | ||
COPY . /go/src/github.com/stefanprodan/mgob | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
# Set environment variables for Go | ||
ENV GOOS=${TARGETOS} \ | ||
GOARCH=${TARGETARCH} \ | ||
CGO_ENABLED=0 | ||
|
||
# Set working directory | ||
WORKDIR /go/src/github.com/stefanprodan/mgob | ||
RUN CGO_ENABLED=0 GOOS=linux go test ./pkg/... && \ | ||
CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.version=$VERSION" -a -installsuffix cgo -o mgob github.com/stefanprodan/mgob/cmd/mgob | ||
|
||
# Copy source code | ||
COPY . . | ||
|
||
# Build and test the mgob binary | ||
RUN go test ./pkg/... && \ | ||
go build -ldflags "-X main.version=$VERSION" -o mgob ./cmd/mgob | ||
|
||
# Stage 3: final image setup with Alpine | ||
FROM alpine:3.18 | ||
|
||
# Define build arguments | ||
ARG BUILD_DATE | ||
ARG VCS_REF | ||
ARG VERSION | ||
ARG MONGODB_TOOLS_VERSION | ||
ARG AWS_CLI_VERSION | ||
ARG AZURE_CLI_VERSION | ||
ARG GOOGLE_CLOUD_SDK_VERSION | ||
ARG GNUPG_VERSION | ||
ARG EN_AWS_CLI | ||
ARG EN_AZURE | ||
ARG EN_GCLOUD | ||
ARG EN_GPG | ||
ARG EN_MINIO | ||
ARG EN_RCLONE | ||
ENV MONGODB_TOOLS_VERSION=$MONGODB_TOOLS_VERSION \ | ||
GNUPG_VERSION=$GNUPG_VERSION \ | ||
GOOGLE_CLOUD_SDK_VERSION=$GOOGLE_CLOUD_SDK_VERSION \ | ||
AZURE_CLI_VERSION=$AZURE_CLI_VERSION \ | ||
AWS_CLI_VERSION=$AWS_CLI_VERSION \ | ||
MGOB_EN_AWS_CLI=$EN_AWS_CLI \ | ||
MGOB_EN_AZURE=$EN_AZURE \ | ||
MGOB_EN_GCLOUD=$EN_GCLOUD \ | ||
MGOB_EN_GPG=$EN_GPG \ | ||
MGOB_EN_MINIO=$EN_MINIO \ | ||
MGOB_EN_RCLONE=$EN_RCLONE | ||
|
||
# Set environment variables | ||
ENV MONGODB_TOOLS_VERSION=${MONGODB_TOOLS_VERSION} \ | ||
GOOGLE_CLOUD_SDK_VERSION=${GOOGLE_CLOUD_SDK_VERSION} \ | ||
AZURE_CLI_VERSION=${AZURE_CLI_VERSION} \ | ||
AWS_CLI_VERSION=${AWS_CLI_VERSION} \ | ||
MGOB_EN_AWS_CLI=${EN_AWS_CLI} \ | ||
MGOB_EN_AZURE=${EN_AZURE} \ | ||
MGOB_EN_GCLOUD=${EN_GCLOUD} \ | ||
MGOB_EN_GPG=${EN_GPG} \ | ||
MGOB_EN_MINIO=${EN_MINIO} \ | ||
MGOB_EN_RCLONE=${EN_RCLONE} | ||
|
||
# Set working directory | ||
WORKDIR / | ||
|
||
COPY build.sh /tmp | ||
RUN /tmp/build.sh | ||
# Copy and run the build script | ||
COPY build.sh /tmp/ | ||
RUN chmod +x /tmp/build.sh && /tmp/build.sh | ||
|
||
# Set the PATH for Google Cloud SDK | ||
ENV PATH="/google-cloud-sdk/bin:${PATH}" | ||
COPY --from=mgob-builder /go/src/github.com/stefanprodan/mgob/mgob . | ||
COPY --from=tools-builder /go/mongo-tools/bin/* /usr/bin/ | ||
|
||
# Copy the mgob binary from the builder | ||
COPY --from=mgob-builder /go/src/github.com/stefanprodan/mgob/mgob /usr/local/bin/ | ||
RUN chmod +x /usr/local/bin/mgob | ||
|
||
# Copy MongoDB tools from the tools-builder | ||
COPY --from=tools-builder /usr/local/bin/ /usr/bin/ | ||
|
||
# Install necessary runtime dependencies for MongoDB tools | ||
RUN apk add --no-cache krb5-libs | ||
|
||
# Volumes for storage | ||
VOLUME ["/storage", "/tmp", "/data"] | ||
|
||
LABEL org.label-schema.build-date=$BUILD_DATE \ | ||
org.label-schema.name="mgob" \ | ||
org.label-schema.description="MongoDB backup automation tool" \ | ||
org.label-schema.url="https://github.com/stefanprodan/mgob" \ | ||
org.label-schema.vcs-ref=$VCS_REF \ | ||
org.label-schema.vcs-url="https://github.com/stefanprodan/mgob" \ | ||
org.label-schema.vendor="stefanprodan.com,maxisam" \ | ||
org.label-schema.version=$VERSION \ | ||
org.label-schema.schema-version="1.0" | ||
|
||
ENTRYPOINT [ "./mgob" ] | ||
# Labels for image metadata | ||
LABEL org.label-schema.build-date=${BUILD_DATE} \ | ||
org.label-schema.name="mgob" \ | ||
org.label-schema.description="MongoDB backup automation tool" \ | ||
org.label-schema.url="https://github.com/stefanprodan/mgob" \ | ||
org.label-schema.vcs-ref=${VCS_REF} \ | ||
org.label-schema.vcs-url="https://github.com/stefanprodan/mgob" \ | ||
org.label-schema.vendor="stefanprodan.com,maxisam" \ | ||
org.label-schema.version=${VERSION} \ | ||
org.label-schema.schema-version="1.0" | ||
|
||
# Entry point for the mgob application | ||
ENTRYPOINT [ "/usr/local/bin/mgob" ] |
Oops, something went wrong.