|
| 1 | +name: Deploy - Devnet |
| 2 | + |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + codex_image: |
| 8 | + description: codexstorage/nim-codex:latest-dist-tests |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + workflow_call: |
| 12 | + inputs: |
| 13 | + codex_image: |
| 14 | + description: codexstorage/nim-codex:latest-dist-tests |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +env: |
| 19 | + CODEX_NAMESPACE: codex |
| 20 | + TOOLS_NAMESPACE: common |
| 21 | + KUBE_CONFIG: ${{ secrets.DEVNET_KUBE_CONFIG }} |
| 22 | + KUBE_VERSION: v1.33.1 |
| 23 | + CODEX_IMAGE: ${{ inputs.codex_image }} |
| 24 | + SSH_HOSTS: ${{ secrets.DEVNET_SSH_HOSTS }} |
| 25 | + SSH_PORT: ${{ secrets.DEVNET_SSH_PORT }} |
| 26 | + SSH_USERNAME: ${{ secrets.DEVNET_SSH_USERNAME }} |
| 27 | + SSH_PRIVATE_KEY: ${{ secrets.DEVNET_SSH_KEY }} |
| 28 | + |
| 29 | + |
| 30 | +jobs: |
| 31 | + deploy-contracts: |
| 32 | + name: Deploy contracts |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Create access token |
| 36 | + uses: actions/create-github-app-token@v2 |
| 37 | + id: app-token |
| 38 | + with: |
| 39 | + app-id: ${{ secrets.DEPLOYER_APP_ID }} |
| 40 | + private-key: ${{ secrets.DEPLOYER_PRIVATE_KEY }} |
| 41 | + repositories: codex-contracts-eth |
| 42 | + |
| 43 | + - name: Checkout sources |
| 44 | + uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + submodules: recursive |
| 47 | + |
| 48 | + - name: Get contracts submodule ref |
| 49 | + id: contracts |
| 50 | + run: echo "ref=$(git rev-parse HEAD:vendor/codex-contracts-eth)" >> $GITHUB_OUTPUT |
| 51 | + |
| 52 | + - name: Deploy smart contracts |
| 53 | + uses: the-actions-org/workflow-dispatch@v4 |
| 54 | + with: |
| 55 | + repo: codex-storage/codex-contracts-eth |
| 56 | + workflow: devnet-contracts.yml |
| 57 | + token: ${{ steps.app-token.outputs.token }} |
| 58 | + wait-for-completion-timeout: 20m |
| 59 | + wait-for-completion-interval: 20s |
| 60 | + inputs: '{ "network": "codex_devnet", "contracts_ref": "${{ steps.contracts.outputs.ref }}" }' |
| 61 | + |
| 62 | + |
| 63 | + bootstrap-nodes: |
| 64 | + name: Bootstrap nodes |
| 65 | + runs-on: ubuntu-latest |
| 66 | + needs: deploy-contracts |
| 67 | + steps: |
| 68 | + - name: Codex Bootstrap - Update |
| 69 | + uses: appleboy/ssh-action@v1 |
| 70 | + with: |
| 71 | + host: ${{ secrets.DEVNET_SSH_HOSTS }} |
| 72 | + username: ${{ secrets.DEVNET_SSH_USERNAME }} |
| 73 | + key: ${{ secrets.DEVNET_SSH_KEY }} |
| 74 | + port: ${{ secrets.DEVNET_SSH_PORT }} |
| 75 | + script: /opt/codex/remote-deploy.sh ${{ env.CODEX_IMAGE }} |
| 76 | + |
| 77 | + cluster-nodes: |
| 78 | + name: Cluster nodes |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: bootstrap-nodes |
| 81 | + steps: |
| 82 | + - name: Kubectl - Install ${{ env.KUBE_VERSION }} |
| 83 | + uses: azure/setup-kubectl@v4 |
| 84 | + with: |
| 85 | + version: ${{ env.KUBE_VERSION }} |
| 86 | + |
| 87 | + - name: Kubectl - Kubeconfig |
| 88 | + run: | |
| 89 | + mkdir -p "${HOME}"/.kube |
| 90 | + echo "${{ env.KUBE_CONFIG }}" | base64 -d > "${HOME}"/.kube/config |
| 91 | +
|
| 92 | + - name: Codex Storage - Update |
| 93 | + run: | |
| 94 | + for node in {1..5}; do |
| 95 | + kubectl -n "${{ env.CODEX_NAMESPACE }}" patch statefulset codex-storage-${node} \ |
| 96 | + --patch '{"spec": {"template": {"spec":{"containers":[{"name": "codex", "image":"${{ env.CODEX_IMAGE }}"}]}}}}' |
| 97 | + done |
| 98 | +
|
| 99 | + - name: Codex Validators - Update |
| 100 | + run: | |
| 101 | + for node in {1..1}; do |
| 102 | + kubectl -n "${{ env.CODEX_NAMESPACE }}" patch statefulset codex-validator-${node} \ |
| 103 | + --patch '{"spec": {"template": {"spec":{"containers":[{"name": "codex", "image":"${{ env.CODEX_IMAGE }}"}]}}}}' |
| 104 | + done |
| 105 | +
|
| 106 | + - name: Codex Storage - Status |
| 107 | + run: | |
| 108 | + WAIT=300 |
| 109 | + SECONDS=0 |
| 110 | + sleep=1 |
| 111 | + for instance in {1..5}; do |
| 112 | + while (( SECONDS < WAIT )); do |
| 113 | + pod=codex-storage-${instance}-1 |
| 114 | + phase=$(kubectl get pod "${pod}" -n "${{ env.CODEX_NAMESPACE }}" -o jsonpath='{.status.phase}') |
| 115 | + if [[ "${phase}" == "Running" ]]; then |
| 116 | + echo "Pod ${pod} is in the ${phase} state" |
| 117 | + break |
| 118 | + else |
| 119 | + echo "Pod ${pod} is in the ${phase} state - Check in ${sleep} second(s) / $((WAIT - SECONDS))" |
| 120 | + fi |
| 121 | + sleep "${sleep}" |
| 122 | + done |
| 123 | + done |
| 124 | +
|
| 125 | + - name: Codex Validators - Status |
| 126 | + run: | |
| 127 | + WAIT=300 |
| 128 | + SECONDS=0 |
| 129 | + sleep=1 |
| 130 | + for instance in {1..1}; do |
| 131 | + while (( SECONDS < WAIT )); do |
| 132 | + pod=codex-validator-${instance}-1 |
| 133 | + phase=$(kubectl get pod "${pod}" -n "${{ env.CODEX_NAMESPACE }}" -o jsonpath='{.status.phase}') |
| 134 | + if [[ "${phase}" == "Running" ]]; then |
| 135 | + echo "Pod ${pod} is in the ${phase} state" |
| 136 | + break |
| 137 | + else |
| 138 | + echo "Pod ${pod} is in the ${phase} state - Check in ${sleep} second(s) / $((WAIT - SECONDS))" |
| 139 | + fi |
| 140 | + sleep "${sleep}" |
| 141 | + done |
| 142 | + done |
| 143 | +
|
| 144 | + - name: Tools - Update |
| 145 | + run: | |
| 146 | + crawler_pod=$(kubectl get pod -n "${{ env.TOOLS_NAMESPACE }}" -l 'app.kubernetes.io/name=crawler' -ojsonpath='{.items[0].metadata.name}' 2>/dev/null || true) |
| 147 | + discordbot_pod=$(kubectl get pod -n "${{ env.TOOLS_NAMESPACE }}" -l 'app=discordbot' -ojsonpath='{.items[0].metadata.name}' 2>/dev/null || true) |
| 148 | +
|
| 149 | + for pod in "${crawler_pod}" "${discordbot_pod}"; do |
| 150 | + if [[ -n "${pod}" ]]; then |
| 151 | + kubectl delete pod -n "${{ env.TOOLS_NAMESPACE }}" "${pod}" --grace-period=10 |
| 152 | + fi |
| 153 | + done |
| 154 | +
|
| 155 | + - name: Tools - Status |
| 156 | + run: | |
| 157 | + WAIT=300 |
| 158 | + SECONDS=0 |
| 159 | + sleep=1 |
| 160 | + crawler_pod=$(kubectl get pod -n "${{ env.TOOLS_NAMESPACE }}" -l 'app.kubernetes.io/name=crawler' -ojsonpath='{.items[0].metadata.name}' 2>/dev/null || true) |
| 161 | + discordbot_pod=$(kubectl get pod -n "${{ env.TOOLS_NAMESPACE }}" -l 'app=discordbot' -ojsonpath='{.items[0].metadata.name}' 2>/dev/null || true) |
| 162 | + for pod in "${crawler_pod}" "${discordbot_pod}"; do |
| 163 | + if [[ -n "${pod}" ]]; then |
| 164 | + while (( SECONDS < WAIT )); do |
| 165 | + phase=$(kubectl get pod "${pod}" -n "${{ env.TOOLS_NAMESPACE }}" -o jsonpath='{.status.phase}') |
| 166 | + if [[ "${phase}" == "Running" ]]; then |
| 167 | + echo "Pod ${pod} is in the ${phase} state" |
| 168 | + break |
| 169 | + else |
| 170 | + echo "Pod ${pod} is in the ${phase} state - Check in ${sleep} second(s) / $((WAIT - SECONDS))" |
| 171 | + fi |
| 172 | + sleep "${sleep}" |
| 173 | + done |
| 174 | + fi |
| 175 | + done |
0 commit comments