From 155d70ccfa53f298ffdf094f3d6fd5fa5097ff58 Mon Sep 17 00:00:00 2001 From: cryi Date: Fri, 12 Apr 2024 22:53:58 +0200 Subject: [PATCH] fixed initialized file and added readme --- containers/alpine/Containerfile | 44 ++++++++++++++++++ readme.md | 79 +++++++++++++++++++++++++++++++++ src/box/core.lua | 6 ++- tools/download-binaries.lua | 0 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 containers/alpine/Containerfile create mode 100644 readme.md create mode 100644 tools/download-binaries.lua diff --git a/containers/alpine/Containerfile b/containers/alpine/Containerfile new file mode 100644 index 0000000..a5646d8 --- /dev/null +++ b/containers/alpine/Containerfile @@ -0,0 +1,44 @@ +ARG IMAGE_TAG=latest + +FROM docker.io/alpine:${IMAGE_TAG} + +ARG TEZOS_VERSION=19.1 +ARG PROTOCOLS=oxfordbox + +ENV ASCEND_SERVICES=/ascend/services +ENV ASCEND_HEALTHCHECKS=/ascend/healthchecks +ENV ASCEND_SOCKET=/var/run/ascend.socket +ENV ASCEND_LOGS=/var/log/ascend +ENV ASCEND_INIT="tezbox init --setup-services" +ENV TEZBOX_USER=tezos + +RUN adduser -D -H -s /sbin/nologin -G nogroup -g 'Tezos User' ${TEZBOX_USER} + +RUN printf '#!/bin/sh\n\ +if [ -z "$GITHUB_TOKEN" ]; then\n\ + wget "$@" \n\ +else\n\ + wget --header "Authorization: token $GITHUB_TOKEN" "$@" \n\ +fi\n' > /usr/local/bin/auth_wget && chmod +x /usr/local/bin/auth_wget + +# Use auth_wget for downloading files with optional authentication +RUN auth_wget https://raw.githubusercontent.com/alis-is/ascend/main/tools/setup/standalone-linux.sh -O /tmp/setup-ascend.sh && sh /tmp/setup-ascend.sh --prerelease + +RUN mkdir -p /tezbox /tezbox/configuration /tezbox/overrides /tezbox/overrides/context +COPY configuration /tezbox/configuration +RUN chown -R tezos:tezos /tezbox + +COPY bin/tezbox /usr/local/bin/tezbox +RUN chmod +x /usr/local/bin/tezbox +RUN chown -R tezos:nogroup /usr/local/bin/tezbox + +ENV PROTOCOLS=${PROTOCOLS} +RUN echo $PROTOCOLS +ADD tools/cleanup-protocols.lua /tmp/cleanup-protocols.lua +RUN eli /tmp/cleanup-protocols.lua && rm /tmp/cleanup-protocols.lua +ADD tools/download-binaries.lua /tmp/cleanup-protocols.lua +RUN eli /tmp/download-binaries.lua && rm /tmp/download-binaries.lua + +USER root +ENTRYPOINT [ "ascend" ] +CMD ["oxfordbox"] \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..ed87b9d --- /dev/null +++ b/readme.md @@ -0,0 +1,79 @@ +## TEZBOX - tezos sandbox by tez.capital + +### What is TezBox? + +TezBox is a tezos sandbox that allows you to run a minimal local tezos chain with a single command. It is designed to be a simple and easy to use tool for developers who want to quickly test their smart contracts or dapps on a local tezos chain. + +### How to use TezBox? + +To use TezBox, you need to have OCI compatible container runtime installed on your machine (e.g. docker, podman...). You can run TezBox with the following command: + +```bash +# to run chain with the O protocol +docker run -it -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v19.1 oxfordbox + +# to run chain with the P protocol +docker run -it -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v20.0-rc1 parisbox +``` + +### Configuration + +All configuration files are located in the `/tezbox/configuration` directory and merged with overrides from `/tezbox/overrides` directory. You can either mount directly configuration files or user overrides which are merged with the files from the configuration directory. The merge is performed as deep merge with overwrite. Arrays are **NOT** concatenated, but replaced with the value from the overrides. Actual configuration used during the run is located in `/tezbox/context` and is a result of the merge of all configuration files created during the initialization of the container. + +NOTE: *It is not possible to define bootstrap_accounts through sandbox-parameters. Use `.../configuration/bakers.hjson` instead.* + +#### Accounts + +By default tezbox comes with these accounts: +```yaml +{ + alice: { + pkh: tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb + pk: edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn + sk: unencrypted:edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq + balance: 2000000 + } + bob: { + pkh: tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6 + pk: edpkurPsQ8eUApnLUJ9ZPDvu98E8VNj4KtJa1aZr16Cr5ow5VHKnz4 + sk: unencrypted:edsk3RFfvaFaxbHx8BMtEW1rKQcPtDML3LXjNqMNLCzC3wLC1bWbAt + balance: 2000000 + } +} +``` +You can add modify as needed. Just mount your own file to `/tezbox/overrides/accounts.hjson` for override or `/tezbox/configuration/accounts.hjson` for full replacement. + +#### Chain Context + +Chain and protocol is automatically initialized only once during the first run. The chain and all runtime data are stored in `/tezbox/data` directory. If you want to persist your sandbox state just run it with mounted volume to `/tezbox/data` directory. + +e.g. +```bash +docker run -it -v $(pwd)/sandbox-data:/tezbox -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v19.1 oxfordbox +``` + +NOTE: *To reset the state you can remove the `/tezbox/data/tezbox-initialized` file. After its removal all chain and client data will be removed and the chain will be reinitialized on the next run.* + +#### Flextesa Compatibility + +To maintain some level of compatibility with flextesa, the alice and bob accounts are the same. The RPC port is exposed on ports 8732 and 20000. And we use similar protocol aliases like oxfordbox and parisbox. + +But unlike flextesa the tezbox won't expose configuration through command line arguments. Instead, you can edit configuration directly in the configuration files or use overrides. + +### Building TezBox + +To build TezBox follow these steps: + +1. clone the repository + - `git clone https://github.com/tez-capital/tezbox && cd tezbox` +2. edit the Dockerfile, configuration and sources if needed +3. build lua sources (you can get eli [here](https://github.com/alis-is/eli/releases)) + - `eli build/build.lua` +4. build the image + - `docker build --build-arg="PROTOCOLS=Proxford,PtParisB" --build-arg="IMAGE_TAG=octez-v20.0-rc1" -t tezbox . -f containers/tezos/Containerfile --no-cache` + +### Future development + +TezBox is going to follow official tezos releases and tag. You can expect new release shortly after the official release of the new tezos version. + +We would like to introduce tezbox minimal image with only the tezos node, baker, client and the minimal configuration eventually. But there is no ETA for this feature yet. \ No newline at end of file diff --git a/src/box/core.lua b/src/box/core.lua index cb2d7df..01d2840 100644 --- a/src/box/core.lua +++ b/src/box/core.lua @@ -92,7 +92,9 @@ function core.initialize(protocol, options) if type(options) ~= "table" then options = {} end protocol = string.lower(protocol) - local ok, initializedProtocol = fs.safe_read_file(path.combine(env.tezboxDirectory, "tezbox-initialized")) + local initializedProtocolFilePath = path.combine(env.homeDirectory, "tezbox-initialized") + + local ok, initializedProtocol = fs.safe_read_file(initializedProtocolFilePath) if ok then if initializedProtocol == protocol then @@ -215,7 +217,7 @@ function core.initialize(protocol, options) end -- finalize - fs.write_file("tezbox-initialized", protocol) + fs.write_file(initializedProtocolFilePath, protocol) end function core.run() diff --git a/tools/download-binaries.lua b/tools/download-binaries.lua new file mode 100644 index 0000000..e69de29