Skip to content

Commit

Permalink
refactor(images): remove avif
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Jan 3, 2024
1 parent 48c3300 commit 1fb372f
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 207 deletions.
72 changes: 11 additions & 61 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,75 +1,25 @@
FROM ubuntu:22.04 AS build
# Build the application from source
FROM golang:1.21 AS builder

ARG GO_VERSION TARGETOS TARGETARCH
ARG TARGETOS
ARG TARGETARCH

ENV GO_VERSION=${GO_VERSION}
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

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 \
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/*

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
WORKDIR /app

COPY go.* ./
RUN go mod download

COPY . .

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

FROM ubuntu:22.04
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o morphos .

WORKDIR /app
# Deploy the application binary into a lean image
FROM debian:bookworm-slim AS release

COPY --from=build /app/morphos .
WORKDIR /

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/*
COPY --from=builder /app/morphos /bin/morphos

EXPOSE 8080

ENTRYPOINT ["/app/morphos"]
ENTRYPOINT ["/bin/morphos"]
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ module github.com/danvergara/morphos
go 1.21.3

require (
github.com/Kagami/go-avif v0.1.0
github.com/chai2010/webp v1.1.1
github.com/gabriel-vasile/mimetype v1.4.3
github.com/go-chi/chi/v5 v5.0.10
github.com/stretchr/testify v1.8.4
github.com/strukturag/libheif v1.17.6
golang.org/x/image v0.14.0
golang.org/x/text v0.14.0
)
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/Kagami/go-avif v0.1.0 h1:8GHAGLxCdFfhpd4Zg8j1EqO7rtcQNenxIDerC/uu68w=
github.com/Kagami/go-avif v0.1.0/go.mod h1:OPmPqzNdQq3+sXm0HqaUJQ9W/4k+Elbc3RSfJUemDKA=
github.com/chai2010/webp v1.1.1 h1:jTRmEccAJ4MGrhFOrPMpNGIJ/eybIgwKpcACsrTEapk=
github.com/chai2010/webp v1.1.1/go.mod h1:0XVwvZWdjjdxpUEIf7b9g9VkHFnInUSYujwqTLEuldU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -12,8 +10,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/strukturag/libheif v1.17.6 h1:UFz4FI7kKLINWyL7bcNEBu4gZxK7rHRkwq49IOzHyvE=
github.com/strukturag/libheif v1.17.6/go.mod h1:E/PNRlmVtrtj9j2AvBZlrO4dsBDu6KfwDZn7X1Ce8Ks=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
Expand Down
2 changes: 0 additions & 2 deletions pkg/files/image_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func (i *ImageFactory) NewFile(f string) (File, error) {
return images.NewTiff(), nil
case images.BMP:
return images.NewBmp(), nil
case images.AVIF:
return images.NewAvif(), nil
default:
return nil, fmt.Errorf("type file %s not recognized", f)
}
Expand Down
84 changes: 0 additions & 84 deletions pkg/files/images/avif.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/files/images/bmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewBmp() *Bmp {
b := Bmp{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand Down
1 change: 0 additions & 1 deletion pkg/files/images/gif.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewGif() *Gif {
g := Gif{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand Down
17 changes: 0 additions & 17 deletions pkg/files/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"image/png"
"strings"

"github.com/Kagami/go-avif"
"github.com/chai2010/webp"
"golang.org/x/image/bmp"
"golang.org/x/image/tiff"
Expand All @@ -23,7 +22,6 @@ const (
WEBP = "webp"
TIFF = "tiff"
BMP = "bmp"
AVIF = "avif"

imageMimeType = "image/"
imageType = "image"
Expand Down Expand Up @@ -94,16 +92,6 @@ func toBMP(img image.Image) ([]byte, error) {
return buf.Bytes(), nil
}

func toAvif(img image.Image) ([]byte, error) {
buf := new(bytes.Buffer)

if err := avif.Encode(buf, img, nil); err != nil {
return nil, err
}

return buf.Bytes(), nil
}

func ParseMimeType(mimetype string) string {
if !strings.Contains(mimetype, imageMimeType) {
return mimetype
Expand Down Expand Up @@ -147,11 +135,6 @@ func convertToImage(target string, img image.Image) ([]byte, error) {
if err != nil {
return nil, err
}
case AVIF:
result, err = toAvif(img)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("file format to convert to not supported: %s", target)
}
Expand Down
31 changes: 0 additions & 31 deletions pkg/files/images/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/jpeg",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.JPG,
images.JPEG,
images.GIF,
Expand All @@ -74,7 +73,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/png",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.PNG,
images.GIF,
images.WEBP,
Expand All @@ -97,7 +95,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/png",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.JPG,
images.JPEG,
images.PNG,
Expand All @@ -121,7 +118,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/webp",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.JPG,
images.JPEG,
images.GIF,
Expand All @@ -145,7 +141,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/tiff",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.JPG,
images.JPEG,
images.PNG,
Expand All @@ -169,7 +164,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/png",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.JPG,
images.JPEG,
images.PNG,
Expand All @@ -193,31 +187,6 @@ func TestConvertImage(t *testing.T) {
mimetype: "image/bmp",
supportedFormats: map[string][]string{
"Image": {
images.AVIF,
images.PNG,
images.GIF,
images.WEBP,
images.TIFF,
images.BMP,
},
},
},
},
{
name: "avif to png",
input: input{
filename: "testdata/mr_robot.avif",
mimetype: "image/avif",
targetFileType: "Image",
targetFormat: "png",
imager: images.NewAvif(),
},
expected: expected{
mimetype: "image/png",
supportedFormats: map[string][]string{
"Image": {
images.JPG,
images.JPEG,
images.PNG,
images.GIF,
images.WEBP,
Expand Down
1 change: 0 additions & 1 deletion pkg/files/images/jpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewJpeg() *Jpeg {
j := Jpeg{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
PNG,
GIF,
WEBP,
Expand Down
1 change: 0 additions & 1 deletion pkg/files/images/png.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewPng() *Png {
p := Png{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
GIF,
Expand Down
1 change: 0 additions & 1 deletion pkg/files/images/tiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewTiff() *Tiff {
t := Tiff{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand Down
1 change: 0 additions & 1 deletion pkg/files/images/webp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewWebp() *Webp {
w := Webp{
compatibleFormats: map[string][]string{
"Image": {
AVIF,
JPG,
JPEG,
PNG,
Expand Down

0 comments on commit 1fb372f

Please sign in to comment.