Skip to content

Commit

Permalink
[ci] update server configs from git
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Baryshev <[email protected]>
  • Loading branch information
dennybaa committed Jul 27, 2021
1 parent 4c1249b commit 81eac7f
Showing 1 changed file with 66 additions and 33 deletions.
99 changes: 66 additions & 33 deletions .github/workflows/deploy-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Deploy Apps
on:
deployment:

defaults:
run:
shell: bash -leo pipefail {0}

env:
DEPLOY_APPS: -l name=server -l name=prover

Expand All @@ -12,41 +16,36 @@ jobs:
steps:
- uses: actions/checkout@v2
-
id: print
run: echo "::set-output name=shortRev::$(git rev-parse --short HEAD)"
id: config
run: |
environment=${{ github.event.deployment.environment }}
echo "::set-output name=shortRev::$(git rev-parse --short HEAD)"
echo "::set-output name=environment::${environment}"
-
uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.ref }}
regex: '^refs\/tags\/(v[0-9]+\.[0-9]+\.[0-9](-?.*)?)$'
regex: '^refs\/tags\/((v[0-9]+\.[0-9]+\.[0-9])(-?.*)?)$'
-
name: Map runtime environment data
uses: kanga333/[email protected]
id: envMap
uses: kanga333/[email protected]
with:
key: "${{ github.event.deployment.environment }}"
key: ${{ steps.config.outputs.environment }}
export_to: output
mode: overwrite
map: |
{
"^mainnet$": {
"KUBECONF": "KUBECONF_MAINNET",
"HFENV": "prod",
"RUNNER": "mainnet"
},
"^rinkeby$": {
"KUBECONF": "KUBECONF_TESTNET",
"HFENV": "${{ github.event.deployment.environment }}",
"RUNNER": "testnet"
},
"^ropsten$": {
"KUBECONF": "KUBECONF_TESTNET",
"HFENV": "${{ github.event.deployment.environment }}",
"RUNNER": "testnet"
},
".*": {
"KUBECONF": "KUBECONF_STAGE",
"HFENV": "${{ github.event.deployment.environment }}",
"RUNNER": "stage"
}
"hfEnv": "${{ steps.config.outputs.environment }}",
"kubeConf": "KUBECONF_STAGE",
"runner": "stage",
"namespace": "${{ steps.config.outputs.environment }}"
},
"^rinkeby$": { "kubeConf": "KUBECONF_TESTNET", "runner": "testnet" },
"^ropsten$": { "kubeConf": "KUBECONF_TESTNET", "runner": "testnet" },
"^mainnet$": { "kubeConf": "KUBECONF_MAINNET", "runner": "mainnet", "hfEnv": "prod", "namespace": "zksync" }
}
-
name: Cancel deployment (deployment tag missmatch)
Expand All @@ -58,25 +57,60 @@ jobs:
deployment_id: ${{ github.event.deployment.id }}

outputs:
shortRev: ${{ steps.print.outputs.shortRev }}
kubeConf: ${{ env.KUBECONF }}
hfEnv: ${{ env.HFENV }}
runner: ${{ env.RUNNER }}
shortRev: ${{ steps.config.outputs.shortRev }}
environment: ${{ steps.config.outputs.environment }}
kubeConf: ${{ steps.envMap.outputs.kubeConf }}
hfEnv: ${{ steps.envMap.outputs.hfEnv }}
namespace: ${{ steps.envMap.outputs.namespace }}
runner: ${{ steps.envMap.outputs.runner }}
isTag: ${{ steps.regex-match.outputs.group1 != '' }}
configTag: ${{ steps.regex-match.outputs.group2 }}

updateConfig:
name: update config
needs: [pre]
runs-on: [k8s, deployer, "${{ needs.pre.outputs.runner }}"]
container:
image: dysnix/kubectl:v1.19-gcloud
env:
IMAGE_TAG: ${{ needs.pre.outputs.shortRev }}
KUBECONF: ${{ secrets[needs.pre.outputs.kubeConf] }}
ENVFILE: ./compiled_envs/${{ needs.pre.outputs.environment }}.env
steps:
-
if: ${{ needs.pre.outputs.isTag == 'true' }}
name: Create ~/.kube/config
run: mkdir -p ~/.kube && echo "$KUBECONF" | base64 -d > ~/.kube/config
-
if: ${{ needs.pre.outputs.isTag == 'true' }}
name: Clone configs
uses: actions/checkout@v2
with:
repository: matter-labs/configs
path: configs
ref: ${{ needs.pre.outputs.configTag }}
token: ${{ secrets.GH_TOKEN }}
-
if: ${{ needs.pre.outputs.isTag == 'true' }}
name: Update Server Config
working-directory: configs
run: |
sudo apk --no-cache add yarn
./bin/config
./bin/config compile ${{ needs.pre.outputs.environment }}
kubectl delete configmap -n ${{ needs.pre.outputs.namespace }} server-env-custom || /bin/true
kubectl create configmap -n ${{ needs.pre.outputs.namespace }} server-env-custom --from-env-file=${{ env.ENVFILE }}
deploy:
name: Deploy Apps
runs-on: [k8s, deployer, "${{ needs.pre.outputs.runner }}"]
needs: pre

container:
image: dysnix/kubectl:v1.19-gcloud

env:
IMAGE_TAG: ${{ needs.pre.outputs.shortRev }}
KUBECONF: ${{ secrets[needs.pre.outputs.kubeConf] }}
HFENV: ${{ needs.pre.outputs.hfEnv }}

steps:
-
if: ${{ needs.pre.outputs.isTag == 'true' }}
Expand All @@ -89,7 +123,6 @@ jobs:
with:
repository: matter-labs/helm-infra
path: helm-infra
ref: new-health-and-conf
token: ${{ secrets.GH_TOKEN }}
-
if: ${{ needs.pre.outputs.isTag == 'true' }}
Expand Down Expand Up @@ -123,7 +156,7 @@ jobs:
uses: tferreira/matterfy@releases/v1
with:
type: ${{ job.status }}
job_name: '*Deployment to "${{ github.event.deployment.environment }}" failed*'
job_name: '*Deployment to "${{ steps.config.outputs.environment }}" failed*'
icon_emoji: octocat
channel: 'matterlabs-alerts'
url: ${{ secrets.MATTERMOST_WEBHOOK }}

0 comments on commit 81eac7f

Please sign in to comment.