glow icon indicating copy to clipboard operation
glow copied to clipboard

Docker version (PR idea)

Open pascalandy opened this issue 5 years ago • 4 comments

I made a docker image out of it. It could be optimized but it's good enough at the moment :) It's only 11MB

Let me know if you want a PR

Docker hub

https://hub.docker.com/r/devmtl/glow/tags

Run

input_2=CHANGELOG.md

docker run --rm -it \
  -v $(pwd):/sandbox \
  -w /sandbox \
  devmtl/glow:0.2.0 glow ${input_2}

See output: https://github.com/charmbracelet/glow/issues/139#issue-562094712

Dockerfile

ARG VERSION="0.2.0"
ARG APP_NAME="glow"
ARG GIT_PROJECT_NAME="glow"
ARG GIT_REPO_SOURCE="https://github.com/charmbracelet/glow"

# ----------------------------------------------
# REQUIRED BY OUR GITHUB ACTION CI
# ----------------------------------------------
ARG ALPINE_VERSION="3.11"

# ----------------------------------------------
# STAGE: BASE IMAGE VERSIONNING LAYER
# ----------------------------------------------
FROM alpine:${ALPINE_VERSION} AS myalpine
FROM golang:alpine${ALPINE_VERSION} AS mygolang
# Credit to Tõnis Tiigi / https://bit.ly/2RoCmvG

# ----------------------------------------------
# STAGE: ALPINEBASE LAYER
# ----------------------------------------------
FROM myalpine AS alpinebase

ARG APP_NAME
ARG VERSION

ARG ALPINE_VERSION
ARG GIT_REPO_DOCKERFILE
ARG GIT_REPO_SOURCE

ENV APP_NAME="${APP_NAME}"
ENV VERSION="${VERSION}"
ENV GIT_REPO_SOURCE="${GIT_REPO_SOURCE}"
ENV ALPINE_VERSION="${ALPINE_VERSION}"

ENV LANG=en_US.utf8 \
    TERM=xterm-256color

# Install basics
RUN set -eux && apk --update --no-cache add \
    tini

COPY hello.md /usr/local/bin/hello.md
WORKDIR /usr/local/bin
ENTRYPOINT [ "/sbin/tini", "--" ]
CMD [ "glow", "/usr/local/bin/hello.md" ]

# ----------------------------------------------
# STAGE: BUILDER LAYER
# ----------------------------------------------
FROM mygolang AS gobuilder

ARG APP_NAME
ARG VERSION
ARG GIT_REPO_SOURCE

ENV APP_NAME="${APP_NAME}"
ENV VERSION="${VERSION}"
ENV GIT_REPO_SOURCE="${GIT_REPO_SOURCE}"

# Install common utilities
RUN set -eux && apk --update --no-cache add \
    bash wget curl git nano openssl ca-certificates upx

# Compile Go app
RUN set -eux && \
    git clone "${GIT_REPO_SOURCE}" --depth 1 && \
    cd "${APP_NAME}" && \
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/"${APP_NAME}"

# Compress binary
RUN set -eux && \
    upx /usr/local/bin/"${APP_NAME}" && \
    upx -t /usr/local/bin/"${APP_NAME}" 

# ----------------------------------------------
# STAGE: FINAL
# ----------------------------------------------
FROM alpinebase AS final
COPY --from=gobuilder /usr/local/bin/"${APP_NAME}" /usr/local/bin/"${APP_NAME}"

pascalandy avatar Feb 08 '20 23:02 pascalandy

Looks like a nice contribution, thank you!

As glow should be able to build as a static binary I'm wondering if we really need alpine as a base image, though? We could also look into using goreleaser to publish new releases to Docker Hub.

muesli avatar Feb 10 '20 05:02 muesli

You are right, alpine is not needed. It's just part of my workflow to use it by default. Do you have a post to suggest to learn more about goreleaser? I don't know it's purpose. Thanks!

pascalandy avatar Feb 10 '20 22:02 pascalandy

goreleaser is fantastic and I can highly recommend reading up on it. It automates the entire process of building, packaging & publishing releases. You can find glow's current config in the repo: .goreleaser.yml.

GoReleaser tutorial: https://goreleaser.com/quick-start/

Docker specific tutorial: https://carlosbecker.com/posts/goreleaser-docker/

muesli avatar Feb 11 '20 08:02 muesli

Thanks for sharing! I'll keep this in my backlog :)

pascalandy avatar Feb 11 '20 16:02 pascalandy