From 9481bd29d04ac511e920a29b3cc95fca0c20062a Mon Sep 17 00:00:00 2001 From: Wil Wade Date: Wed, 3 Apr 2024 13:06:34 -0400 Subject: [PATCH] Docker Published to GitHub (#13) ## Goal The goal of this PR is to publish docker images to GitHub ## Checklist - [x] PR Self-Review and Commenting - [x] Docs updated - [x] Tests added ## How To Test the Changes - Test Run: https://github.com/frequency-chain/testnet-faucet/actions/runs/8527012881 - Package Details: https://github.com/frequency-chain/testnet-faucet/pkgs/container/testnet-faucet --------- Co-authored-by: Dmitri <4452412+demisx@users.noreply.github.com> --- .env.example | 19 +++------ .github/workflows/merge-pr.yml | 50 +++++++++++++++++++++++ Dockerfile | 2 +- README.md | 9 ++-- docker/docker-compose.rococo-external.yml | 13 ------ docker/docker-compose.rococo.yml | 13 ------ e2e/bootstrap.sh | 4 +- env.faucet.config.json | 32 +-------------- src/bot/index.ts | 5 +-- 9 files changed, 64 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/merge-pr.yml delete mode 100644 docker/docker-compose.rococo-external.yml delete mode 100644 docker/docker-compose.rococo.yml diff --git a/.env.example b/.env.example index f9d7d6f6..1dab70eb 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -SMF_CONFIG_NETWORK="rococo" +SMF_CONFIG_NETWORK="frequencyRococo" SMF_CONFIG_PORT=5555 SMF_CONFIG_DEPLOYED_REF=local @@ -9,26 +9,19 @@ SMF_CONFIG_DEPLOYED_REF=local # 3. Click the "Help & About" tab (left side of the dialog). # 4. Scroll to the bottom and click on part of Access Token. # Note: Keep the browser login active as the token will be invalidated once you logout -SMF_CONFIG_MATRIX_ACCESS_TOKEN="NotValidExampleToken" +# SMF_CONFIG_MATRIX_ACCESS_TOKEN="NotValidExampleToken" # See https://github.com/paritytech/devops/wiki/Matrix%3A-Registering-a-Matrix-Bot for how to register a bot # Note: The bot account needs to be created in SMF_BOT_MATRIX_SERVER -SMF_CONFIG_MATRIX_BOT_USER_ID="@NotValidExampleAccount:matrix.parity.io" -SMF_CONFIG_FAUCET_IGNORE_LIST="" -SMF_CONFIG_MATRIX_SERVER=https://m.parity.io +# SMF_CONFIG_MATRIX_BOT_USER_ID="@NotValidExampleAccount:matrix.parity.io" +# SMF_CONFIG_FAUCET_IGNORE_LIST="" +# SMF_CONFIG_MATRIX_SERVER=https://m.parity.io # To get account mnemonic - create an account in https://polkadot.js.org/apps/#/accounts (save details in password manager) # Prior creating, make sure to switch to according network (in case of westend - TEST WESTEND & PARACHAINS => Westend) # To feed new account with test tokens, go to https://matrix.to/#/#westend_faucet:matrix.org and drip to new address # some convenient for tests amount "!drip
" -SMF_CONFIG_FAUCET_ACCOUNT_MNEMONIC="this is a fake mnemonic" +SMF_CONFIG_FAUCET_ACCOUNT_MNEMONIC="//Alice" # Only used with external access SMF_CONFIG_RECAPTCHA_SECRET="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe" # Public testing secret, will accept all tokens. - -# Database -SMF_CONFIG_DB_HOST=localhost -SMF_CONFIG_DB_PORT=5432 -SMF_CONFIG_DB_USERNAME=postgres -SMF_CONFIG_DB_PASSWORD=postgres -SMF_CONFIG_DB_DATABASE_NAME=faucet diff --git a/.github/workflows/merge-pr.yml b/.github/workflows/merge-pr.yml new file mode 100644 index 00000000..a98f571e --- /dev/null +++ b/.github/workflows/merge-pr.yml @@ -0,0 +1,50 @@ +name: Merge PR +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true +on: + push: + branches: + - main + +jobs: + publish-app-docker-image: + name: "Publish App Docker Image" + + env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Check Out Repo + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=sha,prefix=,format=short + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 8c995ffe..38beb0db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/library/node:18.16.0-alpine +FROM docker.io/library/node:20-alpine # uncomment to fix build on MacOS Apple Silicon chip # RUN apk add --no-cache python3 make g++ diff --git a/README.md b/README.md index ad08ad76..7d339971 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -## Generic Faucet for Substrate based chains +## Frequency Testnet Faucet -[![GitHub Issue Sync](https://github.com/paritytech/polkadot-testnet-faucet/actions/workflows/github-issue-sync.yml/badge.svg)](https://github.com/paritytech/polkadot-testnet-faucet/actions/workflows/github-issue-sync.yml) +Fork of [paritytech/polkadot-testnet-faucet](https://github.com/paritytech/polkadot-testnet-faucet) ## Development @@ -12,9 +12,8 @@ yarn simple-git-hooks ``` #### start local database: -```bash -yarn dev:db -``` + +Uses sqlite file, no start needed. #### run migrations: ```bash diff --git a/docker/docker-compose.rococo-external.yml b/docker/docker-compose.rococo-external.yml deleted file mode 100644 index 10fad69b..00000000 --- a/docker/docker-compose.rococo-external.yml +++ /dev/null @@ -1,13 +0,0 @@ -services: - faucet: - extends: - file: docker-compose.yml - service: faucet - command: yarn start:backend - ports: - - "${SMF_BACKEND_PORT}:${SMF_BACKEND_PORT}" - environment: - SMF_BACKEND_NETWORK_DECIMALS: 12 - SMF_BACKEND_RPC_ENDPOINT: "wss://rpc.rococo.frequency.xyz/" - SMF_BACKEND_EXTERNAL_ACCESS: true - SMF_BACKEND_DRIP_AMOUNT: "0.5" diff --git a/docker/docker-compose.rococo.yml b/docker/docker-compose.rococo.yml deleted file mode 100644 index de58b930..00000000 --- a/docker/docker-compose.rococo.yml +++ /dev/null @@ -1,13 +0,0 @@ -services: - faucet: - extends: - file: docker-compose.yml - service: faucet - environment: - SMF_BACKEND_NETWORK_DECIMALS: 12 - SMF_BACKEND_RPC_ENDPOINT: "wss://rpc.rococo.frequency.xyz/" - - SMF_BOT_MATRIX_SERVER: https://m.parity.io - SMF_BOT_MATRIX_BOT_USER_ID: '@rococo-faucet-bot:matrix.org' - SMF_BOT_DRIP_AMOUNT: 5000 - SMF_BOT_NETWORK_UNIT: XRQCY diff --git a/e2e/bootstrap.sh b/e2e/bootstrap.sh index 3696f7b5..83d9eb8f 100755 --- a/e2e/bootstrap.sh +++ b/e2e/bootstrap.sh @@ -63,13 +63,11 @@ SMF_BOT_DEPLOYED_TIME=local # BACKEND -SMF_BACKEND_FAUCET_ACCOUNT_MNEMONIC="//Alice" +SMF_CONFIG_FAUCET_ACCOUNT_MNEMONIC="//Alice" SMF_BACKEND_FAUCET_BALANCE_CAP=100 SMF_BACKEND_INJECTED_TYPES="{ \"Address\": \"AccountId\", \"LookupSource\": \"AccountId\" }" -SMF_BACKEND_NETWORK_DECIMALS=12 SMF_BACKEND_PORT=5555 # Local Zombienet relaychain node. -SMF_BACKEND_RPC_ENDPOINT="ws://host.docker.internal:9944/" SMF_BACKEND_DEPLOYED_REF=local SMF_BACKEND_DEPLOYED_TIME=local SMF_BACKEND_EXTERNAL_ACCESS=true diff --git a/env.faucet.config.json b/env.faucet.config.json index 21d759b8..b6f78426 100644 --- a/env.faucet.config.json +++ b/env.faucet.config.json @@ -1,37 +1,6 @@ { "SMF": { "CONFIG": { - "DB_HOST": { - "description": "database hostname", - "default": "localhost", - "mandatory": true, - "type": "string" - }, - "DB_PORT": { - "description": "database port", - "default": 5432, - "mandatory": true, - "type": "number" - }, - "DB_USERNAME": { - "description": "database username", - "default": "postgres", - "mandatory": true, - "type": "string" - }, - "DB_PASSWORD": { - "description": "database password", - "default": "postgres", - "mandatory": true, - "masked": true, - "type": "string" - }, - "DB_DATABASE_NAME": { - "description": "name of postgres database", - "default": "faucet", - "mandatory": true, - "type": "string" - }, "DEPLOYED_REF": { "description": "git ref which of deployed app", "default": "unset", @@ -55,6 +24,7 @@ }, "MATRIX_BOT_USER_ID": { "description": "your bot user id", + "default": "@:", "regexp": "^@.*:.*$", "type": "string" }, diff --git a/src/bot/index.ts b/src/bot/index.ts index dc1d54be..3f903d85 100644 --- a/src/bot/index.ts +++ b/src/bot/index.ts @@ -20,10 +20,7 @@ const deployedRef = config.Get("DEPLOYED_REF"); const networkName = config.Get("NETWORK"); const networkData = getNetworkData(networkName); -const ignoreList = config - .Get("FAUCET_IGNORE_LIST") - .split(",") - .map((item) => item.replace('"', "")); +const ignoreList = (config.Get("FAUCET_IGNORE_LIST") || "").split(",").map((item) => item.replace('"', "")); // Show the ignore list at start if any if (ignoreList.length > 0) {