Skip to content

Commit

Permalink
Use environment variable to activate local node (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Viénot <simon.vienot@icloud.com>
  • Loading branch information
svienot authored Oct 3, 2023
1 parent 2ee76b3 commit e6f8db2
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-image-to-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
file: ./ui/Dockerfile
# platforms: linux/amd64, linux/arm64
build-args: |
SERVER_URL=http://localhost:5555
SERVER_URL=http://localhost:5002
REPOSITORY_SERVER_URL=http://localhost:10000
TAG=latest
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Wait for hedera-sourcify server
uses: iFaxity/wait-on-action@v1
with:
resource: http://127.0.0.1:5000/chains
resource: http://127.0.0.1:5002/chains

- name: Start tests
run: npm run test:hedera
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ From the root of the project workspace:

1. Run `npm ci`. This will create populate and link `node_modules`.
2. `cp environments/.env.dev.hedera environments/.env`
* Adjust SERVER_PORT variable in `environments/.env` to use 5555 instead of 5000 if running on a Mac
* Adjust the value of the port in the SERVER_URL field in ui/public/config.json accordingly
3. Make sure the following variables defined in `.env` point to directories which exist on the file system: `REPOSITORY_PATH, SOLC_REPO, SOLJSON_REPO` (paths relative to the environments/ directory)
4. Run `npx lerna bootstrap && npx lerna run build`. This will build the server and ui as well as needed libraries.
5. Run `docker-compose -f environments/build-repository.yaml build`. This will build the docker image for the repository service.
Expand Down Expand Up @@ -60,7 +58,6 @@ or build the images locally.
1. `cp environments/.env.docker.hedera environments/.env`
2. Adjust the configuration in `environments/.env` as follows:
* Replace all occurrences of `localhost` by the fully qualified hostname if not running locally
* Adjust SERVER_EXTERNAL_PORT variable in `environments/.env` to use 5555 instead of 5000 if running on a Mac
3. `cp environments/example-docker-config.json environments/docker-config.json`
* Adjust the URLs in `docker-config.json` as needed
4. You may need to authenticate to the GitHub container registry at `ghcr.io` using a personal access token [as described here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
Expand Down
7 changes: 3 additions & 4 deletions environments/.env.dev.hedera
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
###
### USE THIS IN DEVELOPMENT TO RUN FROM LOCAL BUILD OF UI AND SERVER
### NOTE THE REPOSITORY ALWAYS RUNS AS A DOCKER CONTAINER
### NOTE:
### - to run on a Mac, use 5555 instead of 5000 for the server port
###

# Server config
Expand All @@ -12,7 +10,7 @@ REPOSITORY_PATH=../../data/repository
SOLC_REPO=../../data/solc-bin/linux-amd64
## Path where Solidity JS (solc-js) compilers will be saved
SOLJSON_REPO=../../data/solc-bin/soljson
SERVER_PORT=5000
SERVER_PORT=5002
## The fully qualified domain name of the host running the ui
## used by Server to configure allowed origins for CORS
UI_DOMAIN_NAME=localhost
Expand All @@ -23,7 +21,7 @@ UI_DOMAIN_NAME=localhost
## (resp. ui/public/config.json and h5ai-nginx/select-contract-form/public/config.json)
## - the 'server' uses the REPOSITORY_SERVER_URL env variable to return links to the various
## contract files.
#SERVER_URL=http://localhost:5000
SERVER_URL=http://localhost:5002
REPOSITORY_SERVER_URL=http://localhost:10000

# Docker config (only used for repository service in dev mode)
Expand All @@ -37,6 +35,7 @@ REPOSITORY_SERVER_EXTERNAL_PORT=10000
TESTING=false
TAG=latest
NODE_ENV=development
USE_LOCAL_NODE=true

# Needed to call create2 APIs, format is: TOKEN1,TOKEN2,...
CREATE2_CLIENT_TOKENS=
Expand Down
6 changes: 2 additions & 4 deletions environments/.env.docker.hedera
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
### USE THIS TO DEPLOY UI, SERVER & REPOSITORY RUNNING AS DOCKER CONTAINERS
### NOTE:
### - to deploy on a server, replace all occurences of 'localhost' by the fully qualified hostname
### - to deploy on a Mac, use 5555 instead of 5000 for the server port
###

# Server config
Expand All @@ -28,22 +27,21 @@ UI_DOMAIN_NAME=localhost
## h5ai-nginx/select-contract-form/public/config.json)
## - the 'server' uses the REPOSITORY_SERVER_URL env variable to return links to the various
## contract files.
#SERVER_URL=http://localhost:5000
#SERVER_URL=http://localhost:5002
REPOSITORY_SERVER_URL=http://localhost:10000

# Docker config
## Where to mount the downloaded compilers directory on the host machine
SOLC_REPO_HOST=../../data/solc-bin/linux-amd64
SOLJSON_REPO_HOST=../../data/solc-bin/soljson
## Ports to access containers from the host
SERVER_EXTERNAL_PORT=5000
SERVER_EXTERNAL_PORT=5002
UI_EXTERNAL_PORT=1234
REPOSITORY_SERVER_EXTERNAL_PORT=10000

# Other config
TESTING=false
TAG=latest
NODE_ENV=production

# Needed to call create2 APIs, format is: TOKEN1,TOKEN2,...
CREATE2_CLIENT_TOKENS=
3 changes: 1 addition & 2 deletions environments/.env.poc.hedera
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ REPOSITORY_SERVER_URL=https://repo.verify.simonvienot.fr
SOLC_REPO_HOST=../../data/solc-bin/linux-amd64
SOLJSON_REPO_HOST=../../data/solc-bin/soljson
## Ports to access containers from the host
SERVER_EXTERNAL_PORT=5000
SERVER_EXTERNAL_PORT=5002
UI_EXTERNAL_PORT=1234
REPOSITORY_SERVER_EXTERNAL_PORT=10000

# Other config
TESTING=false
TAG=latest
NODE_ENV=production

# Needed to call create2 APIs, format is: TOKEN1,TOKEN2,...
CREATE2_CLIENT_TOKENS=TESTTOKEN
2 changes: 1 addition & 1 deletion environments/example-docker-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SERVER_URL": "http://localhost:5555",
"SERVER_URL": "http://localhost:5002",
"REPOSITORY_SERVER_URL": "http://localhost:10000",
"HASHSCAN_URL": "https://hashscan-latest.hedera-devops.com"
}
2 changes: 1 addition & 1 deletion hedera-patch/h5ai-nginx.patch
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ new file mode 100644
+++ b/select-contract-form/public/config.json (date 1695221304211)
@@ -0,0 +1,3 @@
+ {
+ "SERVER_URL": "http://localhost:5555"
+ "SERVER_URL": "http://localhost:5002"
+ }
\ No newline at end of file
2 changes: 1 addition & 1 deletion nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ server {
}

location /server/ {
proxy_pass http://verify.simonvienot.fr:5000/;
proxy_pass http://verify.simonvienot.fr:5002/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sourcify-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ const sourcifyChainsExtensions: SourcifyChainsExtensionsObject = {
const sourcifyChainsMap: SourcifyChainMap = {};

// Add test chains too if developing or testing
if (process.env.NODE_ENV !== "production") {
if (process.env.USE_LOCAL_NODE === "true") {
for (const chain of LOCAL_CHAINS) {
sourcifyChainsMap[chain.chainId.toString()] = chain;
}
Expand All @@ -949,7 +949,7 @@ for (const i in allChains) {
if (chainId in sourcifyChainsMap) {
// Don't throw on local chains in development, override the chain.json item
if (
process.env.NODE_ENV !== "production" &&
process.env.USE_LOCAL_NODE === "true" &&
LOCAL_CHAINS.map((c) => c.chainId).includes(chainId)
) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion test/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require('dotenv').config({path: './environments/.env'});

describe('Basic non-regression of hedera-sourcify server', function () {

const SERVER_URL = process.env.SERVER_URL ?? "http://localhost:5000"
const SERVER_URL = process.env.SERVER_URL ?? "http://localhost:5002"
this.timeout(20000) // Overwrite Mocha timeout of 2sec -> 20sec

it('Should return correct verification status for newly created contract', async function () {
Expand Down
2 changes: 1 addition & 1 deletion ui/public/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SERVER_URL": "http://localhost:5555",
"SERVER_URL": "http://localhost:5002",
"REPOSITORY_SERVER_URL": "http://localhost:10000",
"HASHSCAN_URL": "https://hashscan-latest.hedera-devops.com"
}

0 comments on commit e6f8db2

Please sign in to comment.