Skip to content

Commit

Permalink
chore: reduce dowload of go mods
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Aug 7, 2024
1 parent 62487f7 commit 43efd95
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ build: BUILD_ARGS=-o $(BUILDDIR)/ ## Build babylond binary
build-linux: ## Build babylond linux version binary
GOOS=linux GOARCH=$(if $(findstring aarch64,$(shell uname -m)) || $(findstring arm64,$(shell uname -m)),arm64,amd64) LEDGER_ENABLED=false $(MAKE) build

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
$(BUILD_TARGETS): $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
Expand Down
16 changes: 11 additions & 5 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ babylond: babylond-rmi

babylond-e2e: babylond-rmi
docker build --tag babylonlabs-io/babylond -f babylond/Dockerfile ${BABYLON_FULL_PATH} \
--build-arg BUILD_TAGS="e2e"
--build-arg BUILD_TAGS="e2e" --progress=plain

## TODO: once release docker public versions for tags, remove this!
babylond-before-upgrade:
docker rmi babylonlabs-io/babylond-before-upgrade 2>/dev/null; true && \
docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile \
docker build --tag babylonlabs-io/babylond-before-upgrade -f babylond/Dockerfile --progress=plain \
--build-arg VERSION="${BABYLON_VERSION_BEFORE_UPGRADE}" ${BABYLON_FULL_PATH}

babylond-rmi:
docker rmi babylonlabs-io/babylond 2>/dev/null; true
docker rmi babylonlabs-io/babylond --force 2>/dev/null; true

babylond-rmi-upgrade:
docker rmi babylonlabs-io/babylond-before-upgrade --force 2>/dev/null; true

e2e-init-chain-rmi:
docker rmi babylonlabs-io/babylond-e2e-init-chain --force 2>/dev/null; true

e2e-init-chain:
@DOCKER_BUILDKIT=1 docker build -t babylonlabs-io/babylond-e2e-init-chain --build-arg E2E_SCRIPT_NAME=chain --platform=linux/x86_64 \
Expand All @@ -31,4 +37,4 @@ cosmos-relayer: cosmos-relayer-rmi
cosmos-relayer-rmi:
docker rmi babylonlabs-io/cosmos-relayer 2>/dev/null; true

.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi cosmos-relayer-rmi
.PHONY: all babylond babylond-before-upgrade cosmos-relayer e2e-init-chain babylond-rmi babylond-rmi-upgrade cosmos-relayer-rmi
57 changes: 22 additions & 35 deletions contrib/images/babylond/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,45 @@
FROM golang:1.21 AS build-env
FROM golang:1.21 as go-bbn

Check warning on line 1 in contrib/images/babylond/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Version to build. Default is empty
ARG VERSION

ARG BUILD_TAGS=""
ARG LEDGER_ENABLED="false"
# Cosmos build options
ARG COSMOS_BUILD_OPTIONS=""

# Install cli tools for building and final image
RUN apt-get update && apt-get install -y make git bash gcc curl jq

# Build
WORKDIR /go/src/github.com/babylonlabs-io/babylon
# First cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/babylon/
RUN go mod download
# Then copy everything else
COPY ./ /go/src/github.com/babylonlabs-io/babylon/
# If version is set, then checkout this version

# Handle if version is set
RUN if [ -n "${VERSION}" ]; then \
git fetch --all; \
git fetch origin tag ${VERSION} --no-tags; \
git checkout -f ${VERSION}; \
fi

FROM go-bbn as go-bbn-dep

Check warning on line 15 in contrib/images/babylond/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Cache mod dependencies
RUN go mod download

FROM go-bbn-dep as build-env

Check warning on line 20 in contrib/images/babylond/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

ARG BUILD_TAGS=""
ARG LEDGER_ENABLED="false"
ARG COSMOS_BUILD_OPTIONS=""

RUN LEDGER_ENABLED=$LEDGER_ENABLED \
BUILD_TAGS=$BUILD_TAGS \
COSMOS_BUILD_OPTIONS=$COSMOS_BUILD_OPTIONS \
LINK_STATICALLY=false \
make build

FROM debian:bookworm-slim AS run
# Create a user
RUN addgroup --gid 1137 --system babylon && adduser --uid 1137 --gid 1137 --system --home /home/babylon babylon
RUN apt-get update && apt-get install -y bash curl jq wget
FROM debian:bookworm-slim AS wasm-link
ARG WASMVM_VERSION="v2.0.1"

RUN apt-get update && apt-get install -y wget bash

# Label should match your github repo
LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylond:${VERSION}"

Check warning on line 38 in contrib/images/babylond/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$VERSION' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

# Install libraries
# Cosmwasm - Download correct libwasmvm version
COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/go.mod /tmp
RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \
-O /lib/libwasmvm.$(uname -m).so && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1)
RUN rm -f /tmp/go.mod
RUN wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.x86_64.so \
-O /lib/libwasmvm.x86_64.so

FROM wasm-link as final

Check warning on line 44 in contrib/images/babylond/Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/build/babylond /bin/babylond

# Set home directory and user
WORKDIR /home/babylon
RUN chown -R babylon /home/babylon
RUN chmod g+s /home/babylon
USER babylon
31 changes: 11 additions & 20 deletions contrib/images/e2e-initialization/init.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@ FROM golang:1.21 as build-env

ARG E2E_SCRIPT_NAME

# Install cli tools for building and final image
RUN apt-get update && apt-get install -y make git bash gcc curl jq

# Copy All
WORKDIR /go/src/github.com/babylonlabs-io/babylon

# First cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/babylon/
RUN go mod download

# Copy everything else
COPY ./ /go/src/github.com/babylonlabs-io/babylon/

RUN LEDGER_ENABLED=false LINK_STATICALLY=false E2E_SCRIPT_NAME=${E2E_SCRIPT_NAME} make e2e-build-script

FROM debian:bookworm-slim AS run
FROM debian:bookworm-slim AS wasm-link
ARG WASMVM_VERSION="v2.0.1"

RUN apt-get update && apt-get install -y wget bash

# Create a user
RUN addgroup --gid 1137 --system babylon && adduser --uid 1137 --gid 1137 --system --home /home/babylon babylon
RUN apt-get update && apt-get install -y bash curl jq wget
# Label should match your github repo
LABEL org.opencontainers.image.source="https://github.com/babylonlabs-io/babylond:${VERSION}"

COPY --from=build-env /go/src/github.com/babylonlabs-io/babylon/go.mod /tmp
RUN WASMVM_VERSION=$(grep github.com/CosmWasm/wasmvm /tmp/go.mod | cut -d' ' -f2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$(uname -m).so \
-O /lib/libwasmvm.$(uname -m).so && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm.$(uname -m).so | grep $(cat /tmp/checksums.txt | grep libwasmvm.$(uname -m) | cut -d ' ' -f 1)
# Cosmwasm - Download correct libwasmvm version
RUN wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.x86_64.so \
-O /lib/libwasmvm.x86_64.so

FROM wasm-link as final
# Args only last for a single build stage - renew
ARG E2E_SCRIPT_NAME

Expand Down

0 comments on commit 43efd95

Please sign in to comment.