Skip to content

Commit

Permalink
Update docker file for Multi-Platform Builds
Browse files Browse the repository at this point in the history
  • Loading branch information
raikbitters committed Jul 12, 2023
1 parent a4ecf35 commit 531cea8
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
FROM alpine:3.16.2
FROM --platform=${BUILDPLATFORM} golang:1.19.1-alpine AS builder

LABEL maintainer="Andrei Varabyeu <andrei_varabyeu@epam.com>"
LABEL version=5.8.0
ENV APP_DIR=/go/src/github.com/org/repo

ENV APP_DOWNLOAD_URL https://github.com/reportportal/service-index/releases/download/v5.8.0/service-index_linux_amd64
RUN apk --no-cache add --upgrade apk-tools
ARG BUILDPLATFORM TARGETOS TARGETARCH
ARG APP_VERSION=develop
ARG PACKAGE_COMMONS=github.com/reportportal/commons-go/v5
ARG REPO_NAME=reportportal/service-index
ARG COMMIT_HASH
ARG BUILD_DATE

ADD . ${APP_DIR}
WORKDIR ${APP_DIR}

RUN echo "I am running on $BUILDPLATFORM, building for TargetOS: $TARGETOS and Targetarch: $TARGETARCH"

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags "-extldflags '"-static"' \
-X ${PACKAGE_COMMONS}/commons.repo=${REPO_NAME} \
-X ${PACKAGE_COMMONS}/commons.branch=${COMMIT_HASH} \
-X ${PACKAGE_COMMONS}/commons.buildDate=${BUILD_DATE} \
-X ${PACKAGE_COMMONS}/commons.version=${APP_VERSION}" \
-o app ./

ADD ${APP_DOWNLOAD_URL} /service-index
FROM --platform=$BUILDPLATFORM alpine:3.16.2
WORKDIR /root/

RUN chmod +x /service-index
ENV APP_DIR=/go/src/github.com/org/repo
ARG APP_VERSION

LABEL maintainer="Andrei Varabyeu <andrei_varabyeu@epam.com>"
LABEL version=${APP_VERSION}

RUN apk --no-cache add --upgrade apk-tools
COPY --from=builder ${APP_DIR}/app .

EXPOSE 8080
ENTRYPOINT ["/service-index"]
ENTRYPOINT ["./app"]

0 comments on commit 531cea8

Please sign in to comment.