Skip to content

Commit

Permalink
Update Dockerfile for non-root usage (#46)
Browse files Browse the repository at this point in the history
* Update gitignore

* Delete docker files

* Update docker file for Multi-Platform Builds

* Update Dockerfile build arguments

* Fix for openshift clusters (#45)

Signed-off-by: Raviteja Lokineni <raviteja.lokineni@verint.com>

---------

Signed-off-by: Raviteja Lokineni <raviteja.lokineni@verint.com>
Co-authored-by: Raviteja Lokineni <bond-@users.noreply.github.com>
  • Loading branch information
raikbitters and bond- authored Aug 17, 2023
1 parent 3e92619 commit b18bc02
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ vendor/*/

## VSCode meta info
.vscode/
.devcontainer/

##release artifacts
release/
46 changes: 38 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
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
ARG TARGETOS
ARG TARGETARCH
ARG APP_VERSION=develop
ARG PACKAGE_COMMONS=github.com/reportportal/commons-go/v5
ARG REPO_NAME=reportportal/service-index
ARG BUILD_BRANCH
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=${BUILD_BRANCH} \
-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
ENV DEPOLY_DIR=/app/service-index
RUN mkdir -p $DEPOLY_DIR
WORKDIR $DEPOLY_DIR

RUN chmod +x /service-index
RUN chgrp -R 0 $DEPOLY_DIR && chmod -R g=u $DEPOLY_DIR

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"]
24 changes: 0 additions & 24 deletions Dockerfile-develop

This file was deleted.

9 changes: 6 additions & 3 deletions DockerfileDev
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ LABEL quay.expires-after=1w

ARG service
RUN apk --no-cache add ca-certificates
WORKDIR /root/

ADD ./bin/service-index /
ENV DEPOLY_DIR=/app/service-index
RUN mkdir -p $DEPOLY_DIR
WORKDIR $DEPOLY_DIR

ADD ./bin/service-index $DEPOLY_DIR/

EXPOSE 8080
ENTRYPOINT ["/service-index"]
ENTRYPOINT ["./service-index"]
14 changes: 0 additions & 14 deletions DockerfileTmpl

This file was deleted.

0 comments on commit b18bc02

Please sign in to comment.