-
Notifications
You must be signed in to change notification settings - Fork 38
149 lines (130 loc) · 6.85 KB
/
manual-deploy-testnet-l1.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Deploys a L1 network on Azure for Testnet / Dev-Testnet
# Builds the l1 network image, kills any running VM, pushes the image to dockerhub and starts the l1 network on azure
#
# The L1 network is a docker container that runs 1 x (eth node + prysm beacon + prysm validator)
# It exposes the following ports:
# HTTP: 8025, 8026
# WebSocket: 9000, 9001
#
# Exposes the following addresses: (only accessible internally)
# testnet-eth2network-DEPLOYNUMBER.uksouth.azurecontainer.io
# or
# dev-testnet-eth2network-DEPLOYNUMBER.uksouth.azurecontainer.io
#
# The scheduled deployment runs at 03:05 on every day-of-week from Tuesday through Saturday, for dev-testnet only.
name: '[M] Deploy Testnet L1'
on:
workflow_dispatch:
inputs:
testnet_type:
description: 'Testnet Type'
required: true
default: 'dev-testnet'
type: choice
options:
- 'dev-testnet'
- 'testnet'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Set up Docker'
uses: docker/setup-buildx-action@v1
- name: 'Sets env vars for testnet'
if: ${{ github.event.inputs.testnet_type == 'testnet' }}
run: |
echo "ETH2NETWORK_BUILD_TAG=testnetobscuronet.azurecr.io/obscuronet/eth2network:latest" >> $GITHUB_ENV
echo "L1_DOCKER_BUILD_TAG=testnetobscuronet.azurecr.io/obscuronet/testnet_l1network:latest" >> $GITHUB_ENV
echo "L1_CONTAINER_NAME=testnet-eth2network" >> $GITHUB_ENV
echo "RESOURCE_TAG_NAME=l1testnetlatest" >> $GITHUB_ENV
echo "RESOURCE_NAME=testnet-eth2network" >> $GITHUB_ENV
- name: 'Sets env vars for dev-testnet'
if: ${{ github.event.inputs.testnet_type == 'dev-testnet' }}
run: |
echo "ETH2NETWORK_BUILD_TAG=testnetobscuronet.azurecr.io/obscuronet/dev_eth2network:latest" >> $GITHUB_ENV
echo "L1_DOCKER_BUILD_TAG=testnetobscuronet.azurecr.io/obscuronet/dev_testnet_l1network:latest" >> $GITHUB_ENV
echo "L1_CONTAINER_NAME=dev-testnet-eth2network" >> $GITHUB_ENV
echo "RESOURCE_TAG_NAME=devl1testnetlatest" >> $GITHUB_ENV
echo "RESOURCE_NAME=dev-testnet-eth2network" >> $GITHUB_ENV
- name: 'Login via Azure CLI'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: 'Login to Azure docker registry'
uses: azure/docker-login@v1
with:
login-server: testnetobscuronet.azurecr.io
username: testnetobscuronet
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: 'Build and push image'
# DOCKER_BUILDKIT=1 will enable the new docker build kit that allows us to use build only caches on RUN commands.
# Tag the same image with 2 tags and push with the -a flag which pushes all images
run: |
DOCKER_BUILDKIT=1 docker build -t ${{env.ETH2NETWORK_BUILD_TAG}} -t ${{env.L1_DOCKER_BUILD_TAG}} -f testnet/eth2network.Dockerfile .
docker push ${{env.L1_DOCKER_BUILD_TAG}}
docker push ${{env.ETH2NETWORK_BUILD_TAG}}
# 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 ${{env.RESOURCE_TAG_NAME}}=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 ${{env.RESOURCE_TAG_NAME}}=true --query '[]."id"' -o tsv | xargs -n1 az resource delete --verbose -g Testnet --ids) || true
- name: 'Create VM for "${{env.RESOURCE_NAME}}-${{ GITHUB.RUN_NUMBER }}" on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm create -g Testnet -n "${{env.RESOURCE_NAME}}-${{ GITHUB.RUN_NUMBER }}" \
--admin-username obscurouser --admin-password "${{ secrets.OBSCURO_NODE_VM_PWD }}" \
--public-ip-address-dns-name "${{ env.RESOURCE_NAME }}" \
--tags ${{env.RESOURCE_TAG_NAME}}=true \
--vnet-name ${{env.RESOURCE_NAME}}-01VNET --subnet ${{env.RESOURCE_NAME}}-01Subnet \
--size Standard_D3_v2 --image Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest \
--public-ip-sku Basic --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 "${{env.RESOURCE_NAME}}-${{ GITHUB.RUN_NUMBER }}" --port 8025,8026,9000,9001
# 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 60
- name: 'Start l1 ${{env.RESOURCE_NAME}}-${{ GITHUB.RUN_NUMBER }} on Azure'
uses: azure/CLI@v1
with:
inlineScript: |
az vm run-command invoke -g Testnet -n "${{env.RESOURCE_NAME}}-${{ GITHUB.RUN_NUMBER }}" \
--command-id RunShellScript \
--scripts 'mkdir -p /home/obscuro \
&& sudo apt-get update \
&& sudo apt-get install -y gcc \
&& sudo snap refresh \
&& curl -fsSL https://get.docker.com -o get-docker.sh && sh ./get-docker.sh \
&& docker network create --driver bridge l1_network || true \
&& docker run -d --name datadog-agent \
--network l1_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 \
datadog/agent:latest \
&& docker run -d \
-p 8025:8025 -p 8026:8026 -p 9000:9000 -p 9001:9001 \
--entrypoint /home/obscuro/go-obscuro/integration/eth2network/main/main ${{ env.ETH2NETWORK_BUILD_TAG }} \
--blockTimeSecs=15 --slotsPerEpoch=2 --slotsPerSecond=15 \
--numNodes=1 --gethHTTPStartPort=8025 --gethWSStartPort=9000 \
--logToFile=false \
--prefundedAddrs="${{ secrets.GETHNETWORK_PREFUNDED_ADDR_WORKER }},${{ secrets.GETHNETWORK_PREFUNDED_ADDR_0 }},${{ secrets.GETHNETWORK_PREFUNDED_ADDR_1 }}"'