Skip to content

Commit

Permalink
Merge pull request #46 from lat0z/feature/slim-image
Browse files Browse the repository at this point in the history
use multi-stage container to reduce final size
  • Loading branch information
RoseSecurity authored Aug 28, 2024
2 parents a9cf8d0 + 7d8af85 commit 0bc3cf6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM golang:alpine

FROM golang:alpine AS builder
WORKDIR /usr/src/terramaid
# Terraform version
ARG TERRAFORM_VERSION=1.9.2

Expand All @@ -11,18 +11,27 @@ RUN apk update && apk add --no-cache \
unzip

# Install Terraform
RUN curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip && \
unzip terraform.zip && \
mv terraform /usr/local/bin/ && \
rm terraform.zip

# Set the working directory for Terramaid
WORKDIR /usr/src/terramaid
RUN <<EOF
curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip
unzip terraform.zip
EOF

# Copy the source code and build
COPY . .
RUN go mod download && go mod verify
RUN go build -v -o /usr/local/bin/terramaid main.go
RUN <<EOF
go mod download && go mod verify
go build -v -o ./terramaid main.go
EOF

FROM alpine:3.20.2
COPY --from=builder /usr/src/terramaid/terraform /usr/local/bin/terraform
COPY --from=builder /usr/src/terramaid/terramaid /usr/local/bin/terramaid

RUN apk update && apk add --no-cache git
USER nobody

#Set the working directory for Terramaid
WORKDIR /usr/src/terramaid

# Set the entrypoint and default command
ENTRYPOINT ["/usr/local/bin/terramaid"]

0 comments on commit 0bc3cf6

Please sign in to comment.