apiVersion: v1
kind: ConfigMap
metadata:
  name: blockscout-config
  namespace: besu-network
data:
  DATABASE_URL: "postgresql://blockscout:blockscout@blockscout-db:5432/blockscout"
  ETHEREUM_JSONRPC_HTTP_URL: "http://besu-rpc:8545"
  ETHEREUM_JSONRPC_WS_URL: "ws://besu-rpc:8546"
  ETHEREUM_JSONRPC_TRACE_URL: "http://besu-rpc:8545"
  COIN: "ETH"
  NETWORK: "DeFi Oracle Meta Mainnet"
  SUBNETWORK: "Mainnet"
  LOGO: "/images/logo.png"
  LOGO_FOOTER: "/images/logo-footer.png"
  BLOCKSCOUT_VERSION: "v5.1.5"
  RELEASE_LINK: "https://github.com/blockscout/blockscout"
  BLOCK_TRANSFORMER: "base"
  CHAIN_ID: "138"
  SHOW_ADDRESS_MARKETCAP_PERCENTAGE: "true"
  ENABLE_ACCOUNT_BALANCE_CACHE: "true"
  ENABLE_EXCHANGE_RATES: "true"
  EXCHANGE_RATES_COINGECKO_COIN_ID: "ethereum"
  ENABLE_SOURCIFY_INTEGRATION: "true"
  SOURCIFY_SERVER_URL: "https://sourcify.dev/server"
  SOURCIFY_REPO_URL: "https://repo.sourcify.dev/contracts/full_match"
  ENABLE_TXS_STATS: "true"
  TXS_STATS_DAYS_TO_COMPILE_AT_INIT: "1"
  SUPPORTED_CHAINS: "[{\"title\":\"DeFi Oracle Meta Mainnet\",\"url\":\"https://explorer.d-bis.org\"}]"
  ENABLE_SOLIDITYSCAN: "true"
  SOLIDITYSCAN_API_URL: "http://solidityscan-integration:8080"
  SOLIDITYSCAN_AUTO_SCAN: "true"
  # MetaMask Portfolio CORS configuration
  CORS_ALLOWED_ORIGINS: "https://portfolio.metamask.io,https://metamask.io,https://chainlist.org"
  ENABLE_CORS: "true"
  ENABLE_TOKEN_METADATA_API: "true"
  TOKEN_METADATA_CACHE_ENABLED: "true"
  TOKEN_METADATA_CACHE_TTL: "3600"
  ENABLE_TOKEN_LOGO_SERVING: "true"
  TOKEN_LOGO_BASE_URL: "https://explorer.d-bis.org/images/tokens"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: blockscout
  namespace: besu-network
  labels:
    app: blockscout
spec:
  replicas: 1
  selector:
    matchLabels:
      app: blockscout
  template:
    metadata:
      labels:
        app: blockscout
    spec:
      containers:
        - name: blockscout
          image: blockscout/blockscout:v5.1.5
          ports:
            - name: http
              containerPort: 4000
          envFrom:
            - configMapRef:
                name: blockscout-config
          env:
            - name: SECRET_KEY_BASE
              valueFrom:
                secretKeyRef:
                  name: blockscout-secrets
                  key: secret_key_base
          resources:
            requests:
              cpu: "1"
              memory: "2Gi"
            limits:
              cpu: "2"
              memory: "4Gi"
          livenessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 60
            periodSeconds: 30
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
      initContainers:
        - name: db-migration
          image: blockscout/blockscout:v5.1.5
          command: ["/bin/sh", "-c", "mix ecto.migrate"]
          envFrom:
            - configMapRef:
                name: blockscout-config
          env:
            - name: SECRET_KEY_BASE
              valueFrom:
                secretKeyRef:
                  name: blockscout-secrets
                  key: secret_key_base
---
apiVersion: v1
kind: Service
metadata:
  name: blockscout
  namespace: besu-network
  labels:
    app: blockscout
spec:
  type: ClusterIP
  ports:
    - port: 4000
      targetPort: http
      protocol: TCP
  selector:
    app: blockscout
---
# Secret should be created using: kubectl create secret generic blockscout-secrets --from-literal=secret_key_base=$(openssl rand -hex 32) -n besu-network
# Or use scripts/generate-secrets.sh
# apiVersion: v1
# kind: Secret
# metadata:
#   name: blockscout-secrets
#   namespace: besu-network
# type: Opaque
# stringData:
#   secret_key_base: "change-me-in-production"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: blockscout-db
  namespace: besu-network
  labels:
    app: blockscout-db
spec:
  serviceName: blockscout-db
  replicas: 1
  selector:
    matchLabels:
      app: blockscout-db
  template:
    metadata:
      labels:
        app: blockscout-db
    spec:
      containers:
        - name: postgres
          image: postgres:15
          ports:
            - name: postgres
              containerPort: 5432
          env:
            - name: POSTGRES_USER
              value: "blockscout"
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: blockscout-db-secrets
                  key: postgres_password
            - name: POSTGRES_DB
              value: "blockscout"
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql/data
          resources:
            requests:
              cpu: "500m"
              memory: "1Gi"
            limits:
              cpu: "2"
              memory: "4Gi"
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: managed-premium
        resources:
          requests:
            storage: 100Gi
---
apiVersion: v1
kind: Service
metadata:
  name: blockscout-db
  namespace: besu-network
  labels:
    app: blockscout-db
spec:
  type: ClusterIP
  ports:
    - port: 5432
      targetPort: postgres
      protocol: TCP
  selector:
    app: blockscout-db
---
# Secret should be created using: kubectl create secret generic blockscout-db-secrets --from-literal=postgres_password=$(openssl rand -base64 32) -n besu-network
# Or use scripts/generate-secrets.sh
# apiVersion: v1
# kind: Secret
# metadata:
#   name: blockscout-db-secrets
#   namespace: besu-network
# type: Opaque
# stringData:
#   postgres_password: "change-me-in-production"

