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

Feature cicd #18

Merged
merged 19 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and publish image
on:
push:
branches:
- main
tags:
- '*'

jobs:
test_build_and_push_to_docker_registry:
name: Test, build and publish image to docker hub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
# - uses: actions/setup-node@v3
# with:
# node-version: '20.x'
# - name: Install dependencies
# run: npm install && npm run postinstall
# - name: Unit tests
# run: npm run test
- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

- name: Determine Docker Image Name
id: image
run: |
if [[ "${{github.ref_name}}" == "master" ]]; then
echo "name=xinfinorg/xdc-zero:latest" >> $GITHUB_OUTPUT
else
echo "name=xinfinorg/xdc-zero:${{github.ref_name}}" >> $GITHUB_OUTPUT
fi

- name: Docker build and tag image
run: docker build . --file cicd/Dockerfile --tag ${{ steps.image.outputs.name }}
- name: Docker push
run: docker push ${{ steps.image.outputs.name }}
50 changes: 50 additions & 0 deletions .github/workflows/pr_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build custom branch
on:
pull_request:
branches:
- main

jobs:
build:
if: |
( startsWith(github.head_ref, 'feature') ||
startsWith(github.head_ref, 'fix') )
name: Deploy on PR
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: check out trigger branch
run: |
git fetch origin $BRANCH
git checkout $BRANCH
env:
BRANCH: ${{ github.head_ref }}

- name: Record branch env
id: branch
run: |
echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
# echo $repo
# echo $branch
# echo $commit

- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

- name: Determine Docker Image Name
id: image
run: |
echo "name=xinfinorg/xdc-zero:${{ steps.branch.outputs.branch }}" >> $GITHUB_OUTPUT

- name: Build and push image
run: |
docker build . --file cicd/Dockerfile --tag ${{ steps.image.outputs.name }}
docker push ${{ steps.image.outputs.name }}
19 changes: 19 additions & 0 deletions cicd/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

SUBNET_PK=0x1111111111111111111111111111111111111111111111111111111111111111
PARENTNET_PK=0x2222222222222222222222222222222222222222222222222222222222222222
CSC=0x3333333333333333333333333333333333333333
REVERSE_CSC=0x4444444444444444444444444444444444444444

# PARENTNET_URL: full url or devnet,testnet
# devnet : https://devnetstats.apothem.network/devnet/
# testnet : https://devnetstats.apothem.network/testnet/
PARENTNET_URL=testnet
SUBNET_URL=https://devnetstats.apothem.network/subnet/


# add in later steps
# SUBNET_ZERO_CONTRACT=0x3333333333333333333333333333333333333333
# PARENTNET_ZERO_CONTRACT=0x3333333333333333333333333333333333333333

# SUBNET_APP=0x3333333333333333333333333333333333333333
# PARENTNET_APP=0x3333333333333333333333333333333333333333
6 changes: 6 additions & 0 deletions cicd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.env
package-lock.json
mount/*
!mount/placeholder.txt
yarn.lock
14 changes: 14 additions & 0 deletions cicd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:20-alpine

COPY . /app

WORKDIR /app/cicd
RUN yarn
WORKDIR /app/endpoint
RUN yarn
WORKDIR /app/applications/subswap/contract
RUN yarn

WORKDIR /app/cicd

ENTRYPOINT ["node"]
2 changes: 2 additions & 0 deletions cicd/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**node_modules
**package-lock.json
117 changes: 117 additions & 0 deletions cicd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# XDC ZERO CICD

## Deploy with Docker

### 1. Deploy XDC Zero

#### Step 1: Create a `.env` File

Based on the provided `.env.example`, create your own `.env` file with the following details:

- **`PARENTNET_URL`**: RPC URL for the parentnet endpoint.
- **`SUBNET_URL`**: RPC URL for the subnet.
- **`SUBNET_PK`**: Private key for the deploy subnet XDC Zero wallet.
- **`CSC`**: Checkpoint smart contract address within the subnet chain (deployed to parentnet).
- **`REVERSE_CSC`**: Checkpoint smart contract address within the parentnet chain (deployed to subnet).

#### Step 2: Deploy Endpoints and Register Chain

Run the following command to deploy the endpoints and register the chain:

```sh
docker run --env-file .env xinfinorg/xdc-zero:latest endpointandregisterchain.js
```

Add the output to your `.env` file:

- **`SUBNET_ZERO_CONTRACT`**: XDC ZERO contract address for subnet.
- **`PARENTNET_ZERO_CONTRACT`**: XDC ZERO contract address for parentnet.

### 2. Deploy Subswap
Here Subswap is our default provided application, you can also deploy your own custom app.
```sh
docker run --env-file .env xinfinorg/xdc-zero:latest subswap.js
```

### 3. Register Application to XDC Zero

Add the user application contract address to your `.env` file:

- **`SUBNET_APP`**: Subnet user application address.
- **`PARENTNET_APP`**: Parentnet user application address.

Run the following command:

```sh
docker run --env-file .env xinfinorg/xdc-zero:latest applicationregister.js
```

---

## Deploy with Repository

### Step 1: Install Packages

Run the following commands to install the necessary packages:

```sh
cd ../endpoint
yarn
cd ../applications/subswap/contract
yarn
cd cicd
yarn
```


### Step 2: Create a `.env` File to `cicd/mount`

Based on the provided `.env.example`, create your own `.env` file with the following details:

- **`PARENTNET_URL`**: RPC URL for the parentnet endpoint.
- **`SUBNET_URL`**: RPC URL for the subnet.
- **`SUBNET_PK`**: Private key for the deploy subnet XDC Zero wallet.
- **`CSC`**: Checkpoint smart contract address within the subnet chain (deployed to parentnet).
- **`REVERSE_CSC`**: Checkpoint smart contract address within the parentnet chain (deployed to subnet).

### Step 3: Deploy Endpoint and Register Chain

Navigate to the `cicd` directory and run the following command:

```sh
cd cicd
node endpointandregisterchain.js
```

Add the output to your `.env` file:

- **`SUBNET_ZERO_CONTRACT`**: XDC ZERO contract address for subnet.
- **`PARENTNET_ZERO_CONTRACT`**: XDC ZERO contract address for parentnet.

### Step 4: Deploy Subswap
Here Subswap is our default provided application, you can also deploy your own custom app.
```sh
docker run --env-file .env xinfinorg/xdc-zero:latest subswap.js
```

### Step 5: Register Application

Add the user application contract address to `cicd/mount/.env`:

- **`SUBNET_APP`**: Subnet user application address.
- **`PARENTNET_APP`**: Parentnet user application address.

Run the following command:

```sh
node applicationregister.js
```


## There are some application example , you can feel free to deploy

- [Sample](../applications/sample/)

- [Subswap](../applications/subswap/)


Loading
Loading