CMSgov/dpc-app

View on GitHub
docker/Dockerfiles/Dockerfile.ssas

Summary

Maintainability
Test Coverage
# syntax = docker/dockerfile:1-experimental
FROM golang:1.18-alpine3.15 AS base

RUN apk update upgrade
RUN apk add git

WORKDIR /go/src/github.com/CMSgov/bcda-app

# Download all dependencies
# By pulling this step out, we can leverage Docker caching
# since our tooling/dependencies do not frequently change.
COPY go.mod go.sum tools.go .
RUN --mount=type=cache,target=/go/pkg/mod \
    cat tools.go | awk '/[\/\/] bcda/{flag=1; next} /[\/\/] end/{flag=0} flag' | awk -F '"' '{print $2}' | xargs -tI % go get %

COPY . .
WORKDIR /go

# Clone bcda-ssas-app over running "go get" since we have issue determining
# the path where the bcda-ssas-app is placed.
# We need to run main --start at a particular location in order to guarantee that
# the config files are placed in the expected spot
RUN git clone https://github.com/CMSgov/bcda-ssas-app.git
WORKDIR /go/bcda-ssas-app
RUN --mount=type=cache,target=/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
    go install -v ./ssas/service/main

FROM golang:1.18-alpine3.15 AS prod

RUN apk update upgrade
RUN apk add openssl

RUN openssl genrsa -out /var/local/private.pem 2048
RUN openssl rsa -in /var/local/private.pem -outform PEM -pubout -out /var/local/public.pem

# Make sure we are in the directory to ensure the config files are resolved as expected
COPY --from=base /go/bcda-ssas-app/ /go/bcda-ssas-app/
COPY --from=base /go/bin/ /go/bin/
WORKDIR /go/bcda-ssas-app/ssas/

ENTRYPOINT ["main"]
CMD ["--start"]