[M] Build and Deploy Ten Gateway Frontend ( dev-testnet ) #91
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "[M] Build and Deploy Ten Gateway Frontend" | |
run-name: "[M] Build and Deploy Ten Gateway Frontend ( ${{ inputs.testnet_type }} )" | |
on: | |
workflow_dispatch: | |
inputs: | |
testnet_type: | |
description: "Testnet Type" | |
required: true | |
default: "dev-testnet" | |
type: choice | |
options: | |
- "dev-testnet" | |
- "uat-testnet" | |
- "sepolia-testnet" | |
instance_type: | |
description: "Instance" | |
required: true | |
default: "primary" | |
type: choice | |
options: | |
- "primary" | |
- "DEXYNTH" | |
deploy_to_azure: | |
description: "Release to ACR" | |
required: true | |
default: "true" | |
type: choice | |
options: | |
- "true" | |
- "false" | |
deploy_gateway_fe: | |
description: "Deploy Gateway FE to Azure" | |
required: true | |
default: "true" | |
type: choice | |
options: | |
- "true" | |
- "false" | |
next_public_api_host_environment: | |
description: "NEXT_PUBLIC_API_HOST_ENVIRONMENT" | |
required: true | |
default: "dev-testnet" | |
next_public_network_name: | |
description: "NEXT_PUBLIC_NETWORK_NAME" | |
required: true | |
default: "Ten Testnet" | |
next_public_tenscan_url: | |
description: "NEXT_PUBLIC_TENSCAN_URL" | |
required: true | |
default: "https://tenscan.io" | |
next_public_gateway_url: | |
description: "NEXT_PUBLIC_GATEWAY_URL" | |
required: true | |
default: "https://dev-testnet.ten.xyz/" | |
docker_build_tag_gateway_fe: | |
description: "DOCKER_BUILD_TAG_GATEWAY_FE" | |
required: true | |
default: "latest" | |
jobs: | |
validate-inputs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Check if deployment is allowed" | |
run: | | |
if [[ "${{ inputs.instance_type }}" == "DEXYNTH" && "${{ 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 | |
needs: validate-inputs | |
environment: | |
name: ${{ inputs.testnet_type }} | |
steps: | |
- name: "Set up environment variables" | |
id: setup_env | |
run: | | |
INSTANCE_SUFFIX="" | |
INSTANCE_PREFIX="" | |
if [[ "${{ inputs.instance_type }}" != "primary" ]]; then | |
INSTANCE_SUFFIX="_${{ inputs.instance_type }}" | |
INSTANCE_SUFFIX2="-${{ inputs.instance_type }}" | |
INSTANCE_PREFIX="${{ inputs.instance_type }}_" | |
fi | |
echo "INSTANCE_SUFFIX=$INSTANCE_SUFFIX" >> $GITHUB_ENV | |
echo "INSTANCE_PREFIX=$INSTANCE_PREFIX" >> $GITHUB_ENV | |
DNS_NAME_LABEL_GATEWAY_FE="${{ inputs.testnet_type }}-ten-gateway${INSTANCE_SUFFIX2,,}" | |
IMAGE_NAME_GATEWAY_FE="${{ inputs.testnet_type }}-fe-ten-gateway${INSTANCE_SUFFIX2,,}" | |
echo "DNS_NAME_LABEL_GATEWAY_FE=$DNS_NAME_LABEL_GATEWAY_FE" >> $GITHUB_ENV | |
echo "IMAGE_NAME_GATEWAY_FE=$IMAGE_NAME_GATEWAY_FE" >> $GITHUB_ENV | |
echo "DOCKER_BUILD_TAG_GATEWAY_FE=${{ vars.DOCKER_REPO_GATEWAY_FE }}:${{ inputs.docker_build_tag_gateway_fe }}" >> $GITHUB_ENV | |
# Set instance-specific variables | |
declare -a VAR_NAMES=( | |
"GATEWAY_URL" | |
"NETWORK_NAME" | |
"TENSCAN_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: ${{ inputs.testnet_type }}" | |
echo "Selected Instance Type: ${{ 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: ${{ vars.DOCKER_REPO_GATEWAY_FE }}:${{ inputs.docker_build_tag_gateway_fe }}" | |
echo "GATEWAY_URL: $GATEWAY_URL" | |
echo "NETWORK_NAME: $NETWORK_NAME" | |
echo "TENSCAN_URL: $TENSCAN_URL" | |
- 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/[email protected] | |
- name: "Login to Azure docker registry" | |
if: inputs.deploy_to_azure == 'true' | |
uses: azure/docker-login@v1 | |
with: | |
login-server: testnetobscuronet.azurecr.io | |
username: testnetobscuronet | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: "Login via Azure CLI" | |
if: inputs.deploy_to_azure == 'true' | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: "Build and Push Docker Image" | |
run: | | |
DOCKER_BUILDKIT=1 docker build \ | |
--build-arg NEXT_PUBLIC_API_HOST_ENVIRONMENT="${{ inputs.next_public_api_host_environment }}" \ | |
--build-arg NEXT_PUBLIC_NETWORK_NAME="${{ inputs.next_public_network_name }}" \ | |
--build-arg NEXT_PUBLIC_TENSCAN_URL="${{ inputs.next_public_tenscan_url }}" \ | |
--build-arg NEXT_PUBLIC_GATEWAY_URL="${{ inputs.next_public_gateway_url }}" \ | |
-t "${{ vars.DOCKER_REPO_GATEWAY_FE }}:${{ inputs.docker_build_tag_gateway_fe }}" \ | |
-f ./tools/walletextension/frontend/Dockerfile . | |
docker push "${{ vars.DOCKER_REPO_GATEWAY_FE }}:${{ inputs.docker_build_tag_gateway_fe }}" | |
- name: "Deploy Gateway FE to Azure Container Instances" | |
if: inputs.deploy_gateway_fe == 'true' | |
uses: "azure/aci-deploy@v1" | |
with: | |
resource-group: ${{ secrets.RESOURCE_GROUP }} | |
dns-name-label: ${{ env.DNS_NAME_LABEL_GATEWAY_FE }} | |
image: ${{ vars.DOCKER_REPO_GATEWAY_FE }}:${{ inputs.docker_build_tag_gateway_fe }} | |
name: ${{ env.IMAGE_NAME_GATEWAY_FE }} | |
location: "uksouth" | |
restart-policy: "Never" | |
ports: "80" | |
cpu: 2 | |
memory: 2 |