From b565a90685ab5fe810771b22e1fcc0ebd01daa0d Mon Sep 17 00:00:00 2001 From: Tine Jozelj Date: Fri, 25 Dec 2020 16:04:39 +0100 Subject: [PATCH] feat(packages): add glow --- .github/workflows/packages.yaml | 53 +++++++++++++++++++++++++++++++++ Dockerfile.ubuntu | 1 + Makefile | 3 ++ packages/Dockerfile.glow | 26 ++++++++++++++++ workspace.toml | 4 +++ 5 files changed, 87 insertions(+) create mode 100644 packages/Dockerfile.glow diff --git a/.github/workflows/packages.yaml b/.github/workflows/packages.yaml index a3de6b8..54f10aa 100644 --- a/.github/workflows/packages.yaml +++ b/.github/workflows/packages.yaml @@ -114,3 +114,56 @@ jobs: run: | docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} + glow: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Prepare + id: prepare + run: | + DOCKER_IMAGE=ghcr.io/mentos1386/glow + DOCKER_PLATFORMS=linux/amd64,linux/arm64 + VERSION=1.3.0 + + TAGS="--tag ${DOCKER_IMAGE}:${VERSION} --tag ${DOCKER_IMAGE}:latest" + + echo ::set-output name=docker_image::${DOCKER_IMAGE} + echo ::set-output name=version::${VERSION} + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ + --build-arg VERSION=${VERSION} \ + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ + --build-arg VCS_REF=${GITHUB_SHA::8} \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + ${TAGS} --file ./packages/Dockerfile.glow . + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-glow-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-glow- + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Docker Buildx (build) + run: | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} + - name: Login to Github Registry + if: success() && github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + - name: Docker Buildx (push) + if: success() && github.event_name != 'pull_request' + run: | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} + - name: Inspect image + if: always() && github.event_name != 'pull_request' + run: | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} + diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index a3998e4..3fa7054 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -53,6 +53,7 @@ RUN set -ueox pipefail \ # Install other packages COPY --from=ghcr.io/mentos1386/starship:0.47.0 /usr/local/bin/starship /usr/local/bin/starship COPY --from=ghcr.io/mentos1386/kubectl:1.20.0 /usr/local/bin/kubectl /usr/local/bin/kubectl +COPY --from=ghcr.io/mentos1386/glow:1.3.0 /usr/local/bin/glow /usr/local/bin/glow # Golang COPY --from=golang:1.15.6 --chown=${SSH_USER} /usr/local/go /home/${SSH_USER}/.go ENV PATH=/home/${SSH_USER}/.go/bin:$PATH diff --git a/Makefile b/Makefile index 93dd88f..498b39d 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ build-package-starship: build-package-kubectl: @docker buildx build --load -t ${REGISTRY}/kubectl:1.20.0 -f packages/Dockerfile.kubectl packages/ +build-package-glow: + @docker buildx build --progress plain --load -t ${REGISTRY}/glow:1.3.0 -f packages/Dockerfile.glow packages/ + build-packages: package-kubectl package-starship template: diff --git a/packages/Dockerfile.glow b/packages/Dockerfile.glow new file mode 100644 index 0000000..2ee36ef --- /dev/null +++ b/packages/Dockerfile.glow @@ -0,0 +1,26 @@ +FROM alpine:3 as build + +WORKDIR /root + +RUN apk --no-cache add curl tar + +ARG VERSION=1.3.0 +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +# We have to override ARCH if amd64 +# https://github.com/charmbracelet/glow/blob/b9e5d6b144b111ade70e30b7f31e1c46f79a7ec9/.goreleaser.yml#L33-L37 +RUN if [[ "${TARGETARCH}" == "amd64" ]]; then export ARCH="x86_64"; else export ARCH="${TARGETARCH}"; fi \ +&& curl -L -o glow.tar.gz \ + "https://github.com/charmbracelet/glow/releases/download/v${VERSION}/glow_${VERSION}_${TARGETOS}_${ARCH}${TARGETVARIANT}.tar.gz" +RUN tar -xzvf glow.tar.gz + +FROM alpine:3 +LABEL maintainer="Tine Jozelj " +LABEL org.opencontainers.image.source https://github.com/mentos1386/workspace + +COPY --from=build /root/glow /usr/local/bin/glow + +ENTRYPOINT /usr/local/bin/glow + diff --git a/workspace.toml b/workspace.toml index 9345979..6178782 100644 --- a/workspace.toml +++ b/workspace.toml @@ -25,3 +25,7 @@ version = "1.20.0" name = "starship" version = "0.47.0" +[[templates."package-action".vars.jobs]] +name = "glow" +version = "1.3.0" +