Skip to content

Commit

Permalink
fix: docker build & release (#1645)
Browse files Browse the repository at this point in the history
## Description

Fixes the docker image releases
* use debian golang official Docker image
* don't download external libraries - use default dependencies and default build process (this also simplifies the Dockerfile)
* tested with the full process
* use `.dockerfile` extension (lowercase)
* fixed the github action

## Stats

main (alpine): 
* build time 3m 54s
* build time on change: 2m 55s
* build image: 2.95GB
* app image: 118M

this work (debian): 
* build time 2m 26s
* build time on change 2m 05s
* build image: 3.34GB
* app image: 179M (232 with updated ca-certificates and apt registry )


---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Dec 7, 2022
1 parent 3ceefd6 commit 663399b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 55 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/price-feeder-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ jobs:

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: umee-network/price-feeder
tags:
type=semver,pattern=v{{version}}

tags: type=semver,pattern=v{{version}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand All @@ -38,7 +37,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ./contrib/images/price-feeder.Dockerfile
context: ./contrib/images/price-feeder.dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
39 changes: 27 additions & 12 deletions .github/workflows/umee-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
name: Umeed Docker Release
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v[0-9]+\\.[0-9]+\\.[0-9]+" # Official release version tags e.g. v2.0.5
- "v[0-9]+\\.[0-9]+\\.[0-9]+-rc[0-9]+" # Release candidate tags e.g. v1.0.3-rc4
- "v[0-9]+\\.[0-9]+\\.[0-9]+" # Push only official release version tags e.g. v2.0.5

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
umeed-docker:
Expand All @@ -16,18 +18,28 @@ jobs:
- name: checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Docker meta
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: umee-network/umeed

# github.repository == <account>/<repo>
images: ghcr.io/${{ github.repository_owner }}/umeed
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern=latest-{{major}}.{{minor}}
flavor: |
latest=false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Print tags and labels
run: |
echo image: ${{ env.REGISTRY }}/${{ github.repository }}
echo tags "${{ steps.meta.outputs.tags }}"
echo labels "${{ steps.meta.outputs.labels }}"
- name: Login to GHCR
uses: docker/login-action@v2
with:
Expand All @@ -38,8 +50,11 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ./contrib/images/umeed.Dockerfile
push: true
file: contrib/images/umeed.dockerfile
platforms: linux/amd64
# platforms: linux/amd64,linux/arm64 # requires qemu action
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ build: go.sum
build-experimental: go.sum
@echo "--> Building Experimental version..."
EXPERIMENTAL=true $(MAKE) build

build-no_cgo:
@echo "--> Building static binary with no CGO nor GLIBC dynamic linking..."
CGO_ENABLED=0 CGO_LDFLAGS="-static" $(MAKE) build
Expand Down Expand Up @@ -121,7 +121,7 @@ clean:
###############################################################################

docker-build:
@docker build -t umeenet/umeed-e2e -f umee.e2e.Dockerfile .
@docker build -t umeenet/umeed-e2e -f contrib/images/umee.e2e.dockerfile .

docker-push-hermes:
@cd tests/e2e/docker; docker build -t ghcr.io/umee-network/hermes-e2e:latest -f hermes.Dockerfile .; docker push ghcr.io/umee-network/hermes-e2e:latest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Fetch base packages
FROM golang:1.19-alpine AS builder
ENV PACKAGES make git libc-dev gcc linux-headers build-base
RUN apk add --no-cache $PACKAGES
WORKDIR /src/app/
RUN apk add --no-cache make git libc-dev gcc linux-headers build-base
WORKDIR /src/
COPY . .

# Cosmwasm - Download correct libwasmvm version
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
Expand All @@ -14,8 +14,7 @@ RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) &&
# Build the binary
RUN cd price-feeder && LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make install


FROM alpine:3.14
FROM alpine:3.17
RUN apk add bash curl jq
COPY --from=builder /go/bin/price-feeder /usr/local/bin/
EXPOSE 7171
Expand Down
14 changes: 6 additions & 8 deletions umee.e2e.Dockerfile → contrib/images/umee.e2e.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ RUN apk add --no-cache $PACKAGES

# Compile the umeed binary
FROM umee-base-builder AS umeed-builder
WORKDIR /src/app/
COPY go.mod go.sum* ./
WORKDIR /src/umee
COPY . .
RUN go mod download

# Cosmwasm - Download correct libwasmvm version
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
Expand All @@ -21,23 +22,20 @@ RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) &&
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1)

# Copy the remaining files
COPY . .
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make install
RUN cd price-feeder && LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make install

# # Fetch peggo (gravity bridge) binary
FROM base-builder AS peggo-builder
ARG PEGGO_VERSION=v0.3.0
WORKDIR /downloads/
WORKDIR /src/peggo
RUN git clone https://github.com/umee-network/peggo.git
RUN cd peggo && git checkout ${PEGGO_VERSION} && make build && cp ./build/peggo /usr/local/bin/

# Add to a distroless container
FROM gcr.io/distroless/cc:debug
COPY --from=umeed-builder /go/bin/umeed /usr/local/bin/
COPY --from=umeed-builder /go/bin/price-feeder /usr/local/bin/
COPY --from=umeed-builder /go/bin/* /usr/local/bin/
COPY --from=peggo-builder /usr/local/bin/peggo /usr/local/bin/
EXPOSE 26656 26657 1317 9090 7171

EXPOSE 26656 26657 1317 9090 7171
ENTRYPOINT ["umeed", "start"]
23 changes: 0 additions & 23 deletions contrib/images/umeed.Dockerfile

This file was deleted.

23 changes: 23 additions & 0 deletions contrib/images/umeed.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Stage-1: build
# We use Debian Bullseye rather then Alpine because Alpine has problem building libwasmvm
# - requires to download libwasmvm_muslc from external source. Build with glibc is straightforward.
FROM golang:1.19-bullseye AS builder

WORKDIR /src/
COPY . .

RUN LEDGER_ENABLED=false BUILD_TAGS=badgerdb make install

# Stage-2: copy binary and required artifacts to a fresh image
# we need to use debian compatible system.
FROM ubuntu:rolling
# RUN apt update && apt upgrade -y ca-certificates

COPY --from=builder /go/bin/umeed /usr/local/bin/
COPY --from=builder /go/pkg/mod/github.com/\!cosm\!wasm/wasmvm\@v*/internal/api/libwasmvm.*.so /usr/lib/

EXPOSE 26656 26657 1317 9090

# Run umeed by default, omit entrypoint to ease using container with CLI
CMD ["umeed"]
STOPSIGNAL SIGTERM

0 comments on commit 663399b

Please sign in to comment.