Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
.PHONY: release-partials release-recipe release-recipes help
.PHONY: release-recipe release-recipes help

help:
@echo "Available targets:"
@echo " release-partials VERSION_TAG=<version> - Release partials with specified version"
@echo " release-recipe RECIPE=<name> VERSION_TAG=<version> - Release specific recipe with version"
@echo " release-recipes VERSION_TAG=<version> - Release all recipes with specified version"
@echo ""
@echo "Examples:"
@echo " make release-partials VERSION_TAG=v1.0.0"
@echo " make release-recipe RECIPE=rust VERSION_TAG=v1.0.0"
@echo " make release-recipe RECIPE=motoko VERSION_TAG=v1.1.0"
@echo " make release-recipes VERSION_TAG=v1.0.0"

release-partials:
@if [ -z "$(VERSION_TAG)" ]; then \
echo "Error: VERSION_TAG is required"; \
echo "Usage: make release-partials VERSION_TAG=v1.0.0"; \
exit 1; \
fi
@echo "Creating partials release tag: partials-$(VERSION_TAG)"
git tag -a partials-$(VERSION_TAG) -m "Release partials $(VERSION_TAG)"
git push origin partials-$(VERSION_TAG)
@echo "Release tag created! GitHub Actions will build and publish the release."

release-recipes:
@if [ -z "$(VERSION_TAG)" ]; then \
echo "Error: VERSION_TAG is required"; \
Expand Down Expand Up @@ -65,4 +52,4 @@ release-recipe:
git tag -a $(RECIPE)-latest -m "Latest $(RECIPE) recipe ($(VERSION_TAG))" -f
git push origin $(RECIPE)-$(VERSION_TAG)
git push origin $(RECIPE)-latest -f
@echo "Release tags created! GitHub Actions will build and publish the releases."
@echo "Release tags created! GitHub Actions will build and publish the releases."
181 changes: 4 additions & 177 deletions docs/recipe-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ build:
- type: [build-step-type]
[step-specific-configuration]

{{> wasm-inject-metadata name="template:type" value="[recipe-type]" }}

{{#if metadata }}
{{#each metadata }}
{{> wasm-inject-metadata name=name value=value }}
{{/each}}
{{/if}}

{{#if shrink }}
{{> wasm-shrink }}
{{/if}}

{{#if compress }}
{{> wasm-compress }}
{{/if}}

# Optional sync section for recipes that need asset synchronization
sync:
steps:
Expand All @@ -45,89 +29,13 @@ sync:

#### Built-in Helpers

- `{{#if condition}}` - Conditional rendering
- `{{#each array}}` - Loop over arrays
- `{{#unless condition}}` - Inverse conditional
- `{{replace "search" "replace" string}}` - String replacement

#### Custom Helpers

- `{{sha256 file}}` - Generate SHA256 hash of a file
- `{{fileExists path}}` - Check if file exists

### Shared Partials

#### `{{> wasm-inject-metadata}}`

Injects metadata into a WASM file.

**Parameters:**

- `name` (required): Metadata key name
- `value` (required): Metadata value

**Example:**

```handlebars
{{> wasm-inject-metadata name="template:type" value="rust" }}
{{> wasm-inject-metadata name="cargo:version" value="1.70.0" }}
```

#### `{{> wasm-shrink}}`

Optimizes WASM file size by removing unnecessary sections.

**Parameters:** None

**Example:**

```handlebars
{{#if shrink }}
{{> wasm-shrink }}
{{/if}}
```

#### `{{> wasm-compress}}`

Compresses the WASM file using gzip compression.

**Parameters:** None

**Example:**

```handlebars
{{#if compress }}
{{> wasm-compress }}
{{/if}}
```

## Build Step Types

### `pre-built`

Uses a pre-compiled WASM file.

**Configuration:**

- `path`: Local path to WASM file
- `url`: URL to download WASM file
- `sha256`: Expected SHA256 hash

### `script`

Executes shell commands to build the canister.
icp-cli support the default helpers, see: [handlebars documentation](https://handlebarsjs.com/guide/builtin-helpers.html)

**Configuration:**
In addition, it provides the following helpers:

- `commands`: Array of shell commands to execute

### Environment Variables

The following environment variables are available during build:
- `{{replace "search" "replace" string}}` - String replacement

- `ICP_WASM_OUTPUT_PATH`: Path where the final WASM should be written
- `ICP_SOURCE_DIR`: Directory containing source code
- `ICP_BUILD_DIR`: Temporary build directory
More helpers might be added in the future.

## Creating a New Recipe

Expand All @@ -139,53 +47,6 @@ recipes/[recipe-name]/
└── README.md # Documentation following template
```

### 2. Template Development

Start with this basic template:

```handlebars
build:
steps:
# Add your build steps here
- type: script
commands:
- echo "Building {{canister_name}}"

{{> wasm-inject-metadata name="template:type" value="{{recipe_type}}" }}

{{#if metadata }}
{{#each metadata }}
{{> wasm-inject-metadata name=name value=value }}
{{/each}}
{{/if}}

{{#if shrink }}
{{> wasm-shrink }}
{{/if}}

{{#if compress }}
{{> wasm-compress }}
{{/if}}
```

### 3. Configuration Parameters

Define what parameters your recipe accepts:

```handlebars
# For a Rust recipe
- cargo build --package {{ package }} --target wasm32-unknown-unknown --release
- mv target/wasm32-unknown-unknown/release/{{ replace "-" "_" package }}.wasm "$ICP_WASM_OUTPUT_PATH"
```

### 4. Testing Your Recipe

Before submitting, test your recipe with:

1. **Manual testing**: Use the template with sample parameters
2. **Integration testing**: Build an actual canister using the recipe
3. **Documentation review**: Ensure README follows the template

## Best Practices

### Template Design
Expand Down Expand Up @@ -216,40 +77,6 @@ Before submitting, test your recipe with:
- Explain prerequisites and setup
- Include common troubleshooting scenarios

## Recipe Examples

### Simple Script Recipe

```handlebars
build:
steps:
- type: script
commands:
- npm install
- npm run build
- cp dist/main.wasm "$ICP_WASM_OUTPUT_PATH"

{{> wasm-inject-metadata name="template:type" value="npm" }}
```

### Conditional Features Recipe

```handlebars
build:
steps:
- type: script
commands:
{{#if debug}}
- cargo build --target wasm32-unknown-unknown
{{else}}
- cargo build --target wasm32-unknown-unknown --release
{{/if}}

{{#if optimize}}
{{> wasm-shrink }}
{{/if}}
```

## Submission Process

1. **Create recipe directory** with template and README
Expand Down
3 changes: 0 additions & 3 deletions partials/wasm-compress.hbs

This file was deleted.

3 changes: 0 additions & 3 deletions partials/wasm-inject-metadata.hbs

This file was deleted.

3 changes: 0 additions & 3 deletions partials/wasm-shrink.hbs

This file was deleted.

24 changes: 6 additions & 18 deletions recipes/assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ Example of how to reference this recipe in an `icp.yaml` file:
canister:
name: frontend
recipe:
type: assets
url: https://github.com/dfinity/icp-recipes/releases/download/v1.0.0/recipes/assets/recipe.yml
type: "@dfinity/assets"
Comment thread
raymondk marked this conversation as resolved.
Outdated
configuration:
version: 0.23.0
dir: dist
shrink: true
```

## Configuration Parameters

| Parameter | Type | Required | Description | Default |
|-----------|------|----------|-------------|---------|
| version | string | Yes | SDK version tag to download assets canister from | - |
| version | string | No | SDK version tag to download assets canister from, defaults to using the main branch| - |
| dir | string | Yes | Directory containing frontend assets to synchronize | - |
| metadata | array | No | Array of key-value pairs for custom metadata | [] |
| shrink | boolean | No | Enable WASM optimization to reduce file size | false |
| compress | boolean | No | Enable gzip compression of WASM file | false |

## Prerequisites

Expand All @@ -42,10 +38,8 @@ canister:
canister:
name: website
recipe:
type: assets
url: https://github.com/dfinity/icp-recipes/releases/download/v1.0.0/recipes/assets/recipe.yml
type: "@dfinity/assets"
configuration:
version: 0.23.0
dir: build
```

Expand All @@ -55,13 +49,10 @@ canister:
canister:
name: spa-frontend
recipe:
type: assets
url: https://github.com/dfinity/icp-recipes/releases/download/v1.0.0/recipes/assets/recipe.yml
type: "@dfinity/assets"
configuration:
version: 0.23.0
dir: dist
shrink: true
compress: true
metadata:
- name: "frontend:framework"
value: "react"
Expand All @@ -74,11 +65,8 @@ canister:
When this recipe is executed:

1. Downloads the official assets canister WASM from the specified SDK version
2. Injects template type metadata ("template:type" = "assets")
3. Injects any custom metadata specified in the configuration
4. Optionally optimizes the WASM file if `shrink` is enabled
5. Optionally compresses the WASM file if `compress` is enabled
6. Configures asset synchronization for the specified directory
2. Injects any custom metadata specified in the configuration
3. Configures asset synchronization for the specified directory

## Asset Synchronization

Expand Down
37 changes: 22 additions & 15 deletions recipes/assets/recipe.hbs
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
{{! A recipe for building static assets and deploying them to an asset canister }}
{{! `version: string` Optional, The version of the asset canister to use. Defaults to the master branch}}
{{! `dir: string` Required, the directory of assets to synchronize }}
{{! `metadata: [name: string, value: string]`: An array of name/value pairs that get injected into the wasm metadata section }}

build:

steps:

- type: pre-built
{{! There is no convenient way to define defaults }}
{{#if version}}
url: https://github.com/dfinity/sdk/raw/refs/tags/{{ version }}/src/distributed/assetstorage.wasm.gz
{{else}}
{{! TODO We needed a latest tag on the sdk repo }}
url: https://github.com/dfinity/sdk/raw/refs/heads/master/src/distributed/assetstorage.wasm.gz
{{/if}}

{{> wasm-inject-metadata name="template:type" value="assets" }}

{{#if metadata }}
{{#each metadata }}
{{> wasm-inject-metadata name=name value=value }}
{{/each}}
{{/if}}

{{#if shrink }}
{{> wasm-shrink }}
{{/if}}

{{#if compress }}
{{> wasm-compress }}
{{#if metadata}}
- type: script
commands:
{{#each metadata}}
- sh -c 'command -v ic-wasm >/dev/null 2>&1 || { echo >&2 "ic-wasm not found. To install ic-wasm, see https://github.com/dfinity/ic-wasm \n"; exit 1; }'
- sh -c 'ic-wasm "$ICP_WASM_OUTPUT_PATH" -o "${ICP_WASM_OUTPUT_PATH}" metadata "{{ name }}" -d "{{ value }}" --keep-name-section'
{{/each}}
{{/if}}

{{! Synchronize assets }}
sync:
steps:
- type: assets
dir: {{ dir }}
dir: {{ dir }}
Loading