Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate Ninja projects here #1110

Merged
merged 38 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0bbe473
Motoko hello world - remove ninja-specific parts
sesi200 Mar 18, 2025
9a5cffe
rust Hello World
sesi200 Mar 18, 2025
6b4c3cd
update BUILD.md
sesi200 Mar 18, 2025
b79240f
add candid-extractor to CI
sesi200 Mar 18, 2025
ef0115f
fix rust/parallel_calls
sesi200 Mar 18, 2025
cc8cd66
...again
sesi200 Mar 18, 2025
a6c0549
Update motoko/hello_world/backend/app.mo
sesi200 Mar 18, 2025
b60c947
add open-in-ninja button to readmes
sesi200 Mar 19, 2025
34f18a2
add rust/flying_ninja
sesi200 Mar 19, 2025
d16f8e9
add motoko/flying_ninja
sesi200 Mar 19, 2025
d8006e9
add motoko/llm_chatbot
sesi200 Mar 19, 2025
2ad230c
add mops to setup
sesi200 Mar 19, 2025
69e878b
add rust/llm_chatbot
sesi200 Mar 19, 2025
8e3f2c8
add motoko/daily_planner
sesi200 Mar 19, 2025
c8b8a4d
add rust/daily_planner
sesi200 Mar 19, 2025
ddd6681
candid formatting
sesi200 Mar 19, 2025
c2d0b37
add motoko/backend_only
sesi200 Mar 19, 2025
078ac16
add rust/backend_only
sesi200 Mar 19, 2025
513c076
fix backend_only
sesi200 Mar 19, 2025
9183c95
add rust/evm_block_explorer
sesi200 Mar 20, 2025
81dee2d
add motoko/evm_block_explorre
sesi200 Mar 20, 2025
850d304
forgot Makefile
sesi200 Mar 20, 2025
b637550
add motoko/filevault
sesi200 Mar 20, 2025
4b7a223
add motoko/tokenmania
sesi200 Mar 20, 2025
578b525
add rust/tokenmania
sesi200 Mar 20, 2025
77141ea
add hosting/react
sesi200 Mar 20, 2025
ee0b8bb
hosting/my_crypto_blog
sesi200 Mar 20, 2025
6fc8355
add rust/motoko who_am_i
sesi200 Mar 20, 2025
8d5054a
update codeowners
sesi200 Mar 21, 2025
70a094d
move to one .yml file for multiple examples
sesi200 Mar 21, 2025
9c51a2b
target correct branch
sesi200 Mar 21, 2025
186e585
fix matrix definition
sesi200 Mar 21, 2025
33113d5
provision linux container
sesi200 Mar 21, 2025
716de6b
skip bare ubuntu
sesi200 Mar 21, 2025
97fd3de
revert provision script changes
sesi200 Mar 21, 2025
9d95b29
skip npm i
sesi200 Mar 21, 2025
698e418
Merge branch 'master' into severin/consolidate-ninja-projects
sesi200 Mar 24, 2025
e560645
revert rust/parallel_calls to be able to merge
sesi200 Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 19 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@
/c/reverse/ @dfinity/growth

/hosting/godot-html5-template/ @dfinity/sdk
/hosting/my_crypto_blog/ @dfinity/ninja-devs
/hosting/photo-storage/ @dfinity/sdk
/hosting/react/ @dfinity/ninja-devs
/hosting/static-website/ @dfinity/sdk
/hosting/unity-webgl-template/ @dfinity/sdk

/motoko/basic_bitcoin/ @dfinity/execution
/motoko/basic_dao/ @dfinity/languages
/motoko/backend_only/ @dfinity/ninja-devs
/motoko/canister_logs/ @dfinity/execution
/motoko/cert-var/ @dfinity/trust
/motoko/classes/ @dfinity/languages
/motoko/composite_query/ @dfinity/languages
/motoko/counter/ @dfinity/languages
/motoko/daily_planner/ @dfinity/ninja-devs
/motoko/encrypted-notes-dapp-vetkd/ @dfinity/crypto-team
/motoko/encrypted-notes-dapp/ @dfinity/crypto-team
/motoko/evm_block_explorer/ @dfinity/ninja-devs
/motoko/filevault/ @dfinity/ninja-devs
/motoko/flying_ninja/ @dfinity/ninja-devs
/motoko/hello_cycles/ @dfinity/languages
/motoko/hello_world/ @dfinity/ninja-devs
/motoko/ic-pos/ @dfinity/growth
/motoko/icp_transfer/ @dfinity/growth
/motoko/icrc2-swap/ @dfinity/growth
/motoko/internet_identity_integration/ @dfinity/identity
/motoko/life/ @dfinity/languages
/motoko/llm_chatbot/ @dfinity/ninja-devs
/motoko/minimal-counter-dapp/ @dfinity/growth
/motoko/parallel_calls/ @dfinity/languages
/motoko/pub-sub/ @dfinity/growth
Expand All @@ -34,32 +43,39 @@
/motoko/superheroes/ @dfinity/growth
/motoko/threshold-ecdsa/ @dfinity/crypto-team
/motoko/threshold-schnorr/ @dfinity/crypto-team
/motoko/tokenmania/ @dfinity/ninja-devs
/motoko/token_transfer/ @dfinity/growth
/motoko/token_transfer_from/ @dfinity/growth
/motoko/vetkd/ @dfinity/crypto-team
/motoko/whoami/ @dfinity/growth
/motoko/who_am_i/ @dfinity/ninja-devs

/native-apps/unity_ii_applink/ @dfinity/sdk
/native-apps/unity_ii_deeplink/ @dfinity/sdk

/rust/basic_bitcoin/ @dfinity/execution
/rust/basic_dao/ @dfinity/testing-verification
/rust/basic_ethereum/ @dfinity/cross-chain-team
/rust/backend_only/ @dfinity/ninja-devs
/rust/canister-info/ @dfinity/testing-verification
/rust/canister-snapshots/ @dfinity/execution
/rust/canister_logs/ @dfinity/execution
/rust/composite_query/ @dfinity/execution
/rust/counter/ @dfinity/growth
/rust/daily_planner/ @dfinity/ninja-devs
/rust/defi/ @dfinity/growth
/rust/dip721-nft-container/ @dfinity/sdk
/rust/encrypted-notes-dapp-vetkd/ @dfinity/crypto-team
/rust/encrypted-notes-dapp/ @dfinity/crypto-team
/rust/evm_block_explorer/ @dfinity/ninja-devs
/rust/face-recognition/ @dfinity/execution
/rust/flying_ninja/ @dfinity/ninja-devs
/rust/guards/ @dfinity/cross-chain-team
/rust/hello/ @dfinity/sdk
/rust/hello_world/ @dfinity/ninja-devs
/rust/icp_transfer/ @dfinity/growth
/rust/image-classification/ @dfinity/execution
/rust/inter-canister-calls/ @dfinity/ic-message-routing-owners
/rust/llm_chatbot/ @dfinity/ninja-devs
/rust/nft-wallet/ @dfinity/growth
/rust/parallel_calls/ @dfinity/research
/rust/performance_counters/ @dfinity/execution
Expand All @@ -71,9 +87,11 @@
/rust/simd/ @dfinity/execution
/rust/threshold-ecdsa/ @dfinity/crypto-team
/rust/threshold-schnorr/ @dfinity/crypto-team
/rust/tokenmania/ @dfinity/ninja-devs
/rust/token_transfer/ @dfinity/growth
/rust/token_transfer_from/ @dfinity/growth
/rust/vetkd/ @dfinity/crypto-team
/rust/who_am_i/ @dfinity/ninja-devs
/rust/x509/ @dfinity/crypto-team

/svelte/svelte-motoko-starter/ @dfinity/sdk
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/examples_pr_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Test examples

on:
pull_request:
branches:
- master

concurrency:
group: examples-pr-checks-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-example-changes:
name: Filter projects
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_examples: ${{ steps.set-matrix.outputs.has_examples }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Fetch all branches
run: git fetch origin

- name: Set matrix based on changes
id: set-matrix
run: |
changed_files=$(git diff --name-only origin/main ${{ github.sha }})
echo "Changed files: $changed_files"

examples=()
declare -A example_paths=(
["My Crypto Blog (Frontend)"]="hosting/my_crypto_blog"
["React (Frontend)"]="hosting/react"
["Motoko backend (Motoko)"]="motoko/backend_only"
["Daily Planner (Motoko)"]="motoko/daily_planner"
["EVM Block Explorer (Motoko)"]="motoko/evm_block_explorer"
["FileVault (Motoko)"]="motoko/filevault"
["Flying Ninja (Motoko)"]="motoko/flying_ninja"
["Hello World (Motoko)"]="motoko/hello_world"
["LLM Chatbot (Motoko)"]="motoko/llm_chatbot"
["Tokenmania (Motoko)"]="motoko/tokenmania"
["Who Am I (Motoko)"]="motoko/who_am_i"
["Rust backend (Rust)"]="rust/backend_only"
["Daily Planner (Rust)"]="rust/daily_planner"
["EVM Block Explorer (Rust)"]="rust/evm_block_explorer"
["Flying Ninja (Rust)"]="rust/flying_ninja"
["Hello World (Rust)"]="rust/hello_world"
["LLM Chatbot (Rust)"]="rust/llm_chatbot"
["Tokenmania (Rust)"]="rust/tokenmania"
["Who Am I (Rust)"]="rust/who_am_i"
)
for name in "${!example_paths[@]}"; do
path=${example_paths[$name]}
echo "Checking path: $path"

if echo "$changed_files" | grep -q "^$path/"; then
examples+=("{\"name\": \"$name\", \"path\": \"$path\"}")
echo "Added example: $name with path $path"
fi
done

if [ ${#examples[@]} -eq 0 ]; then
echo "No examples detected. Setting has_examples to false."
echo "has_examples=false" >> $GITHUB_OUTPUT
echo "matrix={\"example\": []}" >> $GITHUB_OUTPUT
else
matrix="{\"example\": [$(IFS=, ; echo "${examples[*]}")]}"
echo "Matrix generated: $matrix"
echo "has_examples=true" >> $GITHUB_OUTPUT
echo "matrix=$matrix" >> $GITHUB_OUTPUT
fi

build-examples:
name: Build
needs: check-example-changes
if: needs.check-example-changes.outputs.has_examples == 'true'
runs-on: ubuntu-22.04
container: ghcr.io/dfinity/icp-dev-env-slim:17
strategy:
matrix: ${{ fromJson(needs.check-example-changes.outputs.matrix) }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dfx # This is a temporary workaround. Dfx is already installed in the container, but it does not start in the next step if we don't install it here again.
uses: dfinity/setup-dfx@main

- name: Start dfx
run: dfx start --background

- name: Build project
working-directory: ${{ matrix.example.path }}
run: |
if [ -f "Makefile" ]; then
make test
else
dfx deploy
fi
40 changes: 0 additions & 40 deletions .github/workflows/rust-hello-example.yml

This file was deleted.

109 changes: 109 additions & 0 deletions hosting/my_crypto_blog/BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Continue building locally

Projects deployed through ICP Ninja are temporary; they will only be live for 20 minutes before they are removed. The command-line tool `dfx` can be used to continue building your ICP Ninja project locally and deploy it to the mainnet.

To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps.

### 1. Install developer tools.

You can install the developer tools natively or use Dev Containers.

#### Option 1: Natively install developer tools

> Installing `dfx` natively is currently only supported on macOS and Linux systems. On Windows, it is recommended to use the Dev Containers option.

1. Install `dfx` with the following command:

```

sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"

```

> On Apple Silicon (e.g., Apple M1 chip), make sure you have Rosetta installed (`softwareupdate --install-rosetta`).

2. [Install NodeJS](https://nodejs.org/en/download/package-manager).

3. For Rust projects, you will also need to:

- Install [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html#install-rust-and-cargo): `curl https://sh.rustup.rs -sSf | sh`

- Install [candid-extractor](https://crates.io/crates/candid-extractor): `cargo install candid-extractor`

4. For Motoko projects, you will also need to:

- Install the Motoko package manager [Mops](https://docs.mops.one/quick-start#2-install-mops-cli): `npm i -g ic-mops`

Lastly, navigate into your project's directory that you downloaded from ICP Ninja.

#### Option 2: Dev Containers

Continue building your projects locally by installing the [Dev Container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code and [Docker](https://docs.docker.com/engine/install/).

Make sure Docker is running, then navigate into your project's directory that you downloaded from ICP Ninja and start the Dev Container by selecting `Dev-Containers: Reopen in Container` in VS Code's command palette (F1 or Ctrl/Cmd+Shift+P).

> Note that local development ports (e.g. the ports used by `dfx` or `vite`) are forwarded from the Dev Container to your local machine. In the VS code terminal, use Ctrl/Cmd+Click on the displayed local URLs to open them in your browser. To view the current port mappings, click the "Ports" tab in the VS Code terminal window.

### 2. Create a local developer identity.

To manage your project's canisters, it is recommended that you create a local [developer identity](https://internetcomputer.org/docs/building-apps/getting-started/identities) rather than use the `dfx` default identity that is not stored securely.

To create a new identity, run the commands:

```

dfx start --background

dfx identity new IDENTITY_NAME

dfx identity use IDENTITY_NAME

```

Replace `IDENTITY_NAME` with your preferred identity name. The first command `dfx start --background` starts the local `dfx` processes, then `dfx identity new` will create a new identity and return your identity's seed phase. Be sure to save this in a safe, secure location.

The third command `dfx identity use` will tell `dfx` to use your new identity as the active identity. Any canister smart contracts created after running `dfx identity use` will be owned and controlled by the active identity.

Your identity will have a principal ID associated with it. Principal IDs are used to identify different entities on ICP, such as users and canisters.

[Learn more about ICP developer identities](https://internetcomputer.org/docs/building-apps/getting-started/identities).

### 3. Deploy the project locally.

Deploy your project to your local developer environment with:

```
npm install
dfx deploy

```

Your project will be hosted on your local machine. The local canister URLs for your project will be shown in the terminal window as output of the `dfx deploy` command. You can open these URLs in your web browser to view the local instance of your project.

### 4. Obtain cycles.

To deploy your project to the mainnet for long-term public accessibility, first you will need [cycles](https://internetcomputer.org/docs/building-apps/getting-started/tokens-and-cycles). Cycles are used to pay for the resources your project uses on the mainnet, such as storage and compute.

> This cost model is known as ICP's [reverse gas model](https://internetcomputer.org/docs/building-apps/essentials/gas-cost), where developers pay for their project's gas fees rather than users pay for their own gas fees. This model provides an enhanced end user experience since they do not need to hold tokens or sign transactions when using a dapp deployed on ICP.

> Learn how much a project may cost by using the [pricing calculator](https://internetcomputer.org/docs/building-apps/essentials/cost-estimations-and-examples).

Cycles can be obtained through [converting ICP tokens into cycles using `dfx`](https://internetcomputer.org/docs/building-apps/developer-tools/dfx/dfx-cycles#dfx-cycles-convert).

### 5. Deploy to the mainnet.

Once you have cycles, run the command:

```

dfx deploy --network ic

```

After your project has been deployed to the mainnet, it will continuously require cycles to pay for the resources it uses. You will need to [top up](https://internetcomputer.org/docs/building-apps/canister-management/topping-up) your project's canisters or set up automatic cycles management through a service such as [CycleOps](https://cycleops.dev/).

> If your project's canisters run out of cycles, they will be removed from the network.

## Additional examples

Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples).
25 changes: 25 additions & 0 deletions hosting/my_crypto_blog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# My crypto blog

![My Crypto Blog](my_crypto_blog.png)

This frontend-only asset canister allows you to serve static files without a backend canister.
Asset canisters can be used to serve static frontend files, such as HTML, CSS, and JavaScript files, to users through a web browser.

## Project structure

The `/frontend` folder contains web assets for the application's user interface. The user interface is written using the React framework.

## Deploying from ICP Ninja

When viewing this project in ICP Ninja, you can deploy it directly to the mainnet for free by clicking "Deploy" in the upper right corner.
To open this project in ICP Ninja, click [here](https://icp.ninja/i?url=https://github.com/dfinity/examples/tree/master/hosting/my_crypto_blog).

To **download** or **reset** the project files, click the menu option next to the deploy button.

## Build and deploy from the command-line

To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps. These steps are necessary if you want to deploy this project for long-term, production use on the mainnet.

### 1. Download your project from ICP Ninja using the 'Download files' button on the upper left corner under the pink ninja star icon.

### 2. Open the `BUILD.md` file for further instructions.
20 changes: 20 additions & 0 deletions hosting/my_crypto_blog/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "ICP Dev Environment",
"image": "ghcr.io/dfinity/icp-dev-env-slim:17",
"forwardPorts": [4943, 5173],
"portsAttributes": {
"4943": {
"label": "dfx",
"onAutoForward": "ignore"
},
"5173": {
"label": "vite",
"onAutoForward": "openBrowser"
}
},
"customizations": {
"vscode": {
"extensions": ["dfinity-foundation.vscode-motoko"]
}
}
}
11 changes: 11 additions & 0 deletions hosting/my_crypto_blog/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"canisters": {
"frontend": {
"frontend": {
"entrypoint": "frontend/index.html"
},
"source": ["frontend/dist"],
"type": "assets"
}
}
}
Loading