Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-2158] Create a docker image for starting the emojicoin_dot_fun local testnet for e2e testing locally and in CI #228

Merged
merged 45 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0748c0c
Remove anything but building the node in the local testnet Dockerfile
Aug 31, 2024
fb9566a
Initial try of using state, currently broken. I believe it's an issue…
Sep 2, 2024
c665689
Try to run the node and check the processor type in action
Sep 2, 2024
c8536f6
Add manual trigger workflow action
Sep 2, 2024
b59b2cd
[ECO-2158: fork] Merge fork CI tests into ECO-2158 (#232)
xbtmatt Sep 2, 2024
17238c3
Fix comment issue
Sep 2, 2024
57d7a85
Lint/format, cspell
Sep 2, 2024
8e9dd12
Fix yaml lint issues
Sep 2, 2024
9dccf97
Fix yaml lint error
Sep 2, 2024
1ad4409
Add the entrypoint with no force restart
Sep 2, 2024
20a9141
Add initial bash scripts to fund accounts, remove the pre-generated s…
Sep 4, 2024
7e077ef
Lint and format
Sep 4, 2024
85d2ee5
Use `aptos-labs/aptos-core/...get-latest-cli` action instead of makin…
xbtmatt Sep 4, 2024
01ecdfa
Format bash files
Sep 4, 2024
e52e5be
Remove unnecessary `action.yaml` in lieu of linking the public action…
Sep 4, 2024
1b3d03a
Rename remaining `_PK` instances to `_PRIVATE_KEY`
Sep 4, 2024
f568398
Use public action instead of duplicating it
xbtmatt Sep 4, 2024
c3523ae
Format script files better
Sep 5, 2024
9a8d272
[ECO-2168] Add back the local deployer service (#236)
xbtmatt Sep 5, 2024
abea696
* Update and explani skip fetch latest git deps in publish command
Sep 5, 2024
6196ccd
[EOC-2158 fork] Merge changes from fork to finalize image (#239)
xbtmatt Sep 6, 2024
60c6998
Remove continuation line
Sep 6, 2024
218eb04
Pre-commit, format, lint
Sep 6, 2024
5c62dbf
Remove redundant scripts
Sep 6, 2024
ad99022
Use full commit SHA for CLI action
Sep 6, 2024
1c52785
Rename image in yaml file
Sep 6, 2024
f90a720
Update comment, change name to `localnet`
Sep 6, 2024
ccaa57b
Get localnet test harness with docker compose working
Sep 7, 2024
d000530
Final naming conventions, format and lint
Sep 8, 2024
42aaba2
Fix typo, change `xbtmatt` to `econialabs`
Sep 8, 2024
83c65ec
Add README.md for the helper script
Sep 8, 2024
d3382b2
Update the GitHub workflow action
Sep 8, 2024
d679b60
Change `deployer` => `publisher`, was an accident
Sep 8, 2024
e607e6a
Remove ports because it's on host network
Sep 8, 2024
9904b16
Remove unused healthcheck script, since it's in the base image now
Sep 8, 2024
6a4197e
Rename project and container names to have `emojicoin-dot-fun` prefix
Sep 8, 2024
0df23a3
Use short container names.
Sep 8, 2024
1ff609d
Rename `localnet-publisher` to `deployer` to fix the huge whitespace …
Sep 8, 2024
f402882
Perfect the entire thing.
Sep 9, 2024
290c25b
Finish the script, lint and format
Sep 9, 2024
80cc210
Fix address equality check
Sep 9, 2024
01e3134
Update command in README
Sep 9, 2024
739170e
Move default entrypoint and healthcheck into `Dockerfile`
Sep 9, 2024
b82b7f4
Fix comments
Sep 9, 2024
eca46bb
Fix the workflow name, add a comment explaining what it's for
Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# cspell:word localnet
# Pushes the latest localnet deployer image to Dockerhub. This image handles
# the initialization of the emojicoin contract and test accounts for local
# feature/e2e tests and e2e tests in CI.
---
env:
PUBLISHER_PRIVATE_KEY: >-
0xeaa964d1353b075ac63b0c5a0c1e92aa93355be1402f6077581e37e2a846105e
jobs:
build-push:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v4'
- run: 'git submodule update --init --recursive src/rust/processor'
- id: 'metadata'
uses: 'docker/metadata-action@v5'
with:
images: 'econialabs/emojicoin-dot-fun-aptos-node'
images: 'econialabs/emojicoin-dot-fun-deployer'
tags: |
type=match,pattern=aptos-node-v(.*),group=1
type=match,pattern=emojicoin-dot-fun-deployer-v(.*),group=1
- uses: 'docker/setup-qemu-action@v3'
- uses: 'docker/setup-buildx-action@v3'
- uses: 'docker/login-action@v3'
Expand All @@ -19,18 +25,20 @@ jobs:
username: '${{ secrets.DOCKERHUB_USERNAME }}'
- uses: 'docker/build-push-action@v6'
with:
build-args: |
PUBLISHER_PRIVATE_KEY=${{ env.PUBLISHER_PRIVATE_KEY }}
cache-from: 'type=gha'
cache-to: 'type=gha,mode=max'
context: '.'
file: 'src/docker/aptos-node/Dockerfile'
file: 'src/docker/deployer/Dockerfile'
labels: '${{ steps.metadata.outputs.labels }}'
platforms: '${{ vars.DOCKER_IMAGE_PLATFORMS }}'
push: 'true'
tags: '${{ steps.metadata.outputs.tags }}'
timeout-minutes: 360
name: 'Build aptos-node Docker image and push to Docker Hub'
name: 'Build the deployer Docker image and push to Dockerhub'
'on':
push:
tags:
- 'aptos-node-v*'
- 'emojicoin-dot-fun-deployer*'
...
23 changes: 10 additions & 13 deletions .github/workflows/ts-run-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
---
env:
NEXT_PUBLIC_MODULE_ADDRESS: |-
4bab58978ec1b1bef032eeb285ad47a6a9b997d646c19b598c35f46b26ff9ece
PUBLISHER_PRIVATE_KEY: |-
29479e9e5fe47ba9a8af509dd6da1f907510bcf8917bfb19b7079d8c63c0b720
NEXT_PUBLIC_MODULE_ADDRESS: >-
0xf000d910b99722d201c6cf88eb7d1112b43475b9765b118f289b5d65d919000d
PUBLISHER_PRIVATE_KEY: >-
0xeaa964d1353b075ac63b0c5a0c1e92aa93355be1402f6077581e37e2a846105e
START_LOCAL_NODE_FOR_TEST: 'true'
TS_DIR: 'src/typescript'
jobs:
ts-run-tests:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3'
- uses: 'actions/checkout@v4'
with:
submodules: 'false'
- run: |
git submodule update --init --recursive src/inbox
cp src/inbox/example.env src/inbox/.env && \
docker buildx create \
--name=mybuilder \
--use \
--driver=docker-container
shell: 'bash'
- name: 'Install the latest Aptos CLI'
# yamllint disable-line rule:line-length
uses: 'aptos-labs/aptos-core/.github/actions/get-latest-cli@8792eefecd537c33fb879984635a0762838e2329'
with:
destination_directory: '/usr/local/bin'
- uses: './.github/actions/ts-run-tests'
name: 'Run the TypeScript E2E and unit tests with a local testnet'
'on':
Expand Down
61 changes: 60 additions & 1 deletion src/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- cspell:word localnet -->

# Running the emojicoin dot fun indexer with Docker

Ensure you've successfully pulled all submodule repositories required to
Expand All @@ -23,5 +25,62 @@ docker compose -f compose.yaml up
## Run a local Aptos fullnode as well

```shell
docker compose -f compose.yaml -f compose.local.yaml up
docker compose -f compose.local.yaml up
```

The `compose.local.yaml` file `include`s the `compose.yaml` file and
overwrites some settings like the order of dependencies for the services.

Note the order of the `include:` items in `compose.local.yaml` and where
the config overrides are placed.

## Running the frontend container

If you want to include the `frontend` container to run the frontend in a
`docker` container, without running a local testnet:

```shell
docker compose -f compose.yaml up --profile frontend
```

Note that the frontend is *not* included in the default services.

## Force restart the localnet

In order to simplify the pruning process for the localnet, you can simply run
the [prune.sh] script. It will remove all data, containers, and volumes in the
`emojicoin-dot-fun` project, including removing the local testnet data.

```shell
# Ensure you're in the right directory:
cd src/docker/utils

# With a prompt for removal:
./prune.sh

# To skip the prompt, run any of these:
./prune.sh -y
./prune.sh --yes
./prune.sh -r
./prune.sh --reset-localnet
```

### Why not just pass `--force-restart`?

The CLI simply uses a directory for all localnet test data. By default it's
located at `~/.aptos/testnet`. Since it's not a mounted volume, it is ephemeral
and will be removed on each container restart. This is very unintuitive behavior
that results in corrupt indexer data each time you restart the `localnet`
container unless you explicitly prune the database volumes.

To fix this, the data directory in the container is created as a bind-mount to
the host's `localnet/.aptos` folder, making the data persist between container
restarts.

However, if you try to force restart the node in its entrypoint command with
`--force-restart`, you'll get a `Device or resource busy` error. Since
there's no reason we need to run `--force-restart` at runtime, the best way to
handle a restart is by removing the localnet test data directory prior to each
run as well as pruning all the related volumes, which is what [prune.sh] does.

[prune.sh]: ./utils/prune.sh
60 changes: 0 additions & 60 deletions src/docker/aptos-node/Dockerfile

This file was deleted.

55 changes: 0 additions & 55 deletions src/docker/aptos-node/initialize-contract.sh

This file was deleted.

9 changes: 0 additions & 9 deletions src/docker/aptos-node/run-fullnode.sh

This file was deleted.

61 changes: 29 additions & 32 deletions src/docker/compose.local.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
# yamllint disable rule:empty-lines rule:key-ordering rule:brackets
# yamllint disable rule:empty-lines rule:key-ordering
# cspell:word localnet

# Services in this file are EXCLUSIVELY for running a local testnet.
---
include:
# This setup allows us to only have to specify only one compose file.
- path:
- 'compose.yaml'
- 'processor.overrides.yaml'
name: 'emojicoin-dot-fun'
services:
aptos-node:
localnet:
network_mode: 'host'
container_name: 'localnet'
build:
context: '../../'
dockerfile: 'src/docker/aptos-node/Dockerfile'
ports:
- '50051:50051'
- '8070:8070'
- '8090:8090'
- '8080:8080'
- '8081:8081'
dockerfile: 'src/docker/localnet/Dockerfile'
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:8070/']
interval: '30s'
timeout: '10s'
test:
- 'CMD'
- 'sh/healthcheck.sh'
interval: '5s'
xbtmatt marked this conversation as resolved.
Show resolved Hide resolved
timeout: '5s'
retries: 5
start_period: '30s'
command: ['bash', '/app/run-fullnode.sh']
# In order to start the node with the indexer API; i.e., run
# `aptos node run-local-testnet --with-indexer-api`, the Docker socket must
# be mounted to the container. This mount enables the container to start a
# new container. Note that this is *not* "Docker-in-Docker", but rather
# "Docker-outside-Docker". That is, the container can act as the host in
# terms of creating and orchestrating other containers but still appears as
# a sibling to the existing containers and any new containers it creates.
entrypoint:
- '/bin/bash'
- '/app/sh/run-localnet.sh'
volumes:
xbtmatt marked this conversation as resolved.
Show resolved Hide resolved
- '/var/run/docker.sock:/var/run/docker.sock'

move:
- './localnet/.aptos/testnet:/app/.aptos/testnet'
deployer:
extra_hosts:
- 'host.docker.internal:host-gateway'
build:
context: '../../'
dockerfile: 'src/docker/aptos-node/Dockerfile'
dockerfile: 'src/docker/deployer/Dockerfile'
args:
PUBLISHER_PRIVATE_KEY: '${PUBLISHER_PRIVATE_KEY}'
environment:
PUBLISHER_PRIVATE_KEY: '${PUBLISHER_PRIVATE_KEY}'
BIG_MONEY_GUY_PRIVATE_KEY: '${BIG_MONEY_GUY_PRIVATE_KEY}'
EMOJICOIN_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}'
image: 'econialabs/emojicoin-dot-fun-deployer:latest'
container_name: 'deployer'
depends_on:
aptos-node:
localnet:
condition: 'service_healthy'
command: ['bash', '/app/initialize-contract.sh']

processor:
depends_on:
move:
condition: 'service_completed_successfully'
...
Loading
Loading