Skip to content

Commit

Permalink
fixed initialized file and added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Apr 12, 2024
1 parent cb56e48 commit 155d70c
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 2 deletions.
44 changes: 44 additions & 0 deletions containers/alpine/Containerfile
Original file line number Diff line number Diff line change
@@ -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"]
79 changes: 79 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 4 additions & 2 deletions src/box/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Empty file added tools/download-binaries.lua
Empty file.

0 comments on commit 155d70c

Please sign in to comment.