Skip to content

Commit

Permalink
[BLOCK-1803] - Docker documentation pages update (#82)
Browse files Browse the repository at this point in the history
* BLOCK-1803 - Moved protocol tools to a dedicated section. Updated docker guide pages

* BLOCK-1803 - Replace docker guide references to smart contract build references
  • Loading branch information
igor-sikachyna authored Sep 28, 2023
1 parent 07abcf4 commit bacab64
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 132 deletions.
2 changes: 1 addition & 1 deletion docs/contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ deploy: ['staging', 'mainnet']

If you are looking to learn about the Smart Contracts deployed by Ultra.io, this is it.

If you are looking for information about [writing your own smart contract, follow this link.](../guides/Docker/building-smart-contracts.md)
If you are looking for information about [writing your own smart contract, follow this link.](../guides/Smart%20Contracts/1.index.md)
12 changes: 7 additions & 5 deletions docs/guides/Docker/development-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ outline: [0,4]

# Development Environment Setup

To start the setup process you'll need to clone [development tools](https://github.com/ultraio/blockchain-development-tools/) repo from Github.
Most convinent way to interact with a docker container and manage the files inside it is by using VSCode

## Local

For the local environment you just open `~/ultra_workdir` if you're on linux or `C:\Users\Username\ultra_workdir` on windows.
For the local environment you just open `~/ultra_workdir` if you're on Linux or `C:\Users\Username\ultra_workdir` on Windows using VSCode. You can write all the tests and smart contract code locally. Then if you want to build and test use one of the following pathways:
- [VSCode extension](../../tools/smart-contract-toolkit/index.md)
- [Run build commands in docker](./docker-contract-development-flow.md)

## Docker

Run `./scripts/docker/start_docker.sh` from the development tools.
It'll start a container called `ultra-dev` to which you can connect using vscode.
Run the [docker start command](./docker-image-usage.md#running-the-image).
It'll start a container called `ultra` to which you can connect using VSCode.
By default your `ultra-workdir` is mounted to the `/opt/ultra_workdir` directory inside
the container so any changes in that directory will persist on your filesystem.
Go to the `Remote-Explorer` and attach to the `ultra-dev` container.
Go to the `Remote-Explorer` and attach to the `ultra` container.

![](/images/vscode-attach-to-container.png)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: 'Building Smart Contracts'
title: 'Docker Contract Development Flow'
deploy: ['staging', 'mainnet']
order: -9990
outline: [0,4]
prev: false
---

# Building Smart Contracts
# Docker Contract Development Flow

A smart contract is written in C++ but compiled into WASM.

Expand Down Expand Up @@ -130,8 +130,8 @@ Three files should be created in the `hello` directory.

After compiling the smart contract there are two options for deployment in the local development environment.

- [Deploy with 'ultratest' framework](./ultratest.md)
- ['cleos' based contract deployment](./cleos.md#deploying-a-smart-contract)
- [Deploy with 'ultratest' framework](../../tools/ultratest/ultratest.md)
- ['cleos' based contract deployment](../../tools/protocol/cleos.md#deploying-a-smart-contract)

## CMake

Expand Down Expand Up @@ -169,19 +169,19 @@ Obtain the following files from [the following markdown page](../../examples/eos
|- eosio.token.cpp
```

### Building with the Wrapper Script
### Building using CMakeLists.txt

Inside of the docker image there is a script called `build_contracts` which can be ran from anywhere inside of the docker image.

This script will create a build folder and put build artifacts (wasm and abi files) in the folder.

Run the following command in any folder.
After preparing all the smart contract files and CMakeLists.txt you should be able to proceed with building the contract using the following commands:

```sh
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ../
make
```
build_contracts
```

If everything is setup correctly the script will automatically tap into the `CMakeLists.txt` and build your contract.
If you want to rebuild the contract you can either run the `make` command in the `build` directory again or delete the `build` directory and perform the commands above again

If everything is setup correctly the commands will use the `CMakeLists.txt` and build your contract.

![](/images/vscode-eosio-token-contract-build.png)

Expand Down
22 changes: 18 additions & 4 deletions docs/guides/Docker/docker-image-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ We currently support Docker for a majority of our development needs as it allows
### Running the Image

```sh
docker run -dit --name ultra -p 8888:8888 -p 9876:9876 image_name:tag_name
docker run -dit --name ultra -p 8888:8888 -p 9876:9876 -v ~/ultra/ultra_workdir:/opt/ultra_workdir --name ultra quay.io/ultra.io/3rdparty-devtools:latest
```

* -d
Expand All @@ -31,15 +31,29 @@ docker run -dit --name ultra -p 8888:8888 -p 9876:9876 image_name:tag_name
* Allocate a pseudo-TTY
* -p \[ HostPort:ContainerPort \]
* A port range to expose for the Container
* Port 8888 used as an HTTP port by `nodeos`
* Port 9876 is used as P2P connection port by `nodeos`
* -v \[ HostPath:GuestPath \]
* Attaches a directory from your host machine to the docker container

### Getting in the Image

If the above container name is `ultra` then the following can be used to access the Docker Container.
If the above container name is kept as `ultra` then the following can be used to access the Docker Container.

```
docker attach ultra
docker start ultra && docker attach ultra
```

### Persisting container between runs

If you stick to commands specified under the `Docker` section of guides you should have your Docker container persist between runs. Commands such as `docker start` and `docker attach` will not destroy your existing container. Running the `docker run` command again with the same `ultra` container name will also not overwrite your container but instead will fail

Commands that may potentially remove your container (and erase the data inside it are): `docker rm`, `docker prune`. Please be sure to avoid them if you are concerned with your data being removed.

::: warning
When container is removed all changes you've done inside it will be erased. Because of that please ensure that your `ultra_workdir` is mounted to the container and move any files you want to keep to this `ultra_workdir`.
:::

## Available Binaries

Binaries available inside of the Docker Image
Expand All @@ -49,5 +63,5 @@ Binaries available inside of the Docker Image
* keosd
* ultratest

_All "eosio" based binaries can be found in `/usr/op/eosio/<SOME_VERSION>/bin`_
_All "eosio" based binaries can be found in `/usr/opt/eosio/<SOME_VERSION>/bin`_

6 changes: 3 additions & 3 deletions docs/guides/Docker/endpoint-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ In many cases when working with smart contracts, or on-chain actions you will ne

## Cleos Usage

Cleos has a section on using [external endpoints](./cleos.md#external-apis).
Cleos has a section on using [external endpoints](../../tools/protocol/cleos.md#external-apis).

In short append the `-u` flag with a url.
In short append the `-u` flag with a url. If you are using local environment then this flag can be skipped. The default value of `http://127.0.0.1:8888` will be used

```
cleos -u <endpoint>
Expand All @@ -24,7 +24,7 @@ cleos -u <endpoint>
cUrl can be used normally but suggested to use `json_pp` to help prettify the output from a cUrl response.

```
curl <endpoint>/v1/chain/get_info
curl -X POST <endpoint>/v1/chain/get_info
```

## wget Usage
Expand Down
55 changes: 0 additions & 55 deletions docs/guides/Docker/environments.md

This file was deleted.

47 changes: 23 additions & 24 deletions docs/guides/Docker/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ The goal of this document is to get a development environment setup in as little
- [Docker for Linux](https://docs.docker.com/engine/install/ubuntu/)
- [Git for Windows / Linux](https://git-scm.com/)
- Ensure that you install Git Bash
- [Clone Ultra Blockchain Dev Tools](https://github.com/ultraio/blockchain-development-tools)

## Obtaining the Docker Image

Expand All @@ -29,38 +28,30 @@ _The above image tag may be out of date. Visit [our official quay.io repository]

## Starting / Stopping Image

Inside of the `blockchain-development-tools` directory run the following command to start the image.
Open your terminal (on Windows use `Git Bash`) and use the following command to create development tools container

```sh
./scripts/docker/start_docker.sh
docker run -dit --name ultra -p 8888:8888 -p 9876:9876 -v ~/ultra/ultra_workdir:/opt/ultra_workdir --name ultra quay.io/ultra.io/3rdparty-devtools:latest
```

Alternatively you can optionally specify a full docker image URL with a tag:
::: warning
The above command will utilize ports 8888 and 9876. If those ports are occupied the docker will fail to create the container. You will have an option to change which ports will be used on your host machine later.
:::

```sh
./scripts/docker/start_docker.sh quay.io/ultra.io/3rdparty-devtools:0.1.1
```
After you created the container you realistically won't need to create it again. Existing container will be accessible under the name of `ultra`.

To stop existing development docker instance use the stop script
To stop the container without destroying it you can use the following command

```sh
./scripts/docker/stop_docker.sh
docker stop ultra
```

## Accessing the Image

If the `start_docker` script does not attach automatically you can use the following command to get access inside the container.

**Linux**
After you created the container you will be able to attach to it using the following command. It will also start the container if it is currently stopped (for Windows keep in mind to use `Git Bash` still).

```sh
docker exec -it ultra-dev-environment bash
```

**Windows**

```sh
winpty docker exec -it ultra-dev-environment bash
docker start ultra && docker attach ultra
```

## Accessing Docker Volume
Expand All @@ -76,6 +67,8 @@ The docker container has a shared directory located somewhere in your operating
## Creating a Smart Contract

Create a directory in the `ultra_workdir` directory called `contracts` with a file inside called `hello.cpp`.
- You can do it either on your host machine (Windows/Linux) or inside the docker image using your editor of choice (`nano` is preinstalled, other editors require manual installation)
- You also have an option to use [VSCode Environment](./development-environment.md)

```cpp
#include <eosio/eosio.hpp>
Expand All @@ -95,10 +88,10 @@ class [[eosio::contract]] hello : public eosio::contract {

### Compiling a Smart Contract

Inside of the docker image navigate into the `contracts` directory, and run the following command.
Inside of the docker image (using the terminal that is attached to the `ultra` container) navigate into the `contracts` directory, and run the following command.

```
cd /opt/ultra_workdir/contracts
mkdir -p /opt/ultra_workdir/contracts && cd /opt/ultra_workdir/contracts
```
<Mainnet>

Expand Down Expand Up @@ -143,7 +136,9 @@ This directory structure should be reflected inside of the docker image.

### Write Tests

Test files are written in JavaScript and must have `ultra_test.js` suffix.
Test files are written in JavaScript and must have `ultra_test.js` suffix (e.g. `hello.ultra_test.js`).

Now try adding the following code snippet to `hello.ultra_test.js`. You should place the file `ultra_workdir/tests` directory like the file tree in the section above suggests

```js
module.exports = class test {
Expand Down Expand Up @@ -201,7 +196,11 @@ cd /opt/ultra_workdir
```

```
ultratest -D
ultratest
```

If you are experiencing issues with deployment try appending `-P` as a parameter.
If you did everything properly you should see the test line stating `All Tests Passed`

::: info
If the test run fails or gets stuck you can kill it using the ^C (Ctrl + C) termination command.
:::
7 changes: 1 addition & 6 deletions docs/guides/Docker/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ This section highlights the tools provided inside of a Docker image.
- [Getting Started](./getting-started.md)
- [Setup a Development Environment](./development-environment.md)
- [Docker Image Usage](./docker-image-usage.md)
- [Nodeos Usage](./nodeos.md)
- [Cleos Usage](./cleos.md)
- [Keosd Usage](./keosd.md)
- [ultratest usage](./ultratest.md)
- [Endpoint Usage](./endpoint-usage.md)
- [Environments](./environments.md)
- [Building Smart Contracts](./building-smart-contracts.md)
- [Docker Contract Development Flow](./docker-contract-development-flow.md)
- [Obtaining Tokens Locally](./obtaining-tokens-locally.md)
- [Troubleshooting Docker Image](./troubleshooting.md)
6 changes: 3 additions & 3 deletions docs/guides/Docker/obtaining-tokens-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ outline: [0,4]

Tokens can be obtained in one of two ways in the **local environment**.

The first way involves obtaining tokens in a unit test, check the [ultratest](./ultratest.md#adduos) documentation for more information.
The first way involves obtaining tokens in a unit test, check the [ultratest](../../tools/ultratest/ultratest.md#adduos) documentation for more information.

The second way involves an `ultratest` no test instance and `cleos`.

## Before the Transfer Action

You should be inside of the docker image.

You should have [ultratest running in a no-tests instance](./ultratest.md#starting-a-system-node).
You should have [ultratest running in a no-tests instance](../../tools/ultratest/ultratest.md#starting-a-system-node).

Make sure you have [created an account locally](./cleos.md#creating-an-account) before running the following command.
Make sure you have [created an account locally](../../tools/protocol/cleos.md#creating-an-account) before running the following command.

## The Transfer Action

Expand Down
Loading

0 comments on commit bacab64

Please sign in to comment.