chore: ability to work with Blockscout code base within a VSCode devcontainer (#10838)
Introduce dev container for streamlined Blockscout development - Add .devcontainer setup with pre-configured Elixir, Phoenix, and Node.js - Include PostgreSQL service in docker-compose.yml - Configure VS Code extensions and settings in devcontainer.json - Add bs script for common development tasks - Provide .blockscout_config.example for easy configuration - Enable GitHub Codespaces support for cloud-based development This change aims to reduce setup time, ensure consistency across environments, and allow developers to focus on core development tasks.pull/10885/head
parent
903cbe3901
commit
3a8e9f4e66
@ -0,0 +1,67 @@ |
||||
CHAIN_TYPE=ethereum |
||||
|
||||
ETHEREUM_JSONRPC_VARIANT=geth |
||||
ETHEREUM_JSONRPC_TRACE_URL="" |
||||
|
||||
API_RATE_LIMIT=100 |
||||
HEART_BEAT_TIMEOUT=30 |
||||
TXS_STATS_DAYS_TO_COMPILE_AT_INIT=2 |
||||
INDEXER_MEMORY_LIMIT=6 |
||||
|
||||
POOL_SIZE=50 |
||||
POOL_SIZE_API=50 |
||||
ACCOUNT_POOL_SIZE=10 |
||||
|
||||
INDEXER_DISABLE_EMPTY_BLOCKS_SANITIZER='true' |
||||
INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER='true' |
||||
INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER='true' |
||||
INDEXER_DISABLE_BLOCK_REWARD_FETCHER='true' |
||||
INDEXER_DISABLE_ADDRESS_COIN_BALANCE_FETCHER='true' |
||||
INDEXER_DISABLE_CATALOGED_TOKEN_UPDATER_FETCHER='true' |
||||
ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES='true' |
||||
INDEXER_DISABLE_TOKEN_INSTANCE_RETRY_FETCHER='true' |
||||
INDEXER_DISABLE_TOKEN_INSTANCE_REALTIME_FETCHER='true' |
||||
INDEXER_DISABLE_TOKEN_INSTANCE_SANITIZE_FETCHER='true' |
||||
INDEXER_DISABLE_WITHDRAWALS_FETCHER='true' |
||||
INDEXER_DISABLE_TOKEN_INSTANCE_LEGACY_SANITIZE_FETCHER='true' |
||||
|
||||
INDEXER_CATCHUP_BLOCKS_BATCH_SIZE=5 |
||||
INDEXER_COIN_BALANCES_BATCH_SIZE=1 |
||||
TOKEN_ID_MIGRATION_BATCH_SIZE=1 |
||||
TOKEN_INSTANCE_OWNER_MIGRATION_BATCH_SIZE=1 |
||||
INDEXER_EMPTY_BLOCKS_SANITIZER_BATCH_SIZE=1 |
||||
INDEXER_BLOCK_REWARD_BATCH_SIZE=1 |
||||
INDEXER_RECEIPTS_BATCH_SIZE=10 |
||||
INDEXER_COIN_BALANCES_BATCH_SIZE=1 |
||||
INDEXER_TOKEN_BALANCES_BATCH_SIZE=1 |
||||
|
||||
INDEXER_CATCHUP_BLOCKS_CONCURRENCY=1 |
||||
TOKEN_INSTANCE_OWNER_MIGRATION_CONCURRENCY=1 |
||||
INDEXER_BLOCK_REWARD_CONCURRENCY=1 |
||||
INDEXER_RECEIPTS_CONCURRENCY=1 |
||||
INDEXER_COIN_BALANCES_CONCURRENCY=1 |
||||
INDEXER_TOKEN_CONCURRENCY=1 |
||||
INDEXER_TOKEN_BALANCES_CONCURRENCY=1 |
||||
INDEXER_TOKEN_INSTANCE_RETRY_CONCURRENCY=1 |
||||
INDEXER_TOKEN_INSTANCE_REALTIME_CONCURRENCY=1 |
||||
INDEXER_TOKEN_INSTANCE_SANITIZE_CONCURRENCY=1 |
||||
INDEXER_TOKEN_INSTANCE_LEGACY_SANITIZE_CONCURRENCY=1 |
||||
INDEXER_TOKEN_INSTANCE_RETRY_BATCH_SIZE=1 |
||||
INDEXER_TOKEN_INSTANCE_REALTIME_BATCH_SIZE=1 |
||||
INDEXER_TOKEN_INSTANCE_SANITIZE_BATCH_SIZE=1 |
||||
INDEXER_TOKEN_INSTANCE_LEGACY_SANITIZE_BATCH_SIZE=1 |
||||
|
||||
INDEXER_TOKEN_BALANCES_FETCHER_INIT_QUERY_LIMIT=2 |
||||
INDEXER_COIN_BALANCES_FETCHER_INIT_QUERY_LIMIT=2 |
||||
|
||||
DISABLE_EXCHANGE_RATES='true' |
||||
SOURCIFY_INTEGRATION_ENABLED='false' |
||||
EXCHANGE_RATES_COINGECKO_PLATFORM_ID='' |
||||
DISABLE_TOKEN_EXCHANGE_RATE='true' |
||||
|
||||
API_V2_ENABLED=true |
||||
|
||||
DISABLE_CATCHUP_INDEXER='false' |
||||
INDEXER_CATCHUP_BLOCKS_BATCH_SIZE=10 |
||||
INDEXER_CATCHUP_BLOCKS_CONCURRENCY=10 |
||||
ETHEREUM_JSONRPC_HTTP_URL="https://ethereum-sepolia-rpc.publicnode.com" |
@ -0,0 +1,50 @@ |
||||
# Since this is a copy of https://github.com/blockscout/devcontainer-elixir/blob/main/Dockerfile |
||||
# So after successful testing this file, the original one must be updated as well. |
||||
ARG VARIANT="1.17.3-erlang-27.1-debian-bullseye-20240926" |
||||
FROM hexpm/elixir:${VARIANT} |
||||
|
||||
# ARGs declared before FROM are not persisted beyond the FROM instruction. |
||||
# They must be redeclared here to be available in the rest of the Dockerfile. |
||||
ARG PHOENIX_VERSION="1.7.10" |
||||
ARG NODE_VERSION="18" |
||||
|
||||
# This Dockerfile adds a non-root user with sudo access. Update the “remoteUser” property in |
||||
# devcontainer.json to use it. More info: https://aka.ms/vscode-remote/containers/non-root-user. |
||||
ARG USERNAME=vscode |
||||
ARG USER_UID=1000 |
||||
ARG USER_GID=$USER_UID |
||||
|
||||
# Options for common package install script |
||||
ARG INSTALL_ZSH="true" |
||||
ARG UPGRADE_PACKAGES="true" |
||||
ARG COMMON_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-debian.sh" |
||||
|
||||
# Options for setup nodejs |
||||
ARG NODE_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/node-debian.sh" |
||||
ENV NVM_DIR=/usr/local/share/nvm |
||||
ENV NVM_SYMLINK_CURRENT=true |
||||
ENV PATH=${NVM_DIR}/current/bin:${PATH} |
||||
|
||||
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. |
||||
RUN apt-get update \ |
||||
&& export DEBIAN_FRONTEND=noninteractive \ |
||||
&& apt-get -y install --no-install-recommends curl ca-certificates 2>&1 \ |
||||
&& curl -sSL ${COMMON_SCRIPT_SOURCE} -o /tmp/common-setup.sh \ |
||||
&& /bin/bash /tmp/common-setup.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \ |
||||
# |
||||
# Install Node.js for use with web applications |
||||
&& curl -sSL ${NODE_SCRIPT_SOURCE} -o /tmp/node-setup.sh \ |
||||
&& /bin/bash /tmp/node-setup.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \ |
||||
&& npm install -g cspell@latest \ |
||||
# |
||||
# Install dependencies |
||||
&& apt-get install -y build-essential inotify-tools \ |
||||
# |
||||
# Clean up |
||||
&& apt-get autoremove -y \ |
||||
&& apt-get clean -y \ |
||||
&& rm -rf /var/lib/apt/lists/* /tmp/common-setup.sh /tmp/node-setup.sh |
||||
|
||||
RUN su ${USERNAME} -c "mix local.hex --force \ |
||||
&& mix local.rebar --force \ |
||||
&& mix archive.install --force hex phx_new ${PHOENIX_VERSION}" |
@ -0,0 +1,199 @@ |
||||
# Blockscout Backend Development with VSCode Devcontainers and GitHub Codespaces |
||||
|
||||
## Table of Contents |
||||
1. [Motivation](#motivation) |
||||
2. [Setting Up VSCode Devcontainer Locally](#setting-up-vscode-devcontainer-locally) |
||||
3. [Using GitHub Codespaces in the Browser](#using-github-codespaces-in-the-browser) |
||||
4. [Configuring Postgres DB Access](#configuring-postgres-db-access) |
||||
5. [Developing Blockscout Backend](#developing-blockscout-backend) |
||||
6. [Upgrading Elixir Version](#upgrading-elixir-version) |
||||
7. [Contributing](#contributing) |
||||
|
||||
## Motivation |
||||
|
||||
Setting up a local development environment for Blockscout can be time-consuming and error-prone. This devcontainer setup streamlines the process by providing a pre-configured environment with all necessary dependencies. It ensures consistency across development environments, reduces setup time, and allows developers to focus on coding rather than configuration. |
||||
|
||||
Key benefits include: |
||||
- Pre-configured environment with Elixir, Phoenix, and Node.js |
||||
- Integrated PostgreSQL database |
||||
- Essential VS Code extensions pre-installed |
||||
- Simplified database management |
||||
- Consistent development environment across team members |
||||
|
||||
## Setting Up VSCode Devcontainer Locally |
||||
|
||||
1. Clone the Blockscout repository: |
||||
``` |
||||
git clone https://github.com/blockscout/blockscout.git |
||||
cd blockscout |
||||
``` |
||||
|
||||
2. Open the project in VS Code: |
||||
``` |
||||
code . |
||||
``` |
||||
|
||||
3. Before re-opening in the container, you may find it useful to configure SSH authorization. To do this: |
||||
|
||||
a. Ensure you have SSH access to GitHub configured on your local machine. |
||||
|
||||
b. Open `.devcontainer/devcontainer.json`. |
||||
|
||||
c. Uncomment the `mounts` section: |
||||
```json |
||||
"mounts": [ |
||||
"source=${localEnv:HOME}/.ssh/known_hosts,target=/home/vscode/.ssh/known_hosts,type=bind,consistency=cached", |
||||
"source=${localEnv:HOME}/.ssh/config,target=/home/vscode/.ssh/config,type=bind,consistency=cached", |
||||
"source=${localEnv:HOME}/.ssh/id_rsa,target=/home/vscode/.ssh/id_rsa,type=bind,consistency=cached" |
||||
], |
||||
``` |
||||
|
||||
d. Adjust the paths if your SSH keys are stored in a different location. |
||||
|
||||
4. When prompted, click "Reopen in Container". If not prompted, press `F1`, type "Remote-Containers: Reopen in Container", and press Enter. |
||||
|
||||
5. VS Code will build the devcontainer. This process includes: |
||||
- Pulling the base Docker image |
||||
- Installing specified VS Code extensions |
||||
- Setting up the PostgreSQL database |
||||
- Installing project dependencies |
||||
|
||||
This may take several minutes the first time. |
||||
|
||||
6. Once the devcontainer is built, you'll be working inside the containerized environment. |
||||
|
||||
7. If you modified the `devcontainer.json` file in step 3, you may want to execute `git update-index --assume-unchanged .devcontainer/devcontainer.json` in a terminal within your devcontainer to prevent the changes to `devcontainer.json` from appearing in `git status` and VS Code's Source Control. |
||||
|
||||
### Additional Setup for Cursor.ai Users |
||||
|
||||
If you're using Cursor.ai instead of VSCode, you may need to perform some additional setup steps. Please note that these changes will not persist after reloading the devcontainer, so you may need to repeat these steps each time you start a new session. |
||||
|
||||
1. **Git Configuration**: You may encounter issues when trying to perform Git operations from the terminal or the "Source Control" tab. To resolve this, set up your Git configuration inside the devcontainer: |
||||
|
||||
a. Open a terminal in your devcontainer. |
||||
b. Set your Git username: |
||||
``` |
||||
git config --global user.name "Your Name" |
||||
``` |
||||
c. Set your Git email: |
||||
``` |
||||
git config --global user.email "your.email@example.com" |
||||
``` |
||||
|
||||
Replace "Your Name" and "your.email@example.com" with your actual name and email associated with your GitHub account. |
||||
|
||||
2. **ElixirLS: Elixir support and debugger** (JakeBecker.elixir-ls): This extension may not be automatically installed in Cursor.ai, even though it's specified in the devcontainer configuration. To install it manually: |
||||
|
||||
a. Open the Extensions tab. |
||||
b. Search for "JakeBecker.elixir-ls". |
||||
c. Look for the extension "ElixirLS: Elixir support and debugger" by JakeBecker and click "Install". |
||||
|
||||
Remember, you may need to repeat these steps each time you start a new Cursor.ai session with the devcontainer. |
||||
|
||||
### Signing in to GitHub for Pull Request Extension |
||||
|
||||
1. In the devcontainer, click on the GitHub icon in the Primary sidebar. |
||||
2. Click on "Sign in to GitHub" and follow the prompts to authenticate. |
||||
|
||||
## Using GitHub Codespaces in the Browser |
||||
|
||||
To open the project in GitHub Codespaces: |
||||
|
||||
1. Navigate to the Blockscout repository on GitHub. |
||||
2. Switch to the branch you want to work on. |
||||
3. Click the "Code" button. |
||||
4. Instead of clicking "Create codespace on [branch]" (which would use the default machine type that may not be sufficient for this Elixir-based project), click on the three dots (...) next to it. |
||||
5. Select "New with options". |
||||
6. Choose the "4-core/16GB RAM" machine type for optimal performance. |
||||
7. Click "Create codespace". |
||||
|
||||
This will create a new Codespace with the specified resources, ensuring adequate performance for the Elixir-based project. |
||||
|
||||
Note: After the container opens, you may see an error about the inability to use "GitHub Copilot Chat". This Copilot functionality will not be accessible in the Codespace environment. |
||||
|
||||
## Configuring Postgres DB Access |
||||
|
||||
To configure access to the PostgreSQL database using the VS Code extension: |
||||
|
||||
1. Click on the PostgreSQL icon in the Primary sidebar. |
||||
2. Click "+" (Add Connection) in the PostgreSQL explorer. |
||||
3. Use the following details: |
||||
- Host: `db` |
||||
- User: `postgres` |
||||
- Password: `postgres` |
||||
- Port: `5432` |
||||
- Use an ssl connection: "Standard connection" |
||||
- Database: `blockscout` |
||||
- The display name: "<some name>" |
||||
|
||||
These credentials are derived from the `DATABASE_URL` in the `bs` script. |
||||
|
||||
## Developing Blockscout Backend |
||||
|
||||
### Configuration |
||||
|
||||
Before running the Blockscout server, you need to set up the configuration: |
||||
|
||||
1. Copy the `.devcontainer/.blockscout_config.example` file to `.devcontainer/.blockscout_config`. |
||||
2. Adjust the settings in `.devcontainer/.blockscout_config` as needed for your development environment. |
||||
|
||||
For a comprehensive list of environment variables that can be set in this configuration file, refer to the [Blockscout documentation](https://docs.blockscout.com/setup/env-variables). |
||||
|
||||
### Using the `bs` Script |
||||
|
||||
The `bs` script in `.devcontainer/bin/` helps orchestrate common development tasks. Here are some key commands: |
||||
|
||||
- Initialize the project: `bs --init` |
||||
- Initialize or re-initialize the database: `bs --db-init` (This will remove all data and tables from the DB and re-create the tables) |
||||
- Run the server: `bs` |
||||
- Run the server without syncing: `bs --no-sync` |
||||
- Recompile the project: `bs --recompile` (Use this when new dependencies arrive after a merge or when switching to another `CHAIN_TYPE`) |
||||
- Run various checks: `bs --spellcheck`, `bs --dialyzer`, `bs --credo`, `bs --format` |
||||
|
||||
For a full list of options, run `bs --help`. |
||||
|
||||
### Interacting with the Blockscout API |
||||
|
||||
For local devcontainer setups (not applicable to GitHub Codespaces), you can use API testing tools like Postman or Insomnia on your host machine to interact with the Blockscout API running in the container: |
||||
|
||||
1. Ensure the Blockscout server is running in the devcontainer. |
||||
2. In the API testing tool on your host machine, use `http://127.0.0.1:4000` as the base URL. |
||||
3. Example endpoint: `GET http://127.0.0.1:4000/api/v2/blocks` |
||||
|
||||
This allows testing API endpoints directly from your host machine while the server runs in the container. |
||||
|
||||
### Troubleshooting |
||||
|
||||
If you face issues with dependency compilation or dialyzer after container creation: |
||||
|
||||
1. Check for untracked files: `git ls-files --others` |
||||
2. Remove compilation artifacts or generated files if present. |
||||
3. For persistent issues, consider cleaning all untracked files (use with caution): |
||||
``` |
||||
git clean -fdX |
||||
bs --recompile |
||||
``` |
||||
|
||||
This ensures a clean compilation environment within the container. |
||||
|
||||
## Upgrading Elixir Version |
||||
|
||||
To upgrade the Elixir version: |
||||
|
||||
1. Open `.devcontainer/Dockerfile`. |
||||
2. Update the `VARIANT` argument with the desired Elixir version. |
||||
3. Rebuild the devcontainer. |
||||
|
||||
Note: Ensure that the version you choose is compatible with the project dependencies. |
||||
|
||||
After testing the new Elixir version, propagate the corresponding changes in the Dockerfile to the repo https://github.com/blockscout/devcontainer-elixir. Once a new release tag is published there and a new docker image `ghcr.io/blockscout/devcontainer-elixir` appears in the GitHub registry, modify the `docker-compose.yml` file in the `.devcontainer` directory to reflect the proper docker image tag. |
||||
|
||||
## Contributing |
||||
|
||||
When contributing changes that require additional checks for specific blockchain types: |
||||
|
||||
1. Open `.devcontainer/bin/chain-specific-checks`. |
||||
2. Add your checks under the appropriate `CHAIN_TYPE` case. |
||||
3. Ensure your checks exit with a non-zero code if unsuccessful. |
||||
|
||||
Remember to document any new checks or configuration options in this README. |
@ -0,0 +1,237 @@ |
||||
#!/bin/bash |
||||
|
||||
# This script helps to orchestrate typical tasks when developing Blockscout |
||||
|
||||
source $(dirname $0)/utils |
||||
|
||||
# cd $(dirname $0)/../../ |
||||
|
||||
# Source and exaport environment variables related to the backend configuration |
||||
BLOCKSCOUT_CONFIG_FILE=".devcontainer/.blockscout_config" |
||||
if [ -f "./${BLOCKSCOUT_CONFIG_FILE}" ]; then |
||||
set -a # Automatically export all variables |
||||
source ./${BLOCKSCOUT_CONFIG_FILE} |
||||
set +a # Disable automatic export |
||||
else |
||||
echo "Warning: ${BLOCKSCOUT_CONFIG_FILE} file not found. Skipping configuration loading." |
||||
fi |
||||
|
||||
if [ "${DATABASE_URL}" == "" ]; then |
||||
export DATABASE_URL="postgresql://postgres:postgres@db:5432/blockscout" |
||||
fi |
||||
|
||||
# Initialize variables |
||||
INIT=false |
||||
NO_SYNC=false |
||||
DB_INIT=false |
||||
RECOMPILE=false |
||||
SPELLCHECK=false |
||||
DIALYZER=false |
||||
CREDO=false |
||||
FORMAT=false |
||||
DOCS=false |
||||
HELP=false |
||||
|
||||
# Parse command line arguments |
||||
for arg in "$@" |
||||
do |
||||
case $arg in |
||||
--help) |
||||
HELP=true |
||||
shift # Remove --help from processing |
||||
;; |
||||
--init) |
||||
INIT=true |
||||
shift # Remove --init from processing |
||||
;; |
||||
--no-sync) |
||||
NO_SYNC=true |
||||
shift # Remove --no-sync from processing |
||||
;; |
||||
--db-init) |
||||
DB_INIT=true |
||||
shift # Remove --db-init from processing |
||||
;; |
||||
--recompile) |
||||
RECOMPILE=true |
||||
shift # Remove --recompile from processing |
||||
;; |
||||
--spellcheck) |
||||
SPELLCHECK=true |
||||
shift # Remove --spellcheck from processing |
||||
;; |
||||
--dialyzer) |
||||
DIALYZER=true |
||||
shift # Remove --dialyzer from processing |
||||
;; |
||||
--credo) |
||||
CREDO=true |
||||
shift # Remove --credo from processing |
||||
;; |
||||
--format) |
||||
FORMAT=true |
||||
shift # Remove --format from processing |
||||
;; |
||||
--docs) |
||||
DOCS=true |
||||
shift # Remove --docs from processing |
||||
;; |
||||
esac |
||||
done |
||||
|
||||
# Define the help function |
||||
show_help() { |
||||
echo "Usage: bs [OPTION]" |
||||
echo "Orchestrate typical tasks when developing Blockscout backend server" |
||||
echo |
||||
echo "Options:" |
||||
echo " --help Show this help message and exit" |
||||
echo " --init Initialize the project directory" |
||||
echo " --format Run code formatter" |
||||
echo " --spellcheck Run spellcheck" |
||||
echo " --dialyzer Run dialyzer" |
||||
echo " --credo Run credo" |
||||
echo " --docs Generate documentation" |
||||
echo " --recompile Re-fetch dependencies and recompile" |
||||
echo " --db-init (Re)initialize the database" |
||||
echo " --no-sync Run the server with disabled indexer, so only the API is available" |
||||
echo |
||||
echo "If no option is provided, the script will run the backend server." |
||||
} |
||||
|
||||
# If --help argument is passed, show help and exit |
||||
if [ "$HELP" = true ]; then |
||||
show_help |
||||
exit 0 |
||||
fi |
||||
|
||||
# Define the project directory initialization subroutine |
||||
initialize_project() { |
||||
if [ ! -d "apps/block_scout_web/priv/cert" ]; then |
||||
mix local.rebar --force |
||||
mix deps.compile |
||||
mix compile |
||||
|
||||
# cd apps/block_scout_web/assets |
||||
# npm install && node_modules/webpack/bin/webpack.js --mode production |
||||
# cd - |
||||
# cd apps/explorer |
||||
# npm install |
||||
# cd - |
||||
|
||||
cd apps/block_scout_web |
||||
mix phx.gen.cert blockscout blockscout.local |
||||
cd - |
||||
else |
||||
echo "Looks like the project directory is already initialized" |
||||
fi |
||||
} |
||||
|
||||
# Define the initialization subroutine |
||||
initialize_db() { |
||||
echo "Initializing database. Step 1 of 2: Dropping database" |
||||
mix ecto.drop > /dev/null 2>&1 |
||||
echo "Initializing database. Step 2 of 2: Creating database" |
||||
mix do ecto.create, ecto.migrate | grep Runn |
||||
} |
||||
|
||||
# Define the recompile subroutine |
||||
recompile() { |
||||
mix deps.clean block_scout_web |
||||
mix deps.clean explorer |
||||
mix deps.clean indexer |
||||
mix deps.get |
||||
mix deps.compile --force |
||||
} |
||||
|
||||
# Define the spellcheck subroutine |
||||
spellcheck() { |
||||
cspell --config cspell.json "**/*.ex*" "**/*.eex" "**/*.js" --gitignore | less |
||||
} |
||||
|
||||
# Define the dialyzer subroutine |
||||
dialyzer() { |
||||
mix dialyzer |
||||
} |
||||
|
||||
# Define the credo subroutine |
||||
credo() { |
||||
mix credo |
||||
} |
||||
|
||||
# Define the format subroutine |
||||
format() { |
||||
mix format |
||||
} |
||||
|
||||
# Define the generate_docs subroutine |
||||
generate_docs() { |
||||
mix docs |
||||
} |
||||
|
||||
# If --init argument is passed, run the project dir initialization subroutine and exit |
||||
if [ "$INIT" = true ]; then |
||||
initialize_project |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --db-init argument is passed, run the database initialization subroutine and exit |
||||
if [ "$DB_INIT" = true ]; then |
||||
initialize_db |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --recompile argument is passed, run the recompile subroutine and exit |
||||
if [ "$RECOMPILE" = true ]; then |
||||
recompile |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --spellcheck argument is passed, run the spellcheck subroutine and exit |
||||
if [ "$SPELLCHECK" = true ]; then |
||||
spellcheck |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --dialyzer argument is passed, run the dialyzer subroutine and exit |
||||
if [ "$DIALYZER" = true ]; then |
||||
dialyzer |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --credo argument is passed, run the credo subroutine and exit |
||||
if [ "$CREDO" = true ]; then |
||||
credo |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --format argument is passed, run the format subroutine and exit |
||||
if [ "$FORMAT" = true ]; then |
||||
format |
||||
exit 0 |
||||
fi |
||||
|
||||
# If --doc argument is passed, run the format subroutine and exit |
||||
if [ "$DOCS" = true ]; then |
||||
generate_docs |
||||
exit 0 |
||||
fi |
||||
|
||||
if [ "${ETHEREUM_JSONRPC_HTTP_URL}" != "" ]; then |
||||
check_server_availability ${ETHEREUM_JSONRPC_HTTP_URL} |
||||
check_server_accessibility ${ETHEREUM_JSONRPC_HTTP_URL} |
||||
fi |
||||
|
||||
if [ "${CHAIN_TYPE}" != "" -o "${CHAIN_TYPE}" != "ethereum" -o "${CHAIN_TYPE}" != "default" ]; then |
||||
source $(dirname $0)/chain-specific-checks |
||||
fi |
||||
|
||||
if [ ! -d "apps/block_scout_web/priv/cert" ]; then |
||||
echo "Project directory is not initialized" |
||||
echo "Run 'bs --init' to initialize the project directory" |
||||
exit 1 |
||||
fi |
||||
|
||||
export DISABLE_INDEXER=${NO_SYNC} |
||||
|
||||
mix phx.server |
@ -0,0 +1,17 @@ |
||||
# The script is sourced from the main script, so the unsuccessful check must exit |
||||
# with non-zero code to terminate the main script. |
||||
|
||||
source $(dirname $0)/utils |
||||
|
||||
# Run the appropriate checks based on CHAIN_TYPE |
||||
case "${CHAIN_TYPE}" in |
||||
"arbitrum") |
||||
echo "Arbitrum sepcific checks" |
||||
# if the check is not successful, exit with code 1 |
||||
check_server_availability ${INDEXER_ARBITRUM_L1_RPC} |
||||
check_server_accessibility ${INDEXER_ARBITRUM_L1_RPC} |
||||
;; |
||||
*) |
||||
echo "No special checks for CHAIN_TYPE: $CHAIN_TYPE" |
||||
;; |
||||
esac |
@ -0,0 +1,22 @@ |
||||
# Function to check server availability |
||||
check_server_availability() { |
||||
local url=$1 |
||||
|
||||
curl --connect-timeout 3 --silent ${url} 1>/dev/null |
||||
if [ $? -ne 0 ]; then |
||||
echo "VPN must be enabled to connect to ${url}" |
||||
exit 1 |
||||
fi |
||||
} |
||||
|
||||
# Function to check server accessibility with a POST request |
||||
check_server_accessibility() { |
||||
local url=$1 |
||||
local payload='[{"id":0,"params":["latest",false],"method":"eth_getBlockByNumber","jsonrpc":"2.0"}]' |
||||
|
||||
http_code=$(curl -s -o /dev/null -w "%{http_code}" -X POST ${url} -H "Content-Type: application/json" -d "${payload}") |
||||
if [ "$http_code" -ne 200 ]; then |
||||
echo "VPN must be enabled to access ${url} (HTTP status code: ${http_code})" |
||||
exit 1 |
||||
fi |
||||
} |
@ -0,0 +1,47 @@ |
||||
{ |
||||
"name": "Blockscout Elixir", |
||||
"dockerComposeFile": "docker-compose.yml", |
||||
"service": "elixir", |
||||
"workspaceFolder": "/workspace", |
||||
"postCreateCommand": { |
||||
"safe-directory": "git config --global --add safe.directory ${containerWorkspaceFolder}", |
||||
"deps": "mix deps.get" |
||||
}, |
||||
"remoteEnv": { |
||||
"PATH": "${containerEnv:PATH}:${containerWorkspaceFolder}/.devcontainer/bin" |
||||
}, |
||||
// Configure tool-specific properties. |
||||
"customizations": { |
||||
// Configure properties specific to VS Code. |
||||
"vscode": { |
||||
// Add the IDs of extensions you want installed when the container is created. |
||||
"extensions": [ |
||||
"JakeBecker.elixir-ls", |
||||
"ckolkman.vscode-postgres", |
||||
"GitHub.copilot", |
||||
"GitHub.copilot-chat", |
||||
"GitHub.vscode-pull-request-github" |
||||
] |
||||
} |
||||
}, |
||||
"features": { |
||||
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {} |
||||
}, |
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally. |
||||
// This can be used to network with other containers or with the host. |
||||
"forwardPorts": [ |
||||
4000, |
||||
4001, |
||||
5432 |
||||
], |
||||
// Uncomment and adjust the private key path to the one you use to authenticate on GitHub |
||||
// if you want to have ability to push to GitHub from the container. |
||||
// "mounts": [ |
||||
// "source=${localEnv:HOME}/.ssh/known_hosts,target=/home/vscode/.ssh/known_hosts,type=bind,consistency=cached", |
||||
// "source=${localEnv:HOME}/.ssh/config,target=/home/vscode/.ssh/config,type=bind,consistency=cached", |
||||
// // Make sure that the private key can be used to authenticate on GitHub |
||||
// "source=${localEnv:HOME}/.ssh/id_rsa,target=/home/vscode/.ssh/id_rsa,type=bind,consistency=cached" |
||||
// ], |
||||
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. |
||||
"remoteUser": "vscode" |
||||
} |
@ -0,0 +1,30 @@ |
||||
services: |
||||
elixir: |
||||
image: ghcr.io/blockscout/devcontainer-elixir:1.17.3-erlang-27.1 |
||||
|
||||
# Uncomment next lines to use test Dockerfile with new Elixir version |
||||
# build: |
||||
# context: . |
||||
# dockerfile: Dockerfile |
||||
|
||||
volumes: |
||||
- ..:/workspace:cached |
||||
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. |
||||
network_mode: service:db |
||||
|
||||
# Overrides default command so things don't shut down after the process ends. |
||||
command: sleep infinity |
||||
|
||||
db: |
||||
image: postgres:latest |
||||
command: postgres -c 'max_connections=250' |
||||
restart: unless-stopped |
||||
volumes: |
||||
- postgres-data:/var/lib/postgresql/data |
||||
environment: |
||||
POSTGRES_USER: postgres |
||||
POSTGRES_PASSWORD: postgres |
||||
POSTGRES_DB: app |
||||
|
||||
volumes: |
||||
postgres-data: |
Loading…
Reference in new issue