Skip to content

Commit

Permalink
build(docker): add multi stage to the dockerfile with ubuntu (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara authored Jan 1, 2024
1 parent 8d40e46 commit 48c3300
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
FROM ubuntu:22.04 AS base
FROM ubuntu:22.04 AS build

ARG GO_VERSION
ENV GO_VERSION=${GO_VERSION}

RUN apt-get update
RUN apt-get install -y wget git gcc

RUN wget -P /tmp "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"

RUN tar -C /usr/local -xzf "/tmp/go${GO_VERSION}.linux-amd64.tar.gz"
RUN rm "/tmp/go${GO_VERSION}.linux-amd64.tar.gz"
ARG GO_VERSION TARGETOS TARGETARCH

ENV GO_VERSION=${GO_VERSION}
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

WORKDIR $GOPATH

FROM base AS builder

RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:strukturag/libde265 && \
add-apt-repository ppa:strukturag/libheif && \
apt-get install -y --no-install-recommends cmake \
wget \
git \
gcc \
make \
pkg-config \
x265 \
Expand All @@ -35,11 +25,15 @@ RUN apt-get update && \
libaom-dev \
libheif1 \
libheif-dev && \
apt-get clean && \
apt-get autoremove -y && \
apt-get purge -y --auto-remove && \
rm -rf /var/lib/apt/lists/*

ARG TARGETOS
ARG TARGETARCH
RUN wget --no-check-certificate -P /tmp "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" && \
tar -C /usr/local -xzf "/tmp/go${GO_VERSION}.linux-amd64.tar.gz" && \
rm "/tmp/go${GO_VERSION}.linux-amd64.tar.gz"

RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

WORKDIR /build

Expand All @@ -50,4 +44,32 @@ COPY . .

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags='-s -w' -trimpath -o /app/morphos .

FROM ubuntu:22.04

WORKDIR /app

COPY --from=build /app/morphos .

RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:strukturag/libde265 && \
add-apt-repository ppa:strukturag/libheif && \
apt-get install -y --no-install-recommends cmake \
make \
pkg-config \
x265 \
libx265-dev \
libde265-dev \
libjpeg-dev \
libtool \
zlib1g-dev \
libaom-dev \
libheif1 \
libheif-dev && \
apt-get autoremove -y && \
apt-get purge -y --auto-remove && \
rm -rf /var/lib/apt/lists/*

EXPOSE 8080

ENTRYPOINT ["/app/morphos"]

0 comments on commit 48c3300

Please sign in to comment.