diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..6ee8d70f --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +# Use the base image from the provided Docker command +FROM mudassirshabbir/dab:mc3 + +# Expose the ports as specified in the docker run command +EXPOSE 26656 +EXPOSE 26657 +EXPOSE 1317 +EXPOSE 5173 + +# Set the NODE_PATH environment variable +ENV NODE_PATH=/usr/src/cache +# Set the entrypoint or command if necessary (adjust as needed) +ENTRYPOINT ["/bin/bash -c"] + +CMD "/bin/bash -c" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 18e4d42e..72507dbb 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,10 +1,20 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node { - "name": "Node.js", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bookworm", - + "name": "Node+GH+DinD", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + "runArgs": [ + "--privileged", + "--platform", "linux/amd64" + ], + "workspaceFolder": "/workspace", + "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached", + "mounts": [ + "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" + ], // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [5173, 1317, 26657, 26656], "portsAttributes": { @@ -26,10 +36,12 @@ } }, // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "bash /workspaces/dapp-agoric-basics/make_ports_public.sh 26657 5173 1317", - "postStartCommand": "yarn install", - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {}, - "ghcr.io/devcontainers/features/github-cli:1": {} - } + "postCreateCommand": "/bin/bash /workspaces/dapp-agoric-basics/entrypoint.sh" + // "postCreateCommand": "bash /workspaces/dapp-agoric-basics/make_ports_public.sh 26657 5173 1317", + // "features": { + // "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + // "ghcr.io/devcontainers/features/github-cli:1": {} + // }, + // // TODO: The image address in the line below needs to be updated + // "postStartCommand": "yarn install && docker run -d -v '.:/workspace' --platform linux/amd64 -p 26656:26656 -p 26657:26657 -p 1317:1317 mudassirshabbir/agoric:mc2 && yarn start:ui" } diff --git a/README-GHCS.md b/README-GHCS.md new file mode 100644 index 00000000..39a1b741 --- /dev/null +++ b/README-GHCS.md @@ -0,0 +1,74 @@ +# Running `dapp-agoric-basics` on GHCS + +This README outlines the instructions, directions, and steps currently being followed in this PR to make the experience of using GHCS more efficient. For the most part the instructions in the original README should work in this PR as well. However, the ultimate goal is to have a dApp running in a chain with a UI without having to follow any of those steps. This is currently achievable but it takes time and we want to reduce this wait time as much as possible. + +## Important Steps + +- A Dockerfile is introduced in `.devcontainer` directory that loads an image `mudassirshabbir/dab:mc3`. This image contains a linux system with node version `18.20`, GitHub CLI, Docker CLI, and current `dapp-agoric-basics` repo with `yarn install` already baked. +- `dapp-agoric-basics` repo with `yarn install` is baked in `/usr/src/cache`. +- The Dockerfile is already configured in `devcontainer.json` file that is read by GHCS. +- Currently docker is loaded in `--privileged` mode mainly because we want to run docker-in-docker for chain using following `mount`: +```Dockerfile +"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" +``` +- There is an `entrypoint.sh` script that is used to copy the installed `node_modules` to the current workspaces that is mounted on `/workspace`. +- Instead of running `yarn start:docker` followed by `yarn start:contract`, we have created a docker image of the chain (`a3p`) with contract already deployed on it. +```sh +docker run -d -v ".:/workspace" mudassirshabbir/a3p:dab +``` +This saves us about five minutes on average. Once done, we can simply run `yarn start:ui` and we are good to go. + +## What Does Not Work at This Point + +Currently, we need to perform `yarn install` manually. The work to bake it in first docker iamge is unfinished. The `/usr/src/cache` version of the repo has all the modules but copying it to `/workspace` does not provide intended results. + +Below are some of the instructions that be needed to resume the task from here. + +## Docker `dab:mc3` Image Construction + +Docker image construction is done through `docker commit` command. The following instructions are needed to be run to create the first docker image: + +```sh +docker run --privileged -it -v ".:/workspace" -v /var/run/docker.sock:/var/run/docker.sock --platform linux/amd64 -p 26656:26656 -p 26657:26657 -p 1317:1317 node:18.20 /bin/bash + +# Update package list and install dependencies +apt-get update +apt-get install -y curl + +# Download and install GitHub CLI +curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg +chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null +apt-get update +apt-get install -y gh + +# Install Docker +apt-get update +apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release + +# Add Docker’s official GPG key +curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg + +# Set up the stable repository +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + +# Install Docker Engine +apt-get update +apt-get install -y docker-ce docker-ce-cli containerd.io + +# Enable Docker daemon +dockerd & +``` + +```sh +mkdir /usr/src/cache +cd /usr/src/cache +cp -r /workspace/* ./ +yarn install +``` + +After this point, I use `docker commit` to create an image. + +## Docker `a3p:dab` Image Construction + +This is done through straightforward `yarn start:docker`, `yarn start:contract`, followed by a `docker commit`. This can be automated through `compose` and/or `buid` but currently there is no need. \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..14f3173b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -x +cp -r /usr/src/cache/node_modules /workspaces/dapp-agoric-basics/ +/workspaces/dapp-agoric-basics/make_ports_public.sh 5173 1317 26657 26656 +# exec /bin/bash \ No newline at end of file