-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed Dockerfile and added build step * Added script for auto generating simple env * Fixed docker tag and updated script to include faucet * Updated package.json with new command * renamed tutorial-setup * Setup script generated wallet now persists
- Loading branch information
1 parent
7ae7ad5
commit 2d33199
Showing
10 changed files
with
300 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ Dockerfile | |
.github | ||
.vscode | ||
.changeset | ||
.dockerignore | ||
.dockerignore | ||
.secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: 'Build Docker Images' | ||
description: 'Builds Docker images and pushes them to ECR and GHCR' | ||
inputs: | ||
DOCKER_FILENAME: | ||
description: 'Name of the docker file to use for the build' | ||
required: true | ||
REPOSITORY_NAME: | ||
description: 'Name of the Repository' | ||
required: true | ||
IMAGE_TAG: | ||
description: 'Image Tag' | ||
required: true | ||
GHCR_USERNAME: | ||
description: 'Username for GitHub Container Registry' | ||
required: true | ||
GHCR_TOKEN: | ||
description: 'Token for GitHub Container Registry' | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
|
||
steps: | ||
- name: Set Environment Variables" | ||
run: | | ||
echo "DOCKER_FILENAME=${{ inputs.DOCKER_FILENAME }}" >> $GITHUB_ENV | ||
echo "REPOSITORY_NAME=${{ inputs.REPOSITORY_NAME }}" >> $GITHUB_ENV | ||
echo "IMAGE_TAG=${{ inputs.IMAGE_TAG }}" >> $GITHUB_ENV | ||
echo "GHCR_USERNAME=${{ inputs.GHCR_USERNAME }}" >> $GITHUB_ENV | ||
echo "GHCR_TOKEN=${{ inputs.GHCR_TOKEN }}" >> $GITHUB_ENV | ||
shell: bash | ||
|
||
- name: Log in to the GitHub Container Registry | ||
id: login-ghcr | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ env.GHCR_USERNAME }} | ||
password: ${{ env.GHCR_TOKEN }} | ||
|
||
- name: Build, tag, and push images | ||
shell: bash | ||
env: | ||
GHCR_REGISTRY: ghcr.io/zeta-chain | ||
run: | | ||
docker build -f $DOCKER_FILENAME -t $GHCR_REGISTRY/$REPOSITORY_NAME:$IMAGE_TAG . | ||
docker push $GHCR_REGISTRY/$REPOSITORY_NAME:$IMAGE_TAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: 'SET:BRANCH:TAG:REFERENCES' | ||
description: 'Logic to set branch-name from the event and type.' | ||
inputs: | ||
github_ref: | ||
description: "github ref to use" | ||
required: true | ||
github_event: | ||
description: "github event to use" | ||
required: true | ||
github_head_ref: | ||
description: "github head ref to use" | ||
required: true | ||
github_commit_sha: | ||
description: "github sha to use" | ||
required: true | ||
current_branch_name: | ||
description: "current_branch" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set branch name | ||
id: set-branch-name | ||
shell: bash | ||
run: | | ||
tag_check=`echo '${{ inputs.github_ref }}' | grep 'tags'` || echo "proceed" | ||
if [ "${{ inputs.github_event }}" == "pull_request" ]; then | ||
echo "Setting the current branch name to same as the source branch of the PR" | ||
RELEASE_NAME=$(sed 's#/#-#g' <<< ${{ inputs.github_head_ref }}) | ||
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV | ||
TAG_NAME="$RELEASE_NAME-${{ inputs.github_commit_sha }}" | ||
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | ||
elif [ "${{ inputs.github_ref }}" == "refs/heads/main" ]; then | ||
TAG_NAME="latest" | ||
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | ||
else | ||
RELEASE_NAME=$(sed 's#/#-#g' <<< ${{ inputs.current_branch_name }}) | ||
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_ENV | ||
TAG_NAME="$RELEASE_NAME-${{ inputs.github_commit_sha }}" | ||
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | ||
fi | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
|
||
|
||
env: | ||
GITHUB_REF_NAME: "$(echo ${{ github.ref_name }} | tr '//' '-')" | ||
|
||
jobs: | ||
build-docker: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: setup-git-credentials | ||
uses: de-vri-es/[email protected] | ||
with: | ||
credentials: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | ||
|
||
- name: Get branch name | ||
id: branch-name | ||
uses: tj-actions/branch-names@v6 | ||
|
||
- name: Git Hash | ||
run: | | ||
echo "GIT_HASH=$(git rev-parse --short HEAD)" >> ${GITHUB_ENV} | ||
echo "WORKSPACE_DIR=$(pwd)" >> ${GITHUB_ENV} | ||
- name: set-branch-name | ||
uses: ./.github/actions/set-branch-name | ||
with: | ||
github_ref: "${{github.ref}}" | ||
github_event: "${{ github.event_name }}" | ||
github_head_ref: "${{ github.event.pull_request.head.ref }}" | ||
github_commit_sha: "${{ env.GIT_HASH }}" | ||
current_branch_name: "${{ steps.branch-name.outputs.current_branch }}" | ||
|
||
- name: Build, tag, and push docker images | ||
uses: ./.github/actions/build-docker-images | ||
with: | ||
DOCKER_FILENAME: Dockerfile | ||
REPOSITORY_NAME: zetachain | ||
IMAGE_TAG: ${{ env.TAG_NAME }} | ||
GHCR_USERNAME: ${{ secrets.PAT_GITHUB_SERVICE_ACCT_USERNAME }} | ||
GHCR_TOKEN: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,18 @@ RUN apk add --update python3 yarn git nodejs make g++ | |
## Install node modules before the code is copied to the container | ||
WORKDIR /home/zetachain/ | ||
COPY package*.json ./ | ||
RUN yarn install | ||
COPY packages/addresses-tools/package.json ./packages/addresses-tools/package.json | ||
COPY packages/interfaces/package.json ./packages/interfaces/package.json | ||
COPY packages/zevm-example-contracts/package.json ./packages/zevm-example-contracts/package.json | ||
COPY packages/addresses/package.json packages/addresses/package.json | ||
COPY packages/protocol-contracts/package.json ./packages/protocol-contracts/package.json | ||
COPY packages/zevm-protocol-contracts/package.json ./packages/zevm-protocol-contracts/package.json | ||
COPY packages/example-contracts/package.json ./packages/example-contracts/package.json | ||
COPY packages/zeta-app-contracts/package.json ./packages/zeta-app-contracts/package.json | ||
RUN yarn install ; exit 0 | ||
|
||
COPY . ./ | ||
RUN yarn install | ||
RUN yarn install | ||
|
||
RUN yarn add [email protected] | ||
RUN yarn add [email protected] | ||
|
@@ -21,7 +29,9 @@ RUN yarn add [email protected] | |
|
||
RUN cd packages/protocol-contracts && npx hardhat compile && cd - | ||
RUN cd packages/example-contracts && npx hardhat compile && cd - | ||
RUN cd packages/zevm-contracts && npx hardhat compile && cd - | ||
RUN cd packages/zeta-app-contracts && npx hardhat compile && cd - | ||
RUN cd packages/zevm-example-contracts && npx hardhat compile && cd - | ||
RUN cd packages/zevm-protocol-contracts && npx hardhat compile && cd - | ||
|
||
WORKDIR /home/zetachain/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ | |
"slither": "npx ts-node ./scripts/slither.ts", | ||
"test": "yarn workspaces foreach -ptv run test", | ||
"g:changeset": "changeset", | ||
"g:release": "yarn changeset publish" | ||
"g:release": "yarn changeset publish", | ||
"setup-tutorial": "ts-node ./scripts/setup-tutorial.ts" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.23.1", | ||
|
@@ -62,5 +63,8 @@ | |
"typechain": "^8.0.0", | ||
"typescript": "^4.6.3" | ||
}, | ||
"packageManager": "[email protected]" | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"solc": "0.8.7" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Wallet } from "ethers"; | ||
import * as fs from "fs"; | ||
import * as https from "https"; | ||
|
||
const jsonPath = "scripts/.wallet.json"; | ||
|
||
interface WalletConfig { | ||
address: string; | ||
privateKey: string; | ||
} | ||
|
||
function saveEnvFiles(address: string, privateKey: string): void { | ||
const value: string = ` | ||
PRIVATE_KEY=${privateKey} | ||
ZETA_NETWORK=athens | ||
EXECUTE_PROGRAMMATICALLY=true`; | ||
const filePaths: string[] = ["packages/example-contracts/.env", "packages/zevm-example-contracts/.env"]; | ||
|
||
filePaths.forEach((filePath: string) => { | ||
fs.writeFile(filePath, value, (err: NodeJS.ErrnoException | null) => { | ||
if (err) { | ||
console.error(`Failed to write to file ${filePath}: ${err}`); | ||
} else { | ||
console.log(`Updated .env file "${filePath}".`); | ||
} | ||
}); | ||
}); | ||
} | ||
function saveWalletFile(address: string, privateKey: string, jsonPath: string): void { | ||
const data = `{"address": "${address}", "privateKey": "${privateKey}}`; | ||
|
||
fs.access(jsonPath, err => { | ||
if (err) { | ||
// The file does not exist, so we can write to it | ||
fs.writeFile(jsonPath, data, err => { | ||
if (err) throw err; | ||
console.log("The new wallet file has been saved!"); | ||
}); | ||
} else { | ||
// The file already exists, so we do not write to it | ||
// console.log("The file already exists!"); | ||
} | ||
}); | ||
} | ||
function callFaucet(address: string): void { | ||
// Hit Faucet to get some testnet Zeta | ||
console.log("Requesting testnet assets from the faucet..."); | ||
const options: https.RequestOptions = { | ||
hostname: "faucet.zetachain.link", | ||
method: "GET", | ||
path: `/eth/${address}`, | ||
port: 443 | ||
}; | ||
|
||
const req = https.request(options, res => { | ||
console.log(`statusCode: ${res.statusCode}`); | ||
|
||
res.on("data", d => { | ||
process.stdout.write(d); | ||
}); | ||
}); | ||
|
||
req.on("error", error => { | ||
console.error(error); | ||
}); | ||
|
||
req.end(); | ||
} | ||
|
||
function createWallet(filePath: string, callback: () => void): void { | ||
fs.access(filePath, err => { | ||
if (!err) { | ||
callback(); | ||
} | ||
}); | ||
} | ||
|
||
async function getOrCreateWallet(filePath: string): Promise<Wallet> { | ||
let wallet: Wallet; | ||
|
||
try { | ||
const data = await fs.promises.readFile(filePath, "utf8"); | ||
const walletConfig: WalletConfig = JSON.parse(data); | ||
wallet = new Wallet(walletConfig.privateKey); | ||
} catch (error) { | ||
console.log("No Wallet Exists, Creating One..."); | ||
const newWallet = Wallet.createRandom(); | ||
const walletConfig: WalletConfig = { | ||
address: newWallet.address, | ||
privateKey: newWallet.privateKey | ||
}; | ||
await fs.promises.writeFile(filePath, JSON.stringify(walletConfig)); | ||
wallet = newWallet; | ||
} | ||
|
||
return wallet; | ||
} | ||
|
||
const wallet = getOrCreateWallet(jsonPath).then(async wallet => { | ||
console.log(`Your Wallet Address: ${wallet.address}`); | ||
console.log(`Your Private Key: ${wallet.privateKey.substring(2)}`); | ||
saveEnvFiles(wallet.address, wallet.privateKey.substring(2)); | ||
saveWalletFile(wallet.address, wallet.privateKey.substring(2), jsonPath); | ||
await callFaucet(wallet.address); | ||
}); |
Oops, something went wrong.