Skip to content

Commit

Permalink
Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Jan 14, 2022
1 parent 4da5dc6 commit d2f9c62
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ jobs:
- name: Lint
run: $HOME/go/bin/golangci-lint run --timeout=2m ./...
- name: Test
run: go test -failfast -race -covermode=atomic -coverprofile=coverage.txt -cover -json ./... | $HOME/go/bin/tparse
run: go test -failfast -race -covermode=atomic -coverprofile=coverage.txt -cover -json ./... | $HOME/go/bin/tparse

build_docker_image:
name: Build Docker image from latest tag
runs-on: ubuntu-latest
steps:
- name: Build image
run: docker build https://github.com/bojand/ghz.git
env:
DOCKER_BUILDKIT: '1'
25 changes: 24 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,27 @@ jobs:
with:
formula-name: ghz
env:
COMMITTER_TOKEN: ${{ secrets.GH_PAGES_ACTION_TOKEN }}
COMMITTER_TOKEN: ${{ secrets.GH_PAGES_ACTION_TOKEN }}

push_docker_image:
name: Push Docker image
needs: github_release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build image
run: docker build -t ghcr.io/${{ github.repository }} .
env:
DOCKER_BUILDKIT: '1'

- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push image to GHCR
run: docker push ghcr.io/${{ github.repository }}
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# syntax=docker.io/docker/dockerfile:1@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2

FROM --platform=$BUILDPLATFORM docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 AS alpine
FROM --platform=$BUILDPLATFORM gcr.io/distroless/base:nonroot@sha256:02f667185ccf78dbaaf79376b6904aea6d832638e1314387c2c2932f217ac5cb AS distroless

FROM alpine AS osmap-linux
RUN echo linux >/os
FROM alpine AS osmap-macos
RUN echo darwin >/os
FROM alpine AS osmap-windows
RUN echo windows >/os
FROM osmap-$TARGETOS AS osmap

FROM alpine AS fetcher
WORKDIR /app
RUN \
--mount=from=osmap,source=/os,target=/os \
set -ux \
&& apk add --no-cache curl \
&& export url=https://github.com/bojand/ghz/releases \
&& export arch=x86_64 \
&& export VERSION=$( ( curl -#fSLo /dev/null -w '%{url_effective}' $url/latest && echo ) | while read -r x; do basename $x; done) \
&& curl -#fSLo exe.tar.gz $url/download/$VERSION/ghz-$(cat /os)-$arch.tar.gz \
&& curl -#fSLo sha2 $url/download/$VERSION/ghz-$(cat /os)-$arch.tar.gz.sha256 \
&& sha256sum exe.tar.gz | grep -F $(cat sha2) \
&& tar xvf exe.tar.gz \
&& rm ghz-web* && mkdir exe && mv ghz* exe/

FROM scratch AS ghz-binary
COPY --from=fetcher /app/exe/* /

FROM distroless AS ghz
COPY --from=ghz-binary --chown=nonroot /ghz /
RUN ["/ghz", "--version"]
ENTRYPOINT ["/ghz"]

0 comments on commit d2f9c62

Please sign in to comment.