Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evans distribution using docker #559

Merged
merged 5 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.git*
/.idea
/.vscode
/scripts
/Dockerfile*
/*.md
/*.gif
/Makefile
/evans
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,18 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt

test-docker-image-building:
name: Test docker image building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: docker/build-push-action@v3 # Action page: <https://github.com/docker/build-push-action>
with:
context: .
file: Dockerfile
push: false
tags: app:ci

- run: docker run --rm app:ci --version
32 changes: 32 additions & 0 deletions .github/workflows/release_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: release_docker_image

on:
release: # Docs: <https://help.github.com/en/articles/events-that-trigger-workflows#release-event-release>
types: [published]

jobs:
docker-image:
name: Build the docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: gacts/github-slug@v1 # Action page: <https://github.com/gacts/github-slug>
id: slug
- uses: docker/build-push-action@v3 # Action page: <https://github.com/docker/build-push-action>
with:
context: .
file: Dockerfile
push: true
platforms: linux/386,linux/amd64,linux/arm64,linux/arm/v6
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}.${{ steps.slug.outputs.version-patch }}
ghcr.io/${{ github.repository }}:${{ steps.slug.outputs.version-major }}.${{ steps.slug.outputs.version-minor }}
ghcr.io/${{ github.repository }}:${{ steps.slug.outputs.version-major }}
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# syntax=docker/dockerfile:1.2

# Image page: <https://hub.docker.com/_/golang>
FROM golang:1.18-alpine as builder

WORKDIR /src

COPY . /src

RUN set -x \
&& CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o ./evans . \
&& ./evans --version

WORKDIR /tmp/rootfs

# prepare the rootfs for scratch
RUN set -x \
&& mkdir -p ./bin ./etc/ssl ./tmp ./mount ./.config/evans ./.cache \
&& mv /src/evans ./bin/evans \
&& echo 'evans:x:10001:10001::/tmp:/sbin/nologin' > ./etc/passwd \
&& echo 'evans:x:10001:' > ./etc/group \
&& cp -R /etc/ssl/certs ./etc/ssl/certs \
&& chown -R 10001:10001 ./.config ./.cache \
&& chmod -R 777 ./tmp ./mount ./.config ./.cache

# use empty filesystem
FROM scratch as runtime

LABEL \
# Docs: <https://github.com/opencontainers/image-spec/blob/master/annotations.md>
org.opencontainers.image.title="evans" \
org.opencontainers.image.description="more expressive universal gRPC client" \
org.opencontainers.image.url="https://github.com/ktr0731/evans" \
org.opencontainers.image.source="https://github.com/ktr0731/evans" \
org.opencontainers.image.vendor="evans" \
org.opencontainers.image.licenses="MIT"

# use an unprivileged user
USER 10001:10001

# import from builder
COPY --from=builder /tmp/rootfs /

WORKDIR "/mount"

ENTRYPOINT ["/bin/evans"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ So, you can format it by any commands like `jq`. Also, if you want to use the sa
- [Installation](#installation)
- [From GitHub Releases](#from-github-releases)
- [macOS](#macos)
- [Docker image](#docker-image)
- [[Not-recommended] go get](#not-recommended-go-get)
- [Usage (REPL)](#usage-repl)
- [Basic usage](#basic-usage)
Expand Down Expand Up @@ -81,6 +82,19 @@ $ brew tap ktr0731/evans
$ brew install evans
```

### Docker image
You can use our docker image to run Evans - please see [container registry](https://github.com/ktr0731/evans/pkgs/container/evans).
For example, if you want to connect to the server on host `example.com` on port `50051` using proto file in `./proto/files/file-name.proto` (default working directory is `/mount`):
```sh
$ docker run --rm -v "$(pwd):/mount:ro" \
ghcr.io/ktr0731/evans:latest \
--path ./proto/files \
--proto file-name.proto \
--host example.com \
--port 50051 \
repl
```

### **[Not-recommended]** go install

Go v1.16 or later is required.
Expand Down