Skip to content

Commit

Permalink
feat(CI): build and run the tests in a container
Browse files Browse the repository at this point in the history
Add an option to run the unit-tests with no setup require. Below are the
two [1], [2] options, one with :devel docker tags and one with
customizable tags.

[1]
```
docker compose -f compose.yaml run unit-test
```

[2]
```
export REPOSITORY=ghcr.io/
export TAG=pr-001
docker compose -f compose.yaml -f compose.override-tags.yaml run unit-test
```

feat(CI): update workflows
  • Loading branch information
mpolitzer committed Feb 6, 2025
1 parent bb2ae66 commit 9fea9ef
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 92 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.git*
**/target/
.gitignore
cartesi-rollups-authority-claimer
Expand Down
3 changes: 2 additions & 1 deletion .github/license-check/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"include": ["**/*.go", "**/*.rs"],
"exclude": [
"cmd/authority-claimer/target/**",
"internal/repository/postgres/db/**",
"pkg/contracts/**",
"pkg/readerclient/generated.go",
"pkg/inspectclient/generated.go",
"pkg/readerclient/generated.go",
"rollups-contracts/**"
],
"license": ".github/license-check/header.txt"
Expand Down
144 changes: 63 additions & 81 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ permissions:

jobs:
build-ci-base:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
output: ${{ steps.export_tag.outputs.image_tag }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Docker meta
id: docker_meta
Expand All @@ -47,25 +45,53 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- uses: depot/setup-action@v1
- name: Build and push docker image
id: docker_build
uses: depot/bake-action@v1

- name: Build and push devnet image
uses: depot/build-push-action@v1
with:
file: test/devnet/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
tags: ghcr.io/cartesi/rollups-node-devnet:${{steps.docker_meta.outputs.version}}
push: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
project: ${{ vars.DEPOT_PROJECT }}
token: ${{ secrets.DEPOT_TOKEN }}

- name: Build and push node image
uses: depot/build-push-action@v1
with:
file: Dockerfile
context: .
platforms: linux/amd64,linux/arm64
tags: ghcr.io/cartesi/rollups-node:${{steps.docker_meta.outputs.version}}
push: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
project: ${{ vars.DEPOT_PROJECT }}
token: ${{ secrets.DEPOT_TOKEN }}

- name: Build and push test image
uses: depot/build-push-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
./docker-bake.platforms.hcl
targets: rollups-node-ci
file: Dockerfile
context: .
target: go-tester
platforms: linux/amd64,linux/arm64
tags: ghcr.io/cartesi/rollups-node-test:${{steps.docker_meta.outputs.version}}
push: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
project: ${{ vars.DEPOT_PROJECT }}
workdir: build
token: ${{ secrets.DEPOT_TOKEN }}

- name: Export Image Tag
id : export_tag
run : echo "image_tag=${{steps.docker_meta.outputs.version}}" >> "$GITHUB_OUTPUT"

do-basic-checks:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -93,82 +119,37 @@ jobs:
docs/*.md
check-generated-files:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
container:
image: ghcr.io/cartesi/rollups-node-ci:${{needs.build-ci-base.outputs.output}}
image: ghcr.io/cartesi/rollups-node-test:${{needs.build-ci-base.outputs.output}}
needs:
- build-ci-base
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Fix VCS Issue
run : git config --global --add safe.directory /__w/rollups-node/rollups-node

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Check auto generated files
run: make check-generate

test-go:
runs-on: ubuntu-22.04
container:
image: ghcr.io/cartesi/rollups-node-ci:${{needs.build-ci-base.outputs.output}}
unit-test:
runs-on: ubuntu-24.04
needs:
- build-ci-base
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: depot/setup-action@v1
- name: Build dependency images
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
./docker-bake.override.hcl
./docker-bake.platforms.hcl
targets: |
rollups-node-devnet
rollups-node-snapshot
project: ${{ vars.DEPOT_PROJECT }}
workdir: build
load: true

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Fix VCS Go Linter Issue
run : git config --global --add safe.directory /__w/rollups-node/rollups-node

- name: Run Go Linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.58.2

- name: Run Go tests
- name: Run unit tests
env:
TESTCONTAINERS_RYUK_DISABLED: true
run: go test ./...
REPOSITORY: ghcr.io/
TAG: ${{needs.build-ci-base.outputs.output}}
CARTESI_POSTGRES_ENDPOINT: "postgres://postgres:password@database:5432/rollupsdb?sslmode=disable"
run: |
docker compose -f compose.yaml -f compose.override-tags.yaml run unit-test
build-docker:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs:
- do-basic-checks
- test-go
- unit-test
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Docker meta
id: docker_meta
Expand Down Expand Up @@ -197,22 +178,23 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- uses: depot/setup-action@v1
- name: Build and push docker image
id: docker_build
uses: depot/bake-action@v1

- name: Build and push node image
uses: depot/build-push-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
./docker-bake.platforms.hcl
targets: rollups-node
set: rollups-node.args.ROLLUPS_NODE_VERSION=${{ steps.docker_meta.outputs.version }}
file: Dockerfile
context: .
platforms: linux/amd64,linux/arm64
tags: ghcr.io/cartesi/rollups-node:${{steps.docker_meta.outputs.version}}
push: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
project: ${{ vars.DEPOT_PROJECT }}
workdir: build
token: ${{ secrets.DEPOT_TOKEN }}


release:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs:
- build-docker
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,49 @@ COPY --chown=cartesi:cartesi . ${GO_BUILD_PATH}/rollups-node/

RUN cd ${GO_BUILD_PATH}/rollups-node && make build-go

# =============================================================================
# STAGE: go-tester
#
# Gather the dependencies to run the unit-tests
# =============================================================================

FROM go-builder AS go-tester
WORKDIR ${GO_BUILD_PATH}/rollups-node

# fetch dependencies
RUN <<EOF
set -e
wget -nc -i test/dependencies -P /tmp
shasum -ca 256 test/dependencies.sha256
EOF

# install extra packages and machine-emulator runtime artifacts
USER root
ENV CARTESI_IMAGES_PATH=/usr/share/cartesi-machine/images/
RUN <<EOF
set -e
apt-get update
apt-get install -y --no-install-recommends \
git \
iproute2 \
jq \
postgresql-client
rm -rf /var/lib/apt/lists/*

mv /tmp/rootfs-tools-v0.16.1.ext2 ${CARTESI_IMAGES_PATH}rootfs.ext2
mv /tmp/linux-6.5.13-ctsi-1-v0.20.0.bin ${CARTESI_IMAGES_PATH}linux.bin
EOF

# deployment.json is required to run the tests
USER cartesi
RUN <<EOF
set -e
tar -zxf /tmp/rollups-contracts-2.0.0-rc.12-anvil-nightly-2044faec64f99a21f0e5f0094458a973612d0712.tar.gz -C /tmp/
jq -cf test/devnet/deployment.jq < /tmp/localhost.json > deployment.json
mv /tmp/state.json anvil_state.json
EOF
RUN make echo-dapp

# =============================================================================
# STAGE: rollups-node
#
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ generate: $(ROLLUPS_CONTRACTS_ABI_BASEDIR)/.stamp ## Generate the file that are

check-generate: generate ## Check whether the generated files are in sync
@echo "Checking differences on the repository..."
@if git diff --exit-code; then \
@if git diff --exit-code -- pkg/ internal/; then \
echo "No differences found."; \
else \
echo "ERROR: Differences found in the resulting files."; \
Expand Down
15 changes: 15 additions & 0 deletions compose.override-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# better control of tags
# ```
# export REPOSITORY=ghcr.io/
# export TAG=pr-001
# docker compose -f compose.yaml -f compose.unit-test.yaml run unit-test
# ```
services:
ethereum_provider:
image: ${REPOSITORY}cartesi/rollups-node-devnet:${TAG}
migration:
image: ${REPOSITORY}cartesi/rollups-node:${TAG}
node:
image: ${REPOSITORY}cartesi/rollups-node:${TAG}
unit-test:
image: ${REPOSITORY}cartesi/rollups-node-test:${TAG}
34 changes: 34 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ x-env: &env
services:
ethereum_provider:
image: cartesi/rollups-node-devnet:devel
build:
dockerfile: test/devnet/Dockerfile
networks:
- devnet
ports:
Expand Down Expand Up @@ -46,6 +48,8 @@ services:

node:
image: cartesi/rollups-node:devel
build:
dockerfile: Dockerfile
command: cartesi-rollups-node
depends_on:
database:
Expand All @@ -61,6 +65,36 @@ services:
environment:
<<: *env

# run the unit tests.
# ```
# docker compose -f compose.yaml run unit-test
# ```
unit-test:
image: cartesi/rollups-node-test:devel
profiles: [unit-test]
build:
dockerfile: Dockerfile
target: go-tester
entrypoint: ["sh", "-c"]
command: |
'
set -e
psql $CARTESI_POSTGRES_ENDPOINT -f test/postgres/drop-test-db.sql
psql $CARTESI_POSTGRES_ENDPOINT -f test/postgres/init-test-db.sql
make test
'
depends_on:
database:
condition: service_healthy
ethereum_provider:
condition: service_healthy
networks:
- devnet
restart: "no"
environment:
<<: *env
CARTESI_TEST_POSTGRES_ENDPOINT: postgres://postgres:password@database:5432/test_rollupsdb?sslmode=disable

volumes:
node_data:

Expand Down
2 changes: 2 additions & 0 deletions internal/advancer/machines/machines_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
package machines

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/service/address.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

// Implementation of the pflags Value interface.
package service

Expand Down
3 changes: 3 additions & 0 deletions pkg/service/log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

// Implementation of the pflags Value interface.
package service

Expand Down
3 changes: 3 additions & 0 deletions test/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/cartesi/image-kernel/releases/download/v0.20.0/linux-6.5.13-ctsi-1-v0.20.0.bin
https://github.com/cartesi/machine-emulator-tools/releases/download/v0.16.1/rootfs-tools-v0.16.1.ext2
https://github.com/cartesi/rollups-contracts/releases/download/v2.0.0-rc.12/rollups-contracts-2.0.0-rc.12-anvil-nightly-2044faec64f99a21f0e5f0094458a973612d0712.tar.gz
3 changes: 3 additions & 0 deletions test/dependencies.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
65dd100ff6204346ac2f50f772721358b5c1451450ceb39a154542ee27b4c947 /tmp/linux-6.5.13-ctsi-1-v0.20.0.bin
4db885fdb4f013922d8ea8474768148ac4d45460a4ef30aea823836ea72ffed9 /tmp/rootfs-tools-v0.16.1.ext2
691d229e16b866f97ee5cf27b88573d8434f064a959061c8755e91a048c2a811 /tmp/rollups-contracts-2.0.0-rc.12-anvil-nightly-2044faec64f99a21f0e5f0094458a973612d0712.tar.gz
9 changes: 1 addition & 8 deletions test/devnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ EOF

# Install anvil state file and devnet deployment info.
RUN mkdir -p ${DEVNET_BUILD_PATH}
RUN cat <<'EOF' > ${DEVNET_BUILD_PATH}/deployment.jq
. as $root | .contracts |
reduce to_entries[] as $c (
{"name": $root.name, "ChainId": $root.chainId | tonumber};
. + {($c.key): ($c.value.address)}
)
EOF

COPY test/devnet/deployment.jq ${DEVNET_BUILD_PATH}
RUN <<EOF
set -e
URL=https://github.com/cartesi/rollups-contracts/releases/download
Expand Down
Loading

0 comments on commit 9fea9ef

Please sign in to comment.