Skip to content

Commit cba8ac3

Browse files
authored
Merge pull request #107 from mocachain/feat/e2e-docker-build
feat(e2e): add Docker image build scripts and Dockerfiles
2 parents cf48400 + 4f4474c commit cba8ac3

19 files changed

Lines changed: 1907 additions & 144 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040
### Features
4141

4242
- (proto) [#67](https://github.com/mocachain/moca/pull/67) Publish protos to BSR under moca org
43+
- (e2e) [#105](https://github.com/mocachain/moca/pull/105) Add Kind-based e2e test framework with smoke and upgrade tests
4344

4445
### Improvements
4546

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ DOCKER_TAG := $(COMMIT_HASH)
2727
# e2e env
2828
MOUNT_PATH := $(shell pwd)/build/:/root/
2929
E2E_SKIP_CLEANUP := false
30+
E2E_KIND_DIR := e2e/kind
3031

3132
export GO111MODULE = on
3233

@@ -310,6 +311,37 @@ $(TEST_TARGETS): run-tests
310311
test-unit-cover: ARGS=-timeout=15m -race -coverprofile=coverage.txt -covermode=atomic
311312
test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)
312313

314+
###############################################################################
315+
### Kind E2E Tests ###
316+
###############################################################################
317+
318+
# Run all Kind e2e framework tests
319+
e2e-fw:
320+
@bash $(E2E_KIND_DIR)/framework/runner.sh
321+
322+
# Run a single test: make e2e-fw-test TEST=smoke
323+
e2e-fw-test:
324+
@bash $(E2E_KIND_DIR)/tests/test_$(TEST).sh
325+
326+
# Run without cleanup (for dev): make e2e-fw-dev TEST=smoke
327+
e2e-fw-dev:
328+
@FW_SKIP_CLEANUP=true bash $(E2E_KIND_DIR)/tests/test_$(TEST).sh
329+
330+
# Individual Kind e2e steps
331+
e2e-kind-setup:
332+
@bash $(E2E_KIND_DIR)/scripts/setup-kind.sh
333+
334+
e2e-kind-build:
335+
@bash $(E2E_KIND_DIR)/scripts/build-images.sh
336+
337+
e2e-kind-deploy:
338+
@bash $(E2E_KIND_DIR)/scripts/deploy.sh
339+
340+
e2e-kind-cleanup:
341+
@bash $(E2E_KIND_DIR)/scripts/cleanup.sh
342+
343+
.PHONY: e2e-fw e2e-fw-test e2e-fw-dev e2e-kind-setup e2e-kind-build e2e-kind-deploy e2e-kind-cleanup
344+
313345
test-e2e:
314346
@if [ -z "$(TARGET_VERSION)" ]; then \
315347
echo "Building docker image from local codebase"; \

e2e/kind/Dockerfile.e2e

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# syntax=docker/dockerfile:1
2+
# Build mocad from local source for e2e testing.
3+
FROM golang:1.23.6-bullseye AS builder
4+
5+
ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
6+
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
7+
8+
WORKDIR /workspace
9+
COPY go.mod go.sum ./
10+
RUN --mount=type=cache,target=/go/pkg/mod \
11+
--mount=type=secret,id=gitconfig,target=/root/.gitconfig \
12+
go mod download
13+
14+
COPY . .
15+
RUN --mount=type=cache,target=/go/pkg/mod \
16+
--mount=type=cache,target=/root/.cache/go-build \
17+
--mount=type=secret,id=gitconfig,target=/root/.gitconfig \
18+
make build
19+
20+
FROM debian:bullseye-slim
21+
RUN apt-get update && apt-get install -y ca-certificates jq curl && rm -rf /var/lib/apt/lists/*
22+
COPY --from=builder /workspace/build/mocad /usr/local/bin/mocad
23+
ENTRYPOINT ["mocad"]

e2e/kind/Dockerfile.e2e-gitref

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# syntax=docker/dockerfile:1
2+
# Build mocad from a specific git ref (tag/branch/commit) for upgrade tests.
3+
ARG GO_VERSION=1.23.6
4+
FROM golang:${GO_VERSION}-bullseye AS builder
5+
6+
ARG GIT_REF=main
7+
ARG REPO_URL=github.com/mocachain/moca
8+
9+
ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
10+
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
11+
12+
WORKDIR /workspace
13+
14+
RUN --mount=type=secret,id=gitconfig,target=/root/.gitconfig \
15+
git clone "https://${REPO_URL}.git" . && \
16+
git checkout "${GIT_REF}" && \
17+
make build
18+
19+
FROM debian:bullseye-slim
20+
RUN apt-get update && apt-get install -y ca-certificates jq curl && rm -rf /var/lib/apt/lists/*
21+
COPY --from=builder /workspace/build/mocad /usr/local/bin/mocad
22+
ENTRYPOINT ["mocad"]

0 commit comments

Comments
 (0)