Skip to content

Commit

Permalink
[ECO-2158] Create a docker image for starting the emojicoin_dot_fun
Browse files Browse the repository at this point in the history
… local testnet for e2e testing locally and in CI (#228)

Co-authored-by: matt <[email protected]>
Co-authored-by: alnoki <[email protected]>
  • Loading branch information
3 people authored Sep 9, 2024
1 parent 5bae3a4 commit cc2edb3
Show file tree
Hide file tree
Showing 25 changed files with 1,769 additions and 228 deletions.
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'
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:
- '/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

0 comments on commit cc2edb3

Please sign in to comment.