From cc056c4ecb9e37dcfd4e2183515130a3d2def17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Tue, 27 Aug 2024 11:58:57 +0200 Subject: [PATCH] Refactor Gateway deployment (#2036) --- .../manual-deploy-dexynth-gateway.yml | 142 ------------------ .../manual-deploy-obscuro-gateway.yml | 133 +++++++++++++--- .../manual-deploy-ten-gateway-frontend.yml | 72 ++++++++- 3 files changed, 174 insertions(+), 173 deletions(-) delete mode 100644 .github/workflows/manual-deploy-dexynth-gateway.yml diff --git a/.github/workflows/manual-deploy-dexynth-gateway.yml b/.github/workflows/manual-deploy-dexynth-gateway.yml deleted file mode 100644 index d4511bf5c2..0000000000 --- a/.github/workflows/manual-deploy-dexynth-gateway.yml +++ /dev/null @@ -1,142 +0,0 @@ -# Deploys Ten Gateway for Dexynth on Azure for Testnet -# Builds the Ten Gateway image, pushes the image to dockerhub and starts the Obscuro Gateway on Azure VM - -name: '[M] Deploy Ten Gateway Dexynth' -run-name: '[M] Deploy Ten Gateway Dexynth ( ${{ github.event.inputs.testnet_type }} )' -on: - workflow_dispatch: - inputs: - testnet_type: - description: 'Testnet Type' - required: true - default: 'sepolia-testnet' - type: choice - options: - - 'sepolia-testnet' - -jobs: - build-and-deploy-dexynth: - runs-on: ubuntu-latest - environment: - name: ${{ github.event.inputs.testnet_type }} - steps: - - name: 'Print GitHub variables' - # This is a useful record of what the environment variables were at the time the job ran, for debugging and reference - run: | - echo "GitHub Variables = ${{ toJSON(vars) }}" - - - uses: actions/checkout@v4 - - - name: 'Extract branch name' - shell: bash - run: | - echo "Branch Name: ${GITHUB_REF_NAME}" - echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> $GITHUB_ENV - - - name: 'Set up Docker' - uses: docker/setup-buildx-action@v1 - - - name: 'Login to Azure docker registry' - uses: azure/docker-login@v1 - with: - login-server: testnetobscuronet.azurecr.io - username: testnetobscuronet - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: 'Login via Azure CLI' - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Build and Push Docker Image - run: | - DOCKER_BUILDKIT=1 docker build --build-arg TESTNET_TYPE=${{ github.event.inputs.testnet_type }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY_DEXYNTH }} -f ./tools/walletextension/Dockerfile . - docker push ${{ vars.DOCKER_BUILD_TAG_GATEWAY_DEXYNTH }} - - # This will fail some deletions due to resource dependencies ( ie. you must first delete the vm before deleting the disk) - - name: 'Delete deployed VMs' - uses: azure/CLI@v1 - with: - inlineScript: | - $(az resource list --tag ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY_DEXYNTH }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true - - # This will clean up any lingering dependencies - might fail if there are no resources to cleanup - - name: 'Delete VMs dependencies' - uses: azure/CLI@v1 - with: - inlineScript: | - $(az resource list --tag ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY_DEXYNTH }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true - - - name: 'Ensure VM Static Public IP Exists' - uses: azure/CLI@v1 - with: - inlineScript: | - az network public-ip show -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" || az network public-ip create -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" --allocation-method Static --sku Standard - - - name: 'Assign/Update DNS Name for Public IP' - uses: azure/CLI@v1 - with: - inlineScript: | - existing_dns_name=$(az network public-ip show -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" --query dnsSettings.domainNameLabel -o tsv) - if [ -z "$existing_dns_name" ]; then - az network public-ip update -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" --dns-name "obscurogateway-${{ github.event.inputs.testnet_type }}-dexynth" - fi - - - name: 'Create VM for Gateway node on Azure' - uses: azure/CLI@v1 - with: - inlineScript: | - az vm create -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth" \ - --admin-username obscurouser --admin-password "${{ secrets.OBSCURO_NODE_VM_PWD }}" \ - --public-ip-address "${{ github.event.inputs.testnet_type }}-OG-static-dexynth" \ - --tags deploygroup=ObscuroGateway-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}-dexynth ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY_DEXYNTH }}=true \ - --vnet-name ObscuroGateway-${{ github.event.inputs.testnet_type }}-dexynth-01VNET --subnet ObscuroGateway-${{ github.event.inputs.testnet_type }}-dexynth-01Subnet \ - --size Standard_D4_v5 --image Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:latest \ - --authentication-type password - - - name: 'Open Obscuro node-${{ matrix.host_id }} ports on Azure' - uses: azure/CLI@v1 - with: - inlineScript: | - az vm open-port -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth" --port 80,81 - - # To overcome issues with critical VM resources being unavailable, we need to wait for the VM to be ready - - name: 'Allow time for VM initialization' - shell: bash - run: sleep 30 - - - name: 'Start Obscuro gateway on Azure' - uses: azure/CLI@v1 - with: - inlineScript: | - az vm run-command invoke -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth" \ - --command-id RunShellScript \ - --scripts 'mkdir -p /home/obscuro \ - && sudo apt-get update \ - && sudo apt-get install -y gcc \ - && sudo snap refresh && sudo snap install --channel=1.18 go --classic \ - && curl -fsSL https://get.docker.com -o get-docker.sh && sh ./get-docker.sh \ - && git clone --depth 1 -b ${{ env.BRANCH_NAME }} https://github.com/ten-protocol/go-ten.git /home/obscuro/go-obscuro \ - && docker network create --driver bridge node_network || true \ - && docker run -d --name datadog-agent \ - --network node_network \ - -e DD_API_KEY=${{ secrets.DD_API_KEY }} \ - -e DD_LOGS_ENABLED=true \ - -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true \ - -e DD_LOGS_CONFIG_AUTO_MULTI_LINE_DETECTION=true \ - -e DD_CONTAINER_EXCLUDE_LOGS="name:datadog-agent" \ - -e DD_SITE="datadoghq.eu" \ - -v /var/run/docker.sock:/var/run/docker.sock:ro \ - -v /proc/:/host/proc/:ro \ - -v /opt/datadog-agent/run:/opt/datadog-agent/run:rw \ - -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \ - --log-opt max-file=3 --log-opt max-size=10m \ - datadog/agent:latest \ - && cd /home/obscuro/go-obscuro/ \ - && docker run -d -p 80:80 -p 81:81 --name ${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}-dexynth \ - -e OBSCURO_GATEWAY_VERSION="${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}" \ - --log-opt max-file=3 --log-opt max-size=10m \ - ${{ vars.DOCKER_BUILD_TAG_GATEWAY_DEXYNTH }} \ - -host=0.0.0.0 -port=8080 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR_DEXYNTH }} -verbose=true \ - -logPath=sys_out -dbType=mariaDB -dbConnectionURL="obscurouser:${{ secrets.OBSCURO_GATEWAY_MARIADB_USER_PWD }}@tcp(obscurogateway-mariadb-${{ github.event.inputs.testnet_type }}.uksouth.cloudapp.azure.com:3306)/ogdb" \ - -rateLimitUserComputeTime=0 ' diff --git a/.github/workflows/manual-deploy-obscuro-gateway.yml b/.github/workflows/manual-deploy-obscuro-gateway.yml index bf8c1825d1..06d331a140 100644 --- a/.github/workflows/manual-deploy-obscuro-gateway.yml +++ b/.github/workflows/manual-deploy-obscuro-gateway.yml @@ -1,13 +1,13 @@ -# Deploys Obscuro Gateway on Azure for Testnet -# Builds the Obscuro Gateway image, pushes the image to dockerhub and starts the Obscuro Gateway on Azure VM +# Deploys Ten Gateway on Azure for Testnet +# Builds the Ten Gateway image, pushes the image to dockerhub and starts the Ten Gateway on Azure VM -name: '[M] Deploy Obscuro Gateway' -run-name: '[M] Deploy Obscuro Gateway ( ${{ github.event.inputs.testnet_type }} )' +name: '[M] Deploy Ten Gateway Backend' +run-name: '[M] Deploy Ten Gateway Backend ( ${{ github.event.inputs.testnet_type }} )' on: workflow_dispatch: inputs: testnet_type: - description: 'Testnet Type' + description: 'Environment' required: true default: 'dev-testnet' type: choice @@ -15,13 +15,98 @@ on: - 'dev-testnet' - 'uat-testnet' - 'sepolia-testnet' + instance_type: + description: 'Instance' + required: true + default: 'primary' + type: choice + options: + - 'primary' + - 'dexynth' jobs: + validate-inputs: + runs-on: ubuntu-latest + steps: + - name: 'Check if deployment is allowed' + run: | + if [[ "${{ github.event.inputs.instance_type }}" == "Dexynth" && "${{ github.event.inputs.testnet_type }}" != "sepolia-testnet" ]]; then + echo "Error: Dexynth can only be deployed to sepolia-testnet." + exit 1 + fi + build-and-deploy: runs-on: ubuntu-latest environment: name: ${{ github.event.inputs.testnet_type }} steps: + - name: 'Set up environment variables' + id: setup_env + run: | + INSTANCE_SUFFIX="" + INSTANCE_PREFIX="" + + if [[ "${{ github.event.inputs.instance_type }}" != "primary" ]]; then + INSTANCE_SUFFIX="-${{ github.event.inputs.instance_type }}" + INSTANCE_PREFIX="${{ github.event.inputs.instance_type }}-" + fi + + echo "INSTANCE_SUFFIX=$INSTANCE_SUFFIX" >> $GITHUB_ENV + echo "INSTANCE_PREFIX=$INSTANCE_PREFIX" >> $GITHUB_ENV + + # Set infrastructure variables + PUBLIC_IP="${{ github.event.inputs.testnet_type }}-OG-static${INSTANCE_SUFFIX}" + DNS_NAME="obscurogateway-${{ github.event.inputs.testnet_type }}${INSTANCE_SUFFIX}" + VM_NAME="${{ github.event.inputs.testnet_type }}-OG-${{ github.run_number }}${INSTANCE_SUFFIX}" + DEPLOY_GROUP="ObscuroGateway-${{ github.event.inputs.testnet_type }}-${{ github.run_number }}${INSTANCE_SUFFIX}" + VNET_NAME="ObscuroGateway-${{ github.event.inputs.testnet_type }}-01VNET${INSTANCE_SUFFIX}" + SUBNET_NAME="ObscuroGateway-${{ github.event.inputs.testnet_type }}-01Subnet${INSTANCE_SUFFIX}" + + echo "PUBLIC_IP=$PUBLIC_IP" >> $GITHUB_ENV + echo "DNS_NAME=$DNS_NAME" >> $GITHUB_ENV + echo "VM_NAME=$VM_NAME" >> $GITHUB_ENV + echo "DEPLOY_GROUP=$DEPLOY_GROUP" >> $GITHUB_ENV + echo "VNET_NAME=$VNET_NAME" >> $GITHUB_ENV + echo "SUBNET_NAME=$SUBNET_NAME" >> $GITHUB_ENV + + # Set instance-specific variables + declare -a VAR_NAMES=( + "DOCKER_BUILD_TAG_GATEWAY" + "AZURE_DEPLOY_GROUP_GATEWAY" + "L2_RPC_URL_VALIDATOR" + "GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME" + "GATEWAY_RATE_LIMIT_WINDOW" + "GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER" + ) + + for VAR_NAME in "${VAR_NAMES[@]}"; do + FULL_VAR_NAME="${INSTANCE_PREFIX}${VAR_NAME}" + VAR_VALUE=$(jq -r --arg key "$FULL_VAR_NAME" '.[$key] // empty' <<< '${{ toJson(vars) }}') + if [[ -n "$VAR_VALUE" ]]; then + echo "${VAR_NAME}=${VAR_VALUE}" >> $GITHUB_ENV + else + echo "Warning: ${FULL_VAR_NAME} not found in vars" >&2 + fi + done + + - name: 'Print environment variables' + # This is a useful record of what the environment variables were at the time the job ran, for debugging and reference + run: | + echo "INSTANCE_SUFFIX: $INSTANCE_SUFFIX" + echo "INSTANCE_PREFIX: $INSTANCE_PREFIX" + echo "PUBLIC_IP: $PUBLIC_IP" + echo "DNS_NAME: $DNS_NAME" + echo "VM_NAME: $VM_NAME" + echo "DEPLOY_GROUP: $DEPLOY_GROUP" + echo "VNET_NAME: $VNET_NAME" + echo "SUBNET_NAME: $SUBNET_NAME" + echo "DOCKER_BUILD_TAG_GATEWAY: $DOCKER_BUILD_TAG_GATEWAY" + echo "AZURE_DEPLOY_GROUP_GATEWAY: $AZURE_DEPLOY_GROUP_GATEWAY" + echo "L2_RPC_URL_VALIDATOR: $L2_RPC_URL_VALIDATOR" + echo "GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME: $GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME" + echo "GATEWAY_RATE_LIMIT_WINDOW: $GATEWAY_RATE_LIMIT_WINDOW" + echo "GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER: $GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER" + - name: 'Print GitHub variables' # This is a useful record of what the environment variables were at the time the job ran, for debugging and reference run: | @@ -52,66 +137,66 @@ jobs: - name: Build and Push Docker Image run: | - DOCKER_BUILDKIT=1 docker build --build-arg TESTNET_TYPE=${{ github.event.inputs.testnet_type }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY }} -f ./tools/walletextension/Dockerfile . - docker push ${{ vars.DOCKER_BUILD_TAG_GATEWAY }} + DOCKER_BUILDKIT=1 docker build --build-arg TESTNET_TYPE=${{ github.event.inputs.testnet_type }} -t ${{ env.DOCKER_BUILD_TAG_GATEWAY }} -f ./tools/walletextension/Dockerfile . + docker push ${{ env.DOCKER_BUILD_TAG_GATEWAY }} # This will fail some deletions due to resource dependencies ( ie. you must first delete the vm before deleting the disk) - name: 'Delete deployed VMs' uses: azure/CLI@v1 with: inlineScript: | - $(az resource list --tag ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true + $(az resource list --tag ${{ env.AZURE_DEPLOY_GROUP_GATEWAY }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true # This will clean up any lingering dependencies - might fail if there are no resources to cleanup - name: 'Delete VMs dependencies' uses: azure/CLI@v1 with: inlineScript: | - $(az resource list --tag ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true + $(az resource list --tag ${{ env.AZURE_DEPLOY_GROUP_GATEWAY }}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true - name: 'Ensure VM Static Public IP Exists' uses: azure/CLI@v1 with: inlineScript: | - az network public-ip show -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static" || az network public-ip create -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static" --allocation-method Static --sku Standard + az network public-ip show -g Testnet -n "${{ env.PUBLIC_IP }}" || az network public-ip create -g Testnet -n "${{ env.PUBLIC_IP }}" --allocation-method Static --sku Standard - name: 'Assign/Update DNS Name for Public IP' uses: azure/CLI@v1 with: inlineScript: | - existing_dns_name=$(az network public-ip show -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static" --query dnsSettings.domainNameLabel -o tsv) + existing_dns_name=$(az network public-ip show -g Testnet -n "${{ env.PUBLIC_IP }}" --query dnsSettings.domainNameLabel -o tsv) if [ -z "$existing_dns_name" ]; then - az network public-ip update -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-static" --dns-name "obscurogateway-${{ github.event.inputs.testnet_type }}" + az network public-ip update -g Testnet -n "${{ env.PUBLIC_IP }}" --dns-name "${{ env.DNS_NAME }}" fi - name: 'Create VM for Gateway node on Azure' uses: azure/CLI@v1 with: inlineScript: | - az vm create -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}" \ + az vm create -g Testnet -n "${{ env.VM_NAME }}" \ --admin-username obscurouser --admin-password "${{ secrets.OBSCURO_NODE_VM_PWD }}" \ - --public-ip-address "${{ github.event.inputs.testnet_type }}-OG-static" \ - --tags deploygroup=ObscuroGateway-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }} ${{ vars.AZURE_DEPLOY_GROUP_GATEWAY }}=true \ - --vnet-name ObscuroGateway-${{ github.event.inputs.testnet_type }}-01VNET --subnet ObscuroGateway-${{ github.event.inputs.testnet_type }}-01Subnet \ + --public-ip-address "${{ env.PUBLIC_IP }}" \ + --tags deploygroup="${{ env.DEPLOY_GROUP }}" ${{ env.AZURE_DEPLOY_GROUP_GATEWAY }}=true \ + --vnet-name "${{ env.VNET_NAME }}" --subnet "${{ env.SUBNET_NAME }}" \ --size Standard_D4_v5 --image Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:latest \ --authentication-type password - - name: 'Open Obscuro node-${{ matrix.host_id }} ports on Azure' + - name: 'Open Ten node-${{ matrix.host_id }} ports on Azure' uses: azure/CLI@v1 with: inlineScript: | - az vm open-port -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}" --port 80,81 + az vm open-port -g Testnet -n "${{ env.VM_NAME }}" --port 80,81 # To overcome issues with critical VM resources being unavailable, we need to wait for the VM to be ready - name: 'Allow time for VM initialization' shell: bash run: sleep 30 - - name: 'Start Obscuro gateway on Azure' + - name: 'Start Ten Gateway on Azure' uses: azure/CLI@v1 with: inlineScript: | - az vm run-command invoke -g Testnet -n "${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }}" \ + az vm run-command invoke -g Testnet -n "${{ env.VM_NAME }}" \ --command-id RunShellScript \ --scripts 'mkdir -p /home/obscuro \ && sudo apt-get update \ @@ -135,10 +220,10 @@ jobs: --log-opt max-file=3 --log-opt max-size=10m \ datadog/agent:latest \ && cd /home/obscuro/go-obscuro/ \ - && docker run -d -p 80:80 -p 81:81 --name ${{ github.event.inputs.testnet_type }}-OG-${{ GITHUB.RUN_NUMBER }} \ + && docker run -d -p 80:80 -p 81:81 --name "${{ env.VM_NAME }}" \ -e OBSCURO_GATEWAY_VERSION="${{ GITHUB.RUN_NUMBER }}-${{ GITHUB.SHA }}" \ --log-opt max-file=3 --log-opt max-size=10m \ - ${{ vars.DOCKER_BUILD_TAG_GATEWAY }} \ - -host=0.0.0.0 -port=80 -portWS=81 -nodeHost=${{ vars.L2_RPC_URL_VALIDATOR }} -verbose=true \ + ${{ env.DOCKER_BUILD_TAG_GATEWAY }} \ + -host=0.0.0.0 -port=80 -portWS=81 -nodeHost=${{ env.L2_RPC_URL_VALIDATOR }} -verbose=true \ -logPath=sys_out -dbType=mariaDB -dbConnectionURL="obscurouser:${{ secrets.OBSCURO_GATEWAY_MARIADB_USER_PWD }}@tcp(obscurogateway-mariadb-${{ github.event.inputs.testnet_type }}.uksouth.cloudapp.azure.com:3306)/ogdb" \ - -rateLimitUserComputeTime=${{ vars.GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME }} -rateLimitWindow=${{ vars.GATEWAY_RATE_LIMIT_WINDOW }} -maxConcurrentRequestsPerUser=${{ vars.GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER }} ' + -rateLimitUserComputeTime=${{ env.GATEWAY_RATE_LIMIT_USER_COMPUTE_TIME }} -rateLimitWindow=${{ env.GATEWAY_RATE_LIMIT_WINDOW }} -maxConcurrentRequestsPerUser=${{ env.GATEWAY_MAX_CONCURRENT_REQUESTS_PER_USER }} ' diff --git a/.github/workflows/manual-deploy-ten-gateway-frontend.yml b/.github/workflows/manual-deploy-ten-gateway-frontend.yml index b50d0f1506..e3fe12fc0b 100644 --- a/.github/workflows/manual-deploy-ten-gateway-frontend.yml +++ b/.github/workflows/manual-deploy-ten-gateway-frontend.yml @@ -15,16 +15,74 @@ on: - 'dev-testnet' - 'uat-testnet' - 'sepolia-testnet' + instance_type: + description: 'Instance' + required: true + default: 'primary' + type: choice + options: + - 'primary' + - 'dexynth' jobs: + validate-inputs: + runs-on: ubuntu-latest + steps: + - name: 'Check if deployment is allowed' + run: | + if [[ "${{ github.event.inputs.instance_type }}" == "dexynth" && "${{ github.event.inputs.testnet_type }}" != "sepolia-testnet" ]]; then + echo "Error: Dexynth can only be deployed to sepolia-testnet." + exit 1 + fi build-and-deploy: runs-on: ubuntu-latest environment: name: ${{ github.event.inputs.testnet_type }} steps: + - name: 'Set up environment variables' + id: setup_env + run: | + INSTANCE_SUFFIX="" + INSTANCE_PREFIX="" + + if [[ "${{ github.event.inputs.instance_type }}" != "primary" ]]; then + INSTANCE_SUFFIX="-${{ github.event.inputs.instance_type }}" + INSTANCE_PREFIX="${{ github.event.inputs.instance_type }}-" + fi + + echo "INSTANCE_SUFFIX=$INSTANCE_SUFFIX" >> $GITHUB_ENV + echo "INSTANCE_PREFIX=$INSTANCE_PREFIX" >> $GITHUB_ENV + + + DNS_NAME_LABEL_GATEWAY_FE="${{ github.event.inputs.testnet_type }}-ten-gateway${INSTANCE_SUFFIX}" + IMAGE_NAME_GATEWAY_FE="${{ github.event.inputs.testnet_type }}-fe-ten-gateway${INSTANCE_SUFFIX}" + + echo "DNS_NAME_LABEL_GATEWAY_FE=$DNS_NAME_LABEL_GATEWAY_FE" >> $GITHUB_ENV + echo "IMAGE_NAME_GATEWAY_FE=$IMAGE_NAME_GATEWAY_FE" >> $GITHUB_ENV + + # Set instance-specific variables + declare -a VAR_NAMES=( + "DOCKER_BUILD_TAG_GATEWAY_FE" + "GATEWAY_URL" + ) + + for VAR_NAME in "${VAR_NAMES[@]}"; do + FULL_VAR_NAME="${INSTANCE_PREFIX}${VAR_NAME}" + VAR_VALUE=$(jq -r --arg key "$FULL_VAR_NAME" '.[$key] // empty' <<< '${{ toJson(vars) }}') + if [[ -n "$VAR_VALUE" ]]; then + echo "${VAR_NAME}=${VAR_VALUE}" >> $GITHUB_ENV + else + echo "Warning: ${FULL_VAR_NAME} not found in vars" >&2 + fi + done + - name: 'Print GitHub variables' run: | - echo "Selected Testnet Type: ${{ matrix.testnet_type }}" - echo "Gateway API URL: ${{ vars.GATEWAY_URL }}" + echo "Selected Testnet Type: ${{ github.event.inputs.testnet_type }}" + echo "Selected Instance Type: ${{ github.event.inputs.instance_type }}" + echo "DNS_NAME_LABEL_GATEWAY_FE: $DNS_NAME_LABEL_GATEWAY_FE" + echo "IMAGE_NAME_GATEWAY_FE: $IMAGE_NAME_GATEWAY_FE" + echo "DOCKER_BUILD_TAG_GATEWAY_FE: $DOCKER_BUILD_TAG_GATEWAY_FE" + echo "GATEWAY_URL: $GATEWAY_URL" - uses: actions/checkout@v4 @@ -51,16 +109,16 @@ jobs: - name: Build and Push Docker Image run: | - DOCKER_BUILDKIT=1 docker build --build-arg GATEWAY_API_URL=${{ vars.GATEWAY_URL }} -t ${{ vars.DOCKER_BUILD_TAG_GATEWAY_FE }} -f ./tools/walletextension/frontend/Dockerfile . - docker push ${{ vars.DOCKER_BUILD_TAG_GATEWAY_FE }} + DOCKER_BUILDKIT=1 docker build --build-arg GATEWAY_API_URL=${{ env.GATEWAY_URL }} -t ${{ env.DOCKER_BUILD_TAG_GATEWAY_FE }} -f ./tools/walletextension/frontend/Dockerfile . + docker push ${{ env.DOCKER_BUILD_TAG_GATEWAY_FE }} - name: "Deploy Gateway FE to Azure Container Instances" uses: "azure/aci-deploy@v1" with: resource-group: ${{ secrets.RESOURCE_GROUP }} - dns-name-label: ${{ github.event.inputs.testnet_type }}-ten-gateway - image: ${{ vars.DOCKER_BUILD_TAG_GATEWAY_FE }} - name: ${{ github.event.inputs.testnet_type }}-fe-ten-gateway + dns-name-label: ${{ env.DNS_NAME_LABEL_GATEWAY_FE }} + image: ${{ env.DOCKER_BUILD_TAG_GATEWAY_FE }} + name: ${{ env.IMAGE_NAME_GATEWAY_FE }} location: "uksouth" restart-policy: "Never" ports: "80"