Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 46 additions & 35 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
FROM debian:bullseye as builder

ENV TZ=America/New_York
ENV PATH=/go/bin:$PATH
ENV GOROOT=/go
ENV GOPATH=/src/go

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &&\
mkdir /go &&\
mkdir -p /src/go &&\
apt update &&\
apt -y install build-essential &&\
apt -y install gdal-bin gdal-data libgdal-dev &&\
apt -y install wget &&\
wget https://golang.org/dl/go1.19.5.linux-amd64.tar.gz -P / &&\
tar -xvzf /go1.19.5.linux-amd64.tar.gz -C / &&\
apt -y install vim &&\
apt -y install git

WORKDIR /app
RUN git clone https://github.com/USACE/go-consequences.git
WORKDIR /app/go-consequences
RUN go mod download
RUN go mod tidy
RUN go build main.go


FROM ghcr.io/osgeo/gdal:ubuntu-full-3.8.3 as prod
RUN apt update &&\
apt -y install build-essential &&\
apt -y install pkg-config &&\
apt -y install gdal-bin gdal-data libgdal-dev
WORKDIR /app
COPY --from=builder /app/go-consequences/main .
ENTRYPOINT ["/main"]
# Stage 1: Builder
FROM debian:bullseye AS builder

ENV TZ=America/New_York
ENV PATH=/go/bin:$PATH
ENV GOROOT=/go
ENV GOPATH=/src/go

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &&\
mkdir -p /go &&\
mkdir -p /src/go &&\
apt update &&\
apt -y install build-essential &&\
apt -y install libgdal-dev &&\
apt -y install gdal-bin &&\
apt -y install gdal-data &&\
apt -y install wget &&\
wget https://golang.org/dl/go1.19.5.linux-amd64.tar.gz -P / &&\
tar -xvzf /go1.19.5.linux-amd64.tar.gz -C / &&\
apt -y install vim &&\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vim isnt necessary for the builder

apt -y install git

WORKDIR /app
RUN git clone https://github.com/USACE/go-consequences.git
WORKDIR /app/go-consequences
RUN go mod download
RUN go mod tidy
RUN go build -o main .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill have to research this tag now.


# Stage 2: Production
FROM ghcr.io/osgeo/gdal:ubuntu-full-3.8.3 AS prod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this all looks much better, not doing build essential, and pulling the libraries you actually need. super cool great job. will have to test it


# Move the executable from build to production
WORKDIR /app
COPY --from=builder /app/go-consequences/main ./

# Install necessary GDAL libraries
RUN apt update && \
apt install -y libgdal-dev && \
ln -s /usr/lib/libgdal.so /usr/lib/libgdal.so.28 && \
ldconfig

# Verify library dependencies for debugging
RUN ldd ./main

ENTRYPOINT ["/app/main"]