Skip to content

Commit

Permalink
Build CLI Docker Image (#307)
Browse files Browse the repository at this point in the history
Partners might have to run the CLI to export the public key (or generate
it in the first place) and provide it to Ephemera for use in the
`testnet`.

It is not too convenient to download the repo, install go, just to run
the CLI.

Build a docker image instead.

We will eventually need releases here in GH for easy download, and
`homebrew` as well.

The important question is. How should this binary be called?

This should help @jhaaaa with docs.
  • Loading branch information
mkysel authored Dec 5, 2024
1 parent 31c1818 commit 112e7f5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/build-xmtpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ on:
workflow_dispatch:

jobs:

push_to_registry:
name: Push Docker Image to GitHub Packages
strategy:
matrix:
image: ["xmtpd", "xmtpd-cli"]
name: Push Docker Images to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
DOCKER_METADATA_PR_HEAD_SHA: true
outputs:
digest: ${{ steps.push.outputs.digest }}
xmtpd_digest: ${{ steps.set_xmtpd_digest.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,7 +36,7 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/xmtp/xmtpd
images: ghcr.io/xmtp/${{ matrix.image }}
tags: |
type=schedule
type=ref,event=branch
Expand All @@ -51,6 +55,12 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: "GIT_COMMIT=${{ github.event_name != 'pull_request' && github.sha || github.event.pull_request.head.sha }}"

- name: Set xmtpd digest output
if: ${{ matrix.image == 'xmtpd' }}
id: set_xmtpd_digest
run: echo "digest=${{ steps.push.outputs.digest }}" >> $GITHUB_OUTPUT


deploy:
name: Deploy new images to infra
runs-on: ubuntu-latest
Expand All @@ -68,5 +78,5 @@ jobs:
terraform-org: xmtp
terraform-workspace: testnet
variable-name: xmtpd_server_docker_image
variable-value: "ghcr.io/xmtp/xmtpd@${{ needs.push_to_registry.outputs.digest }}"
variable-value: "ghcr.io/xmtp/xmtpd@${{ needs.push_to_registry.outputs.xmtpd_digest }}"
variable-value-required-prefix: "ghcr.io/xmtp/xmtpd@sha256:"
9 changes: 9 additions & 0 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"go.uber.org/zap"
)

var Commit string = "unknown"

type globalOptions struct {
Contracts config.ContractsOptions `group:"Contracts Options" namespace:"contracts"`
Log config.LogOptions `group:"Log Options" namespace:"log"`
Expand Down Expand Up @@ -264,6 +266,13 @@ func updateAddress(logger *zap.Logger, options *CLI) {
}

func main() {
for _, arg := range os.Args[1:] {
if arg == "-v" || arg == "--version" {
fmt.Printf("Version: %s\n", Commit)
return
}
}

options, err := parseOptions(os.Args[1:])
if err != nil {
log.Fatalf("Could not parse options: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion dev/cli
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -eu

go run cmd/cli/main.go "$@"
go run -ldflags="-X main.Commit=$(git rev-parse HEAD)" cmd/cli/main.go "$@"
28 changes: 28 additions & 0 deletions dev/docker/Dockerfile-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# BUILD IMAGE --------------------------------------------------------
ARG GO_VERSION=1.22
FROM golang:${GO_VERSION}-alpine AS builder

# Get build tools and required header files
RUN apk add --no-cache build-base

WORKDIR /app
COPY . .

# Build the final node binary
ARG GIT_COMMIT=unknown
RUN go build -ldflags="-X 'main.Commit=$GIT_COMMIT'" -o bin/xmtpd-cli cmd/cli/main.go

# ACTUAL IMAGE -------------------------------------------------------

FROM alpine:3.12

LABEL maintainer="[email protected]"
LABEL source="https://github.com/xmtp/xmtpd"
LABEL description="XMTPD CLI"

# color, nocolor, json
ENV GOLOG_LOG_FMT=nocolor

COPY --from=builder /app/bin/xmtpd-cli /usr/bin/

ENTRYPOINT ["/usr/bin/xmtpd-cli"]

0 comments on commit 112e7f5

Please sign in to comment.