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

Add CLI image #67

Merged
merged 16 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
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
30 changes: 0 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,6 @@ jobs:
exit 1
fi

windows-init-command:
name: Init Command on Windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Build CLI for windows and link it
run: |
cd chain-cli
npm install
npm run build-win
npm link --force
- name: Initialize a project and validate the package.json
run: galachain init test-project
- name: Check if the package.json contains '@gala-chain/test-project' using windows command
run: |
$package = Get-Content -Path test-project/package.json -Raw
if ($package -match '@gala-chain/test-project') {
Write-Host "package.json contains '@gala-chain/test-project'"
} else {
Write-Host "package.json does not contain '@gala-chain/test-project'"
exit 1
}

chaincode-template-lint:
name: Chaincode Template Lint
runs-on: ubuntu-22.04
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/publish-cli-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish CLI Docker image
on:
push:
paths:
- 'chain-cli/docker/Dockerfile'

env:
REGISTRY: ghcr.io
IMAGE_NAME: galachain/sdk

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Make the repository name lowercase
id: lower-repo
shell: pwsh
run: |
"::set-output name=repository::$($env:GITHUB_REPOSITORY.ToLowerInvariant())"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./chain-cli/docker
push: true
tags: ghcr.io/${{ steps.lower-repo.outputs.repository }}:latest
51 changes: 0 additions & 51 deletions chain-cli/chaincode-template/docker/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ RUN npm install -g @gala-chain/cli
# Install Nodemon globally
RUN npm install -g nodemon

# Define the build-time argument for the project name with a default value
ARG PROJECT_NAME=proj-galachain

# Initialize a project with galachain
RUN galachain init "$PROJECT_NAME"
RUN galachain init chaincode-template

# Change working directory to the project directory
WORKDIR /$PROJECT_NAME
WORKDIR /chaincode-template

# Install project dependencies
RUN npm install

# Expose port 3010
EXPOSE 3010

# Start the Docker daemon as a background process and tail its log file
CMD dockerd > /var/log/dockerd.log 2>&1 & tail -f /var/log/dockerd.log
52 changes: 52 additions & 0 deletions chain-cli/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Dockerized Galachain Dev Environment

## Base requirement

- Docker Desktop or Docker CLI.
- [Optional] VS Code with [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension.

## Run a container
Run a container from the built image:

$ docker run --privileged -d -p 3010:3010 -it --name <container_name> ghcr.io/galachain/sdk:latest

Make sure the container is up and running.
The Docker image initializes a new project with the name `chaincode-template` by default.

## Open the running container

### Open the container with bash

```
docker exec -ti <container_name> /bin/bash
```

### Open the container with VSCode (Requires VSCode and Dev Containers Extension)

Open VSCode and press F1 to open the Command Palette and search for `Dev Containers: Attach to Running Container`

After attach the container you may have to open the project folder manually.

## Start the network

Once the terminal is open, start the network

```
npm run network:start
```

The network is going to start in dev mode and the prompt will be left showing the logs, so don't close the prompt and open new ones to proceed with the following commands.

## Run integration tests

Now you can run integration tests with:

```
npm run test:e2e
```

## Verify changes in block browser and GraphQL

Navigate to [http://localhost:3010/blocks](http://localhost:3010/blocks) to see our block browser which allows you to see what's saved on your local GalaChain network.

Navigate to [http://localhost:3010/graphiql](http://localhost:3010/graphiql) to interact with GraphQL and execute queries.
5 changes: 0 additions & 5 deletions chain-cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ export default class Init extends BaseCommand<typeof Init> {
}

copyChaincodeTemplate(destinationPath: string): void {
if (process.platform === "win32") {
const sourceTemplateDir = path.resolve(__dirname, "..", "..", "..", "chaincode-template");
execSync(`xcopy ${sourceTemplateDir} ${destinationPath} /E /I`);
return;
}
const sourceTemplateDir = path.resolve(require.resolve("."), "../../../chaincode-template");
execSync(`cp -R ${sourceTemplateDir} ${destinationPath}`);
}
Expand Down
47 changes: 31 additions & 16 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,41 +142,56 @@ Navigate to [http://localhost:3010/blocks](http://localhost:3010/blocks) to see

Navigate to [http://localhost:3010/graphiql](http://localhost:3010/graphiql) to interact with GraphQL and execute queries.

## Use Docker file + Dev Containers (Linux, MacOS or Windows)
## Use Docker image (Linux, MacOS or Windows)

### Requirements

- [VSCode](https://code.visualstudio.com/)
- [Dev Containers Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
- Node.js
- Docker
- Docker Desktop or Docker CLI.
- [Optional] VS Code with [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension.

### 1. Install our CLI
### 1. Run the Docker image

```
npm i -g @gala-games/chain-cli
docker run --privileged -d -p 3010:3010 -it --name <container_name> ghcr.io/galachain/sdk:latest
```

Check the CLI:
Make sure the container is up and running.
The Docker image initializes a new project with the name `chaincode-template` by default.

### 2. Open the running container

## 2.1 Open the container with bash

```
galachain --help
docker exec -ti <container_name> /bin/bash
```

### 2. Initialize your project
## 2.2 Open the container with VSCode (Requires VSCode and Dev Containers Extension)

Open VSCode and press F1 to open the Command Palette and search for `Dev Containers: Attach to Running Container`

After attach the container you may have to open the project folder manually.

### 3. Start the network

Once the terminal is open, start the network with:

```
galachain init <project-name>
npm run network:start
```

It will create a sample project inside `<project-name>` directory.
The network is going to start in dev mode and the prompt will be left showing the logs, so don't close the prompt and open new ones to proceed with the following commands.

### 3. Docker file and Instructions
### 4. Run integration tests

Navigate to the docker folder where you can find a Docker file and instructions about how to use it.
Now you can run integration tests with:

```
cd <project-name>/docker
npm run test:e2e
```

Follow the steps on the `README.md` file.
### 5. Verify changes in block browser and GraphQL

Navigate to [http://localhost:3010/blocks](http://localhost:3010/blocks) to see our block browser which allows you to see what's saved on your local GalaChain network.

Navigate to [http://localhost:3010/graphiql](http://localhost:3010/graphiql) to interact with GraphQL and execute queries.
3 changes: 2 additions & 1 deletion unifyVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ packages.forEach(({ packageJson, packageJsonPath }) => {
}
});

const { execSync } = require("child_process");

// execute `npm install` in the root directory to update the lock file and licenses
execSync("npm install");

// execute `npm run build` in chain-cli to update the new version in README.md and oclif.manifest.json
const { execSync } = require("child_process");
execSync("npm run build", { cwd: "chain-cli" });
Loading