-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
259 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Consumer image to be used for compatibility tests with provider | ||
# use docker's build argument --build-arg to overwrite the defaults | ||
# e.g. docker build --build-arg CONSUMER_TAG=v3.1.0 | ||
ARG CONSUMER_VERSION="latest" | ||
ARG CONSUMER_IMAGE="cosmos-ics" | ||
|
||
FROM golang:1.20-alpine AS is-builder | ||
|
||
ENV PACKAGES curl make git libc-dev bash gcc linux-headers | ||
RUN apk add --no-cache $PACKAGES | ||
|
||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
ENV GOFLAGS="-buildvcs=false" | ||
|
||
# cache go modules - done before the files are copied to allow docker to better cache | ||
COPY go.mod /go.mod | ||
COPY go.sum /go.sum | ||
RUN go mod download | ||
|
||
|
||
# Copy in the repo under test | ||
ADD . /ics-consumer | ||
|
||
WORKDIR /ics-consumer | ||
|
||
# Do not specify version here. It leads to odd replacement behavior | ||
RUN if [ -d "./cosmos-sdk" ]; then go mod edit -replace github.com/cosmos/cosmos-sdk=./cosmos-sdk; fi | ||
RUN go mod tidy | ||
|
||
# Install interchain security binary | ||
RUN make install | ||
|
||
|
||
# The image from where the consumer implementation will be used | ||
# Defaults to | ||
FROM --platform=linux/amd64 ${CONSUMER_IMAGE}:${CONSUMER_VERSION} AS consumer | ||
|
||
# Get Hermes build | ||
FROM ghcr.io/informalsystems/hermes:1.4.1 AS hermes-builder | ||
|
||
# Get CometMock | ||
FROM ghcr.io/informalsystems/cometmock:v0.37.x as cometmock-builder | ||
|
||
# Get GoRelayer | ||
FROM ghcr.io/informalsystems/relayer-no-gas-sim:v2.3.0-rc4-no-gas-sim AS gorelayer-builder | ||
|
||
FROM --platform=linux/amd64 fedora:36 | ||
RUN dnf update -y | ||
RUN dnf install -y which iproute iputils procps-ng vim-minimal tmux net-tools htop jq | ||
USER root | ||
|
||
COPY --from=hermes-builder /usr/bin/hermes /usr/local/bin/ | ||
COPY --from=cometmock-builder /usr/local/bin/cometmock /usr/local/bin/cometmock | ||
COPY --from=gorelayer-builder /bin/rly /usr/local/bin/ | ||
|
||
# Copy consumer from specified image | ||
COPY --from=consumer /usr/local/bin/interchain-security-cd /usr/local/bin/interchain-security-cd | ||
COPY --from=consumer /usr/local/bin/interchain-security-cdd /usr/local/bin/interchain-security-cdd | ||
COPY --from=consumer /usr/local/bin/interchain-security-sd /usr/local/bin/interchain-security-sd | ||
|
||
# Copy provider from local build | ||
COPY --from=is-builder /go/bin/interchain-security-pd /usr/local/bin/interchain-security-pd | ||
|
||
# Copy in the shell scripts that run the testnet | ||
ADD ./tests/e2e/testnet-scripts /testnet-scripts | ||
|
||
# Copy in the hermes config | ||
ADD ./tests/e2e/testnet-scripts/hermes-config.toml /root/.hermes/config.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path" | ||
) | ||
|
||
func setupWorkspace(revision string, tmpDir string) error { | ||
log.Printf("Setting up worktree in '%s'", tmpDir) | ||
cmd := exec.Command("git", "worktree", "add", | ||
"--checkout", tmpDir, revision) | ||
cmd.Stderr = cmd.Stdout | ||
log.Printf("Running: %s", cmd.String()) | ||
if err := cmd.Start(); err != nil { | ||
return err | ||
} | ||
if err := cmd.Wait(); err != nil { | ||
out, _ := cmd.CombinedOutput() | ||
log.Printf("Error creating worktree (%v): %s", err, out) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func cleanupWorkspace(workSpacePath string) error { | ||
cmd := exec.Command("git", "worktree", "remove", workSpacePath) | ||
cmd.Stderr = cmd.Stdout | ||
if err := cmd.Start(); err != nil { | ||
log.Printf("Failed removing git worktree '%s' used for docker image creation", workSpacePath) | ||
return err | ||
} | ||
return cmd.Wait() | ||
} | ||
|
||
// Check if docker is running | ||
func dockerIsUp() bool { | ||
cmd := exec.Command("docker", "info") | ||
var errbuf bytes.Buffer | ||
cmd.Stderr = &errbuf | ||
if err := cmd.Run(); err != nil { | ||
log.Printf("Docker engine is not running (%v): %s", err, errbuf.String()) | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// Build docker image of ICS for a given revision | ||
func buildDockerImage(imageName string, revision string, tmpDir string) error { | ||
log.Printf("Building ICS image for version %s", revision) | ||
|
||
if !dockerIsUp() { | ||
return fmt.Errorf("docker engine is not running") | ||
} | ||
workSpace := path.Join(tmpDir, revision) | ||
if err := setupWorkspace(revision, workSpace); err != nil { | ||
return err | ||
} | ||
defer cleanupWorkspace(workSpace) | ||
|
||
_, err := os.Stat(workSpace) | ||
if err != nil { | ||
log.Fatalf("Worktree creation for image build failed: %v", err) | ||
} | ||
|
||
log.Printf("Building docker image") | ||
cmd := exec.Command("docker", "build", "-t", | ||
fmt.Sprintf("cosmos-ics:%s", revision), "-f", "./Dockerfile", "./") | ||
cmd.Dir = workSpace | ||
//cmd.Stderr = cmd.Stdout | ||
if err := cmd.Start(); err != nil { | ||
log.Printf("Failed building docker image '%s': %v", revision, err) | ||
return err | ||
} | ||
if err := cmd.Wait(); err != nil { | ||
out, _ := cmd.CombinedOutput() | ||
log.Printf("Error building image (%v): %s", err, out) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.